@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
176 lines (175 loc) • 4.79 kB
TypeScript
/**
* MCP Server Capabilities - Resources and Prompts
*
* Extends MCP server functionality with resource and prompt handling
* according to MCP specification. This module provides:
* - Resource registration and management
* - Prompt template registration and execution
* - Resource subscription support
*
* @module mcp/serverCapabilities
* @since 8.39.0
*/
import { EventEmitter } from "events";
import type { JsonObject, JsonValue, MCPPrompt, MCPResource, PromptResult, RegisteredPrompt, RegisteredResource, ResourceContent, ResourceSubscriptionCallback, ServerCapabilitiesConfig } from "../types/index.js";
/**
* Server Capabilities Manager
*
* Manages resources and prompts for MCP servers.
*
* @example
* ```typescript
* const capabilities = new ServerCapabilitiesManager({
* resources: true,
* prompts: true,
* });
*
* // Register a resource
* capabilities.registerResource({
* uri: "file:///data/config.json",
* name: "Configuration",
* mimeType: "application/json",
* reader: async (uri) => ({
* uri,
* mimeType: "application/json",
* text: JSON.stringify({ key: "value" }),
* }),
* });
*
* // Register a prompt
* capabilities.registerPrompt({
* name: "summarize",
* description: "Summarize text content",
* arguments: [{ name: "text", required: true }],
* generator: async (args) => ({
* messages: [
* { role: "user", content: { type: "text", text: `Summarize: ${args.text}` } },
* ],
* }),
* });
* ```
*/
export declare class ServerCapabilitiesManager extends EventEmitter {
private config;
private resources;
private prompts;
private subscriptions;
private resourceTemplates;
constructor(config?: ServerCapabilitiesConfig);
/**
* Register a resource
*/
registerResource(resource: RegisteredResource): this;
/**
* Register a resource template (with URI pattern)
*/
registerResourceTemplate(pattern: string, template: Omit<RegisteredResource, "uri"> & {
uriPattern: string;
}): this;
/**
* Unregister a resource
*/
unregisterResource(uri: string): boolean;
/**
* List all resources
*/
listResources(): MCPResource[];
/**
* Read a resource
*/
readResource(uri: string, context?: JsonObject): Promise<ResourceContent>;
/**
* Subscribe to resource changes
*/
subscribeToResource(uri: string, callback: ResourceSubscriptionCallback): () => void;
/**
* Notify subscribers of resource change
*/
notifyResourceChanged(uri: string): Promise<void>;
/**
* Get resource by URI
*/
getResource(uri: string): RegisteredResource | undefined;
/**
* Validate resource URI
*/
private validateResourceUri;
/**
* Find matching resource template
*/
private findResourceTemplate;
/**
* Check if URI matches a pattern
*/
private matchesPattern;
/**
* Register a prompt
*/
registerPrompt(prompt: RegisteredPrompt): this;
/**
* Unregister a prompt
*/
unregisterPrompt(name: string): boolean;
/**
* List all prompts
*/
listPrompts(): MCPPrompt[];
/**
* Get a prompt
*/
getPrompt(name: string, args?: Record<string, JsonValue>, context?: JsonObject): Promise<PromptResult>;
/**
* Get prompt by name
*/
getPromptDefinition(name: string): RegisteredPrompt | undefined;
/**
* Validate prompt name
*/
private validatePromptName;
/**
* Get capabilities object for MCP protocol
*/
getCapabilities(): {
resources?: {
subscribe?: boolean;
listChanged?: boolean;
};
prompts?: {
listChanged?: boolean;
};
};
/**
* Get statistics
*/
getStatistics(): {
resourceCount: number;
templateCount: number;
promptCount: number;
subscriptionCount: number;
};
/**
* Clear all resources and prompts
*/
clear(): void;
}
/**
* Create a simple text resource
*/
export declare function createTextResource(uri: string, name: string, content: string | (() => string | Promise<string>), options?: {
description?: string;
dynamic?: boolean;
}): RegisteredResource;
/**
* Create a JSON resource
*/
export declare function createJsonResource<T extends JsonObject>(uri: string, name: string, content: T | (() => T | Promise<T>), options?: {
description?: string;
dynamic?: boolean;
}): RegisteredResource;
/**
* Create a simple prompt template
*/
export declare function createPrompt(name: string, template: string, options?: {
description?: string;
arguments?: MCPPrompt["arguments"];
}): RegisteredPrompt;