import { type JsonRpcId } from '../server/json-rpc-protocol.ts'; /** * MCP protocol version implemented by Weft's MCP transport adapters. * * @example * ```ts * import { MCP_PROTOCOL_VERSION } from '@lostgradient/weft/mcp'; * * const headers = new Headers({ * 'Mcp-Protocol-Version': MCP_PROTOCOL_VERSION, * }); * void headers; * ``` */ export declare const MCP_PROTOCOL_VERSION = "2025-11-25"; /** MCP method used for live tool introspection. */ export declare const MCP_TOOLS_LIST_METHOD = "tools/list"; /** MCP notification emitted when the live tools/list output changes. */ export declare const MCP_TOOLS_LIST_CHANGED_NOTIFICATION = "notifications/tools/list_changed"; /** MCP method used for live resource introspection. */ export declare const MCP_RESOURCES_LIST_METHOD = "resources/list"; /** MCP method used for live resource-template introspection. */ export declare const MCP_RESOURCE_TEMPLATES_LIST_METHOD = "resources/templates/list"; /** * Default MCP HTTP body limit. Mirrors the existing JSON-RPC adapter limit. * * @example * ```ts * import { DEFAULT_MCP_MAX_BODY_BYTES } from '@lostgradient/weft/mcp'; * * const maxBodyBytes = DEFAULT_MCP_MAX_BODY_BYTES; * void maxBodyBytes; * ``` */ export declare const DEFAULT_MCP_MAX_BODY_BYTES = 1048576; /** JSON-RPC request accepted by the MCP dispatcher. */ export type McpRequest = { readonly jsonrpc: '2.0'; readonly id?: JsonRpcId | undefined; readonly method: string; readonly params?: unknown; }; /** JSON-RPC response emitted by the MCP dispatcher. */ export type McpResponse = { readonly jsonrpc: '2.0'; readonly id: JsonRpcId; readonly result?: unknown; readonly error?: { readonly code: number; readonly message: string; readonly data?: unknown; }; }; /** Result of handling one MCP message. */ export type McpDispatchResult = { readonly kind: 'response'; readonly response: McpResponse; } | { readonly kind: 'accepted'; }; /** Build a JSON-RPC success response. */ export declare function successResponse(id: JsonRpcId, result: unknown): McpResponse; /** Build a JSON-RPC error response. */ export declare function errorResponse(id: JsonRpcId, code: number, message: string, data?: unknown): McpResponse; /** Invalid params error response. */ export declare function invalidParams(id: JsonRpcId, message: string, data?: unknown): McpResponse; /** Method not found error response. */ export declare function methodNotFound(id: JsonRpcId, method: string): McpResponse; /** Internal error response with masked details. */ export declare function internalError(id: JsonRpcId): McpResponse; /** Resource-not-found response using the MCP resource error convention. */ export declare function resourceNotFound(id: JsonRpcId, uri: string): McpResponse; /** Forbidden response. */ export declare function forbidden(id: JsonRpcId, reason: string): McpResponse; /** True when a value is a JSON-RPC object with a method field. */ export declare function isMcpRequest(value: unknown): value is McpRequest; /** True when a JSON-RPC request is a notification. */ export declare function isNotification(request: McpRequest): boolean; /** Convert a request id to a stable map key. */ export declare function requestIdKey(id: JsonRpcId | undefined): string | undefined; /** Parse one JSON text payload into an MCP request or a protocol response. */ export declare function parseMcpMessage(text: string): { ok: true; value: unknown; } | { ok: false; }; /** True when an HTTP content type is JSON. */ export declare function isJsonContentType(contentType: string): boolean; /** True when an Accept header allows the requested MIME type. */ export declare function accepts(acceptHeader: string | null, mimeType: string): boolean;