/** * MCP Protocol Handler * * Handles MCP protocol messages including initialization, tool discovery, * tool invocation, resource management, and prompt handling. * * @see https://spec.modelcontextprotocol.io/specification/ */ import type { JsonRpcId, CallToolResult, ToolRegistration, ResourceRegistration, PromptRegistration, ToolContext, Logger, MCPServerConfig } from '../types'; import type { StdioTransport } from './transport'; /** * MCP Protocol Handler * * Core handler for processing MCP protocol messages. Manages the lifecycle * of the MCP session and dispatches requests to registered handlers. */ export declare class MCPProtocolHandler { private readonly transport; private readonly serverInfo; private readonly serverCapabilities; private readonly logger; private state; private clientInfo; private clientCapabilities; private readonly tools; private readonly resources; private readonly prompts; private readonly pendingRequests; constructor(config: MCPServerConfig, transport: StdioTransport, logger: Logger); /** * Start the protocol handler */ start(): Promise; /** * Stop the protocol handler */ stop(): Promise; /** * Register a tool with the handler */ registerTool(registration: ToolRegistration): void; /** * Unregister a tool */ unregisterTool(name: string): boolean; /** * Register a resource with the handler */ registerResource(registration: ResourceRegistration): void; /** * Unregister a resource */ unregisterResource(uri: string): boolean; /** * Register a prompt with the handler */ registerPrompt(registration: PromptRegistration): void; /** * Unregister a prompt */ unregisterPrompt(name: string): boolean; /** * Handle incoming message from transport */ private handleMessage; /** * Handle a JSON-RPC request */ private handleRequest; /** * Handle a JSON-RPC notification */ private handleNotification; /** * Handle initialize request */ private handleInitialize; /** * Handle list tools request */ private handleListTools; /** * Handle call tool request */ private handleCallTool; /** * Handle list resources request */ private handleListResources; /** * Handle read resource request */ private handleReadResource; /** * Handle list prompts request */ private handleListPrompts; /** * Handle get prompt request */ private handleGetPrompt; /** * Handle shutdown request */ private handleShutdown; /** * Handle cancellation notification */ private handleCancellation; /** * Send a success response */ private sendResponse; /** * Send an error response */ private sendErrorResponse; /** * Send a notification */ private sendNotification; /** * Send progress notification */ private sendProgress; /** * Require that the handler is initialized */ private requireInitialized; /** * Handle transport errors */ private handleTransportError; /** * Handle transport close */ private handleTransportClose; } /** * Protocol-specific error class */ export declare class ProtocolError extends Error { readonly code: number; readonly data?: unknown; constructor(code: number, message: string, data?: unknown); } /** * Create a tool context helper */ export declare function createToolContext(requestId: JsonRpcId, logger: Logger, signal?: AbortSignal): ToolContext; /** * Create a simple text result */ export declare function createTextResult(text: string, isError?: boolean): CallToolResult; /** * Create a JSON result */ export declare function createJsonResult(data: unknown, isError?: boolean): CallToolResult; //# sourceMappingURL=handler.d.ts.map