/** * MCP Server TypeScript Type Definitions * * Implements the Model Context Protocol (MCP) specification types * for Claude Code integration via stdio transport. * * @see https://spec.modelcontextprotocol.io/specification/ */ import { z } from 'zod'; /** * JSON-RPC 2.0 request ID - can be string, number, or null */ export type JsonRpcId = string | number | null; /** * JSON-RPC 2.0 version constant */ export declare const JSONRPC_VERSION: "2.0"; /** * Base JSON-RPC 2.0 message structure */ export interface JsonRpcMessage { readonly jsonrpc: typeof JSONRPC_VERSION; } /** * JSON-RPC 2.0 Request */ export interface JsonRpcRequest extends JsonRpcMessage { readonly id: JsonRpcId; readonly method: string; readonly params?: Record | unknown[]; } /** * JSON-RPC 2.0 Notification (request without id) */ export interface JsonRpcNotification extends JsonRpcMessage { readonly method: string; readonly params?: Record | unknown[]; } /** * JSON-RPC 2.0 Success Response */ export interface JsonRpcSuccessResponse extends JsonRpcMessage { readonly id: JsonRpcId; readonly result: unknown; } /** * JSON-RPC 2.0 Error Response */ export interface JsonRpcErrorResponse extends JsonRpcMessage { readonly id: JsonRpcId; readonly error: JsonRpcError; } /** * JSON-RPC 2.0 Error object */ export interface JsonRpcError { readonly code: number; readonly message: string; readonly data?: unknown; } /** * Union type for all JSON-RPC responses */ export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse; export declare const JsonRpcErrorCodes: { readonly PARSE_ERROR: -32700; readonly INVALID_REQUEST: -32600; readonly METHOD_NOT_FOUND: -32601; readonly INVALID_PARAMS: -32602; readonly INTERNAL_ERROR: -32603; readonly SERVER_ERROR_START: -32099; readonly SERVER_ERROR_END: -32000; readonly TOOL_NOT_FOUND: -32001; readonly TOOL_EXECUTION_ERROR: -32002; readonly RESOURCE_NOT_FOUND: -32003; readonly PROMPT_NOT_FOUND: -32004; readonly CAPABILITY_NOT_SUPPORTED: -32005; }; export type JsonRpcErrorCode = typeof JsonRpcErrorCodes[keyof typeof JsonRpcErrorCodes]; /** * MCP Protocol Version */ export declare const MCP_PROTOCOL_VERSION: "2024-11-05"; /** * MCP Server Information */ export interface ServerInfo { readonly name: string; readonly version: string; readonly protocolVersion?: string; } /** * MCP Client Information */ export interface ClientInfo { readonly name: string; readonly version: string; } /** * MCP Server Capabilities */ export interface ServerCapabilities { readonly tools?: ToolsCapability; readonly resources?: ResourcesCapability; readonly prompts?: PromptsCapability; readonly logging?: LoggingCapability; readonly experimental?: Record; } export interface ToolsCapability { readonly listChanged?: boolean; } export interface ResourcesCapability { readonly subscribe?: boolean; readonly listChanged?: boolean; } export interface PromptsCapability { readonly listChanged?: boolean; } export interface LoggingCapability { readonly levels?: readonly LogLevel[]; } /** * MCP Client Capabilities */ export interface ClientCapabilities { readonly roots?: RootsCapability; readonly sampling?: SamplingCapability; readonly experimental?: Record; } export interface RootsCapability { readonly listChanged?: boolean; } export interface SamplingCapability { } /** * MCP Tool Definition */ export interface Tool { readonly name: string; readonly description: string; readonly inputSchema: ToolInputSchema; } /** * JSON Schema for tool input */ export interface ToolInputSchema { readonly type: 'object'; readonly properties?: Record; readonly required?: readonly string[]; readonly additionalProperties?: boolean; } /** * JSON Schema type definition (simplified) */ export interface JsonSchema { readonly type?: string | readonly string[]; readonly description?: string; readonly enum?: readonly unknown[]; readonly const?: unknown; readonly default?: unknown; readonly properties?: Record; readonly items?: JsonSchema; readonly required?: readonly string[]; readonly additionalProperties?: boolean | JsonSchema; readonly minimum?: number; readonly maximum?: number; readonly minLength?: number; readonly maxLength?: number; readonly pattern?: string; readonly format?: string; readonly oneOf?: readonly JsonSchema[]; readonly anyOf?: readonly JsonSchema[]; readonly allOf?: readonly JsonSchema[]; readonly not?: JsonSchema; } /** * Tool Call Request Parameters */ export interface ToolCallParams { readonly name: string; readonly arguments?: Record; } /** * Tool Call Result */ export interface ToolCallResult { readonly content: readonly ToolContent[]; readonly isError?: boolean; } /** * Tool Content Types */ export type ToolContent = TextContent | ImageContent | EmbeddedResource; export interface TextContent { readonly type: 'text'; readonly text: string; } export interface ImageContent { readonly type: 'image'; readonly data: string; readonly mimeType: string; } export interface EmbeddedResource { readonly type: 'resource'; readonly resource: ResourceContents; } /** * MCP Resource Definition */ export interface Resource { readonly uri: string; readonly name: string; readonly description?: string; readonly mimeType?: string; } /** * Resource Contents */ export interface ResourceContents { readonly uri: string; readonly mimeType?: string; readonly text?: string; readonly blob?: string; } /** * Resource Template for dynamic resources */ export interface ResourceTemplate { readonly uriTemplate: string; readonly name: string; readonly description?: string; readonly mimeType?: string; } /** * MCP Prompt Definition */ export interface Prompt { readonly name: string; readonly description?: string; readonly arguments?: readonly PromptArgument[]; } /** * Prompt Argument Definition */ export interface PromptArgument { readonly name: string; readonly description?: string; readonly required?: boolean; } /** * Prompt Message */ export interface PromptMessage { readonly role: 'user' | 'assistant'; readonly content: TextContent | ImageContent | EmbeddedResource; } /** * Get Prompt Result */ export interface GetPromptResult { readonly description?: string; readonly messages: readonly PromptMessage[]; } /** * Log Levels */ export type LogLevel = 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency'; /** * Log Message */ export interface LogMessage { readonly level: LogLevel; readonly logger?: string; readonly data?: unknown; } /** * Initialize Request Parameters */ export interface InitializeParams { readonly protocolVersion: string; readonly capabilities: ClientCapabilities; readonly clientInfo: ClientInfo; } /** * Initialize Response Result */ export interface InitializeResult { readonly protocolVersion: string; readonly capabilities: ServerCapabilities; readonly serverInfo: ServerInfo; readonly instructions?: string; } /** * List Tools Request (no parameters) */ export interface ListToolsParams { readonly cursor?: string; } /** * List Tools Response */ export interface ListToolsResult { readonly tools: readonly Tool[]; readonly nextCursor?: string; } /** * Call Tool Request */ export interface CallToolParams { readonly name: string; readonly arguments?: Record; } /** * Call Tool Response */ export interface CallToolResult { readonly content: readonly ToolContent[]; readonly isError?: boolean; } /** * List Resources Request */ export interface ListResourcesParams { readonly cursor?: string; } /** * List Resources Response */ export interface ListResourcesResult { readonly resources: readonly Resource[]; readonly nextCursor?: string; } /** * Read Resource Request */ export interface ReadResourceParams { readonly uri: string; } /** * Read Resource Response */ export interface ReadResourceResult { readonly contents: readonly ResourceContents[]; } /** * List Prompts Request */ export interface ListPromptsParams { readonly cursor?: string; } /** * List Prompts Response */ export interface ListPromptsResult { readonly prompts: readonly Prompt[]; readonly nextCursor?: string; } /** * Get Prompt Request */ export interface GetPromptParams { readonly name: string; readonly arguments?: Record; } /** * Progress Notification */ export interface ProgressNotification { readonly progressToken: string | number; readonly progress: number; readonly total?: number; } /** * Resource Updated Notification */ export interface ResourceUpdatedNotification { readonly uri: string; } /** * Tool List Changed Notification */ export interface ToolListChangedNotification { } export declare const MCPMethods: { readonly INITIALIZE: "initialize"; readonly INITIALIZED: "notifications/initialized"; readonly SHUTDOWN: "shutdown"; readonly LIST_TOOLS: "tools/list"; readonly CALL_TOOL: "tools/call"; readonly TOOLS_LIST_CHANGED: "notifications/tools/list_changed"; readonly LIST_RESOURCES: "resources/list"; readonly READ_RESOURCE: "resources/read"; readonly SUBSCRIBE_RESOURCE: "resources/subscribe"; readonly UNSUBSCRIBE_RESOURCE: "resources/unsubscribe"; readonly RESOURCES_LIST_CHANGED: "notifications/resources/list_changed"; readonly RESOURCE_UPDATED: "notifications/resources/updated"; readonly LIST_PROMPTS: "prompts/list"; readonly GET_PROMPT: "prompts/get"; readonly PROMPTS_LIST_CHANGED: "notifications/prompts/list_changed"; readonly SET_LOG_LEVEL: "logging/setLevel"; readonly LOG_MESSAGE: "notifications/message"; readonly PROGRESS: "notifications/progress"; readonly CANCEL: "notifications/cancelled"; readonly PING: "ping"; }; export type MCPMethod = typeof MCPMethods[keyof typeof MCPMethods]; /** * Transport interface for MCP communication */ export interface MCPTransport { /** * Start the transport */ start(): Promise; /** * Stop the transport */ stop(): Promise; /** * Send a message through the transport */ send(message: JsonRpcMessage): Promise; /** * Event handler for received messages */ onMessage: ((message: JsonRpcRequest | JsonRpcNotification) => void) | null; /** * Event handler for transport errors */ onError: ((error: Error) => void) | null; /** * Event handler for transport close */ onClose: (() => void) | null; } /** * Transport options */ export interface StdioTransportOptions { readonly debug?: boolean; readonly inputStream?: NodeJS.ReadableStream; readonly outputStream?: NodeJS.WritableStream; } /** * MCP Server Configuration */ export interface MCPServerConfig { readonly name: string; readonly version: string; readonly description?: string; readonly capabilities?: Partial; readonly transport?: StdioTransportOptions; readonly logging?: LoggingConfig; readonly tools?: ToolRegistration[]; readonly resources?: ResourceRegistration[]; readonly prompts?: PromptRegistration[]; } /** * Logging configuration */ export interface LoggingConfig { readonly level: LogLevel; readonly format?: 'json' | 'text'; readonly destination?: 'stderr' | 'file'; readonly filePath?: string; } /** * Tool registration */ export interface ToolRegistration { readonly tool: Tool; readonly handler: ToolHandler; } /** * Tool handler function type */ export type ToolHandler = (params: Record, context: ToolContext) => Promise; /** * Tool execution context */ export interface ToolContext { readonly requestId: JsonRpcId; readonly signal?: AbortSignal; readonly logger: Logger; readonly progress: (progress: number, total?: number) => void; } /** * Resource registration */ export interface ResourceRegistration { readonly resource: Resource; readonly handler: ResourceHandler; } /** * Resource handler function type */ export type ResourceHandler = (uri: string, context: ResourceContext) => Promise; /** * Resource context */ export interface ResourceContext { readonly requestId: JsonRpcId; readonly logger: Logger; } /** * Prompt registration */ export interface PromptRegistration { readonly prompt: Prompt; readonly handler: PromptHandler; } /** * Prompt handler function type */ export type PromptHandler = (args: Record, context: PromptContext) => Promise; /** * Prompt context */ export interface PromptContext { readonly requestId: JsonRpcId; readonly logger: Logger; } /** * Logger interface for MCP server */ export interface Logger { debug(message: string, data?: unknown): void; info(message: string, data?: unknown): void; notice(message: string, data?: unknown): void; warning(message: string, data?: unknown): void; error(message: string, data?: unknown): void; critical(message: string, data?: unknown): void; alert(message: string, data?: unknown): void; emergency(message: string, data?: unknown): void; } export declare const JsonRpcRequestSchema: z.ZodObject<{ jsonrpc: z.ZodLiteral<"2.0">; id: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodNull]>; method: z.ZodString; params: z.ZodOptional, z.ZodArray]>>; }, "strip", z.ZodTypeAny, { jsonrpc: "2.0"; id: string | number | null; method: string; params?: Record | unknown[] | undefined; }, { jsonrpc: "2.0"; id: string | number | null; method: string; params?: Record | unknown[] | undefined; }>; export declare const JsonRpcNotificationSchema: z.ZodObject<{ jsonrpc: z.ZodLiteral<"2.0">; method: z.ZodString; params: z.ZodOptional, z.ZodArray]>>; }, "strip", z.ZodTypeAny, { jsonrpc: "2.0"; method: string; params?: Record | unknown[] | undefined; }, { jsonrpc: "2.0"; method: string; params?: Record | unknown[] | undefined; }>; export declare const InitializeParamsSchema: z.ZodObject<{ protocolVersion: z.ZodString; capabilities: z.ZodObject<{ roots: z.ZodOptional; }, "strip", z.ZodTypeAny, { listChanged?: boolean | undefined; }, { listChanged?: boolean | undefined; }>>; sampling: z.ZodOptional>; experimental: z.ZodOptional>; }, "strip", z.ZodTypeAny, { roots?: { listChanged?: boolean | undefined; } | undefined; sampling?: {} | undefined; experimental?: Record | undefined; }, { roots?: { listChanged?: boolean | undefined; } | undefined; sampling?: {} | undefined; experimental?: Record | undefined; }>; clientInfo: z.ZodObject<{ name: z.ZodString; version: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; version: string; }, { name: string; version: string; }>; }, "strip", z.ZodTypeAny, { protocolVersion: string; capabilities: { roots?: { listChanged?: boolean | undefined; } | undefined; sampling?: {} | undefined; experimental?: Record | undefined; }; clientInfo: { name: string; version: string; }; }, { protocolVersion: string; capabilities: { roots?: { listChanged?: boolean | undefined; } | undefined; sampling?: {} | undefined; experimental?: Record | undefined; }; clientInfo: { name: string; version: string; }; }>; export declare const CallToolParamsSchema: z.ZodObject<{ name: z.ZodString; arguments: z.ZodOptional>; }, "strip", z.ZodTypeAny, { name: string; arguments?: Record | undefined; }, { name: string; arguments?: Record | undefined; }>; export declare const ReadResourceParamsSchema: z.ZodObject<{ uri: z.ZodString; }, "strip", z.ZodTypeAny, { uri: string; }, { uri: string; }>; export declare const GetPromptParamsSchema: z.ZodObject<{ name: z.ZodString; arguments: z.ZodOptional>; }, "strip", z.ZodTypeAny, { name: string; arguments?: Record | undefined; }, { name: string; arguments?: Record | undefined; }>; export declare const ListParamsSchema: z.ZodObject<{ cursor: z.ZodOptional; }, "strip", z.ZodTypeAny, { cursor?: string | undefined; }, { cursor?: string | undefined; }>; //# sourceMappingURL=index.d.ts.map