@ai-sdk/mcp 2.0.86 → 2.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.d.ts +12 -2
- package/dist/mcp-stdio/index.d.ts.map +1 -1
- package/dist/mcp-stdio/index.js +17 -2
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +3 -3
- package/src/tool/mcp-client.ts +176 -5
- package/src/tool/mcp-http-transport.ts +1 -1
- package/src/tool/mcp-sse-transport.ts +1 -1
- package/src/tool/mcp-stdio/index.ts +13 -4
- package/src/tool/types.ts +18 -0
|
@@ -137,7 +137,7 @@ interface StdioConfig {
|
|
|
137
137
|
cwd?: string;
|
|
138
138
|
shell?: boolean | string;
|
|
139
139
|
}
|
|
140
|
-
declare class StdioMCPTransport implements MCPTransport {
|
|
140
|
+
export declare class StdioMCPTransport implements MCPTransport {
|
|
141
141
|
readonly supportsProtocolVersionDiscovery = true;
|
|
142
142
|
private process?;
|
|
143
143
|
private abortController;
|
|
@@ -153,5 +153,15 @@ declare class StdioMCPTransport implements MCPTransport {
|
|
|
153
153
|
send(message: JSONRPCMessage): Promise<void>;
|
|
154
154
|
}
|
|
155
155
|
//#endregion
|
|
156
|
-
|
|
156
|
+
//#region src/tool/mcp-stdio/index.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* @deprecated Use `StdioMCPTransport` instead.
|
|
159
|
+
*/
|
|
160
|
+
export declare const Experimental_StdioMCPTransport: typeof StdioMCPTransport;
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated Use `StdioMCPTransport` instead.
|
|
163
|
+
*/
|
|
164
|
+
export type Experimental_StdioMCPTransport = StdioMCPTransport;
|
|
165
|
+
//#endregion
|
|
166
|
+
export type { StdioConfig };
|
|
157
167
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tool/json-rpc-message.ts","../../src/tool/mcp-transport.ts","../../src/tool/mcp-stdio/mcp-stdio-transport.ts"],"mappings":";;;;;;cAsDa,sBAAoB,EAAA,mBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAK/B,EAAA,KAAA;KAEU,iBAAiB,EAAE,aAAa;;;;;;;KCjDhC;;;;EAIV,SAAS;;;;EAKT,UAAU;;;;EAKV;;;;EAKA;;;;EAKA,qBAAqB;;KAGX;;;;EAIV,SAAS;;UAGM;;;;;;;EAOf;;;;;;;;;;EAWA;;;;;EAMA;;;;EAKA,SAAS;;;;;;EAOT,KACE,SAAS,gBACT,UAAU,0BACT;;;;;EAMH,MAAM,UAAU,2BAA2B;;;;EAK3C;;;;EAKA,WAAW,OAAO;;;;EAKlB,aAAa,SAAS;;;;EAKtB;;;;EAKA,oBAAoB;;;;UC7GL;EACf;EACA;EACA,MAAM;EACN,SAAS,SAAS;EAClB;EACA;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/tool/json-rpc-message.ts","../../src/tool/mcp-transport.ts","../../src/tool/mcp-stdio/mcp-stdio-transport.ts","../../src/tool/mcp-stdio/index.ts"],"mappings":";;;;;;cAsDa,sBAAoB,EAAA,mBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAK/B,EAAA,KAAA;KAEU,iBAAiB,EAAE,aAAa;;;;;;;KCjDhC;;;;EAIV,SAAS;;;;EAKT,UAAU;;;;EAKV;;;;EAKA;;;;EAKA,qBAAqB;;KAGX;;;;EAIV,SAAS;;UAGM;;;;;;;EAOf;;;;;;;;;;EAWA;;;;;EAMA;;;;EAKA,SAAS;;;;;;EAOT,KACE,SAAS,gBACT,UAAU,0BACT;;;;;EAMH,MAAM,UAAU,2BAA2B;;;;EAK3C;;;;EAKA,WAAW,OAAO;;;;EAKlB,aAAa,SAAS;;;;EAKtB;;;;EAKA,oBAAoB;;;;UC7GL;EACf;EACA;EACA,MAAM;EACN,SAAS,SAAS;EAClB;EACA;;qBAGW,6BAA6B;WAC/B;UACD;UACA;UACA;UACA;EAER;EACA,WAAW;EACX,aAAa,SAAS;EAEV,YAAA,QAAQ;EAId,SAAS;UAsDD;EAgBR,SAAS;EAMf,KAAK,SAAS,iBAAiB;;;;;;;qBCpGpB,uCAA8B;;;;YAK/B,iCAAiC"}
|
package/dist/mcp-stdio/index.js
CHANGED
|
@@ -212,7 +212,7 @@ const ElicitationRequestParamsSchema = BaseParamsSchema.extend({
|
|
|
212
212
|
message: z.string(),
|
|
213
213
|
requestedSchema: z.unknown()
|
|
214
214
|
});
|
|
215
|
-
RequestSchema.extend({
|
|
215
|
+
const ElicitationRequestSchema = RequestSchema.extend({
|
|
216
216
|
method: z.literal("elicitation/create"),
|
|
217
217
|
params: ElicitationRequestParamsSchema
|
|
218
218
|
});
|
|
@@ -224,6 +224,15 @@ ResultSchema.extend({
|
|
|
224
224
|
]),
|
|
225
225
|
content: z.optional(z.record(z.string(), z.unknown()))
|
|
226
226
|
});
|
|
227
|
+
ResultSchema.extend({
|
|
228
|
+
resultType: z.literal("input_required"),
|
|
229
|
+
inputRequests: z.record(z.string(), RequestSchema).optional(),
|
|
230
|
+
requestState: z.string().optional()
|
|
231
|
+
}).refine((result) => result.inputRequests !== void 0 || result.requestState !== void 0, { message: "input_required must include inputRequests or requestState" });
|
|
232
|
+
ElicitationRequestSchema.extend({ params: ElicitationRequestParamsSchema.extend({
|
|
233
|
+
mode: z.literal("form").optional(),
|
|
234
|
+
requestedSchema: z.looseObject({ type: z.literal("object") })
|
|
235
|
+
}) });
|
|
227
236
|
//#endregion
|
|
228
237
|
//#region src/tool/json-rpc-message.ts
|
|
229
238
|
const JSONRPC_VERSION = "2.0";
|
|
@@ -442,6 +451,12 @@ async function deserializeMessage(line) {
|
|
|
442
451
|
return parseJSONRPCMessage(line);
|
|
443
452
|
}
|
|
444
453
|
//#endregion
|
|
445
|
-
|
|
454
|
+
//#region src/tool/mcp-stdio/index.ts
|
|
455
|
+
/**
|
|
456
|
+
* @deprecated Use `StdioMCPTransport` instead.
|
|
457
|
+
*/
|
|
458
|
+
const Experimental_StdioMCPTransport = StdioMCPTransport;
|
|
459
|
+
//#endregion
|
|
460
|
+
export { Experimental_StdioMCPTransport, StdioMCPTransport };
|
|
446
461
|
|
|
447
462
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/tool/types.ts","../../src/tool/json-rpc-message.ts","../../src/error/mcp-client-error.ts","../../src/tool/mcp-stdio/get-environment.ts","../../src/tool/mcp-stdio/create-child-process.ts","../../src/tool/mcp-stdio/mcp-stdio-transport.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport type { JSONObject } from '@ai-sdk/provider';\nimport type {\n FlexibleSchema,\n Tool,\n ToolExecutionOptions,\n} from '@ai-sdk/provider-utils';\n\nexport const LATEST_PROTOCOL_VERSION = '2026-07-28';\nexport const LATEST_LEGACY_PROTOCOL_VERSION = '2025-11-25';\nexport const SUPPORTED_PROTOCOL_VERSIONS = [\n LATEST_PROTOCOL_VERSION,\n LATEST_LEGACY_PROTOCOL_VERSION,\n '2025-06-18',\n '2025-03-26',\n '2024-11-05',\n];\n\nexport type McpProviderMetadata = {\n clientName?: string;\n title?: string;\n toolName?: string;\n annotations?: McpToolAnnotations;\n app?: JSONObject;\n};\n\n/**\n * Behavioral hints reported by an MCP server for a tool.\n *\n * These annotations are untrusted unless the server itself is trusted.\n *\n * @see https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations\n */\nexport type McpToolAnnotations = {\n title?: string;\n readOnlyHint?: boolean;\n destructiveHint?: boolean;\n idempotentHint?: boolean;\n openWorldHint?: boolean;\n};\n\n/** MCP tool metadata - keys should follow MCP _meta key format specification */\nconst ToolMetaSchema = z.optional(z.record(z.string(), z.unknown()));\nexport type ToolMeta = z.infer<typeof ToolMetaSchema>;\n\nexport type ToolSchemas =\n | Record<\n string,\n {\n inputSchema: FlexibleSchema<JSONObject | unknown>;\n outputSchema?: FlexibleSchema<JSONObject | unknown>;\n }\n >\n | 'automatic'\n | undefined;\n\n/** Base MCP tool type with execute and _meta */\ntype McpToolBase<INPUT = unknown, OUTPUT = CallToolResult> = Tool<\n INPUT,\n OUTPUT\n> & {\n execute: (\n input: INPUT,\n options?: ToolExecutionOptions<{}>,\n ) => ReturnType<NonNullable<Tool<INPUT, OUTPUT>['execute']>>;\n _meta?: ToolMeta;\n};\n\nexport type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> =\n TOOL_SCHEMAS extends Record<\n string,\n { inputSchema: FlexibleSchema<any>; outputSchema?: FlexibleSchema<any> }\n >\n ? {\n [K in keyof TOOL_SCHEMAS]: TOOL_SCHEMAS[K] extends {\n inputSchema: FlexibleSchema<infer INPUT>;\n outputSchema: FlexibleSchema<infer OUTPUT>;\n }\n ? McpToolBase<INPUT, OUTPUT>\n : TOOL_SCHEMAS[K] extends {\n inputSchema: FlexibleSchema<infer INPUT>;\n }\n ? McpToolBase<INPUT, CallToolResult>\n : never;\n }\n : Record<string, McpToolBase<unknown, CallToolResult>>;\n\nconst ClientOrServerImplementationSchema = z.looseObject({\n name: z.string(),\n version: z.string(),\n title: z.optional(z.string()),\n});\n\n// Maps to `Implementation` in the MCP specification\nexport type Configuration = z.infer<typeof ClientOrServerImplementationSchema>;\n\nexport const BaseParamsSchema = z.looseObject({\n _meta: z.optional(z.object({}).loose()),\n});\ntype BaseParams = z.infer<typeof BaseParamsSchema>;\nexport const ResultSchema = BaseParamsSchema.extend({\n resultType: z.optional(z.string()),\n});\n\nexport const RequestSchema = z.object({\n method: z.string(),\n params: z.optional(BaseParamsSchema),\n});\nexport type Request = z.infer<typeof RequestSchema>;\nexport type RequestOptions = {\n signal?: AbortSignal;\n timeout?: number;\n maxTotalTimeout?: number;\n};\n\nexport type Notification = z.infer<typeof RequestSchema>;\n\n/** @see https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation */\nconst ElicitationCapabilitySchema = z\n .object({\n applyDefaults: z.optional(z.boolean()),\n })\n .loose();\n\nconst ServerCapabilitiesSchema = z.looseObject({\n events: z.looseObject({ listChanged: z.boolean().nullish() }).nullish(),\n experimental: z.optional(z.object({}).loose()),\n logging: z.optional(z.object({}).loose()),\n completions: z.optional(z.object({}).loose()),\n prompts: z.optional(\n z.looseObject({\n listChanged: z.optional(z.boolean()),\n }),\n ),\n resources: z.optional(\n z.looseObject({\n subscribe: z.optional(z.boolean()),\n listChanged: z.optional(z.boolean()),\n }),\n ),\n tools: z.optional(\n z.looseObject({\n listChanged: z.optional(z.boolean()),\n }),\n ),\n elicitation: z.optional(ElicitationCapabilitySchema),\n});\n\nexport type ServerCapabilities = z.infer<typeof ServerCapabilitiesSchema>;\nexport const ClientCapabilitiesSchema = z\n .object({\n elicitation: z.optional(ElicitationCapabilitySchema),\n })\n .loose();\n\nexport type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;\nexport type ElicitationCapability = z.infer<typeof ElicitationCapabilitySchema>;\n\nexport const DiscoverResultSchema = ResultSchema.extend({\n supportedVersions: z.array(z.string()),\n capabilities: ServerCapabilitiesSchema,\n instructions: z.optional(z.string()),\n ttlMs: z.optional(z.number()),\n cacheScope: z.optional(z.union([z.literal('public'), z.literal('private')])),\n});\nexport type DiscoverResult = z.infer<typeof DiscoverResultSchema>;\n\nexport const InitializeResultSchema = ResultSchema.extend({\n protocolVersion: z.string(),\n capabilities: ServerCapabilitiesSchema,\n serverInfo: ClientOrServerImplementationSchema,\n instructions: z.optional(z.string()),\n});\nexport type InitializeResult = z.infer<typeof InitializeResultSchema>;\n\nexport type PaginatedRequest = Request & {\n params?: BaseParams & {\n cursor?: string;\n };\n};\n\nconst PaginatedResultSchema = ResultSchema.extend({\n nextCursor: z.optional(z.string()),\n});\n\nconst ToolSchema = z\n .object({\n name: z.string(),\n /**\n * @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool\n */\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n inputSchema: z.looseObject({\n type: z.optional(z.unknown()),\n properties: z.optional(z.object({}).loose()),\n }),\n /**\n * @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema\n */\n outputSchema: z.optional(z.object({}).loose()),\n annotations: z.optional(\n z\n .object({\n title: z.optional(z.string()),\n readOnlyHint: z.optional(z.boolean()),\n destructiveHint: z.optional(z.boolean()),\n idempotentHint: z.optional(z.boolean()),\n openWorldHint: z.optional(z.boolean()),\n })\n .loose(),\n ),\n _meta: ToolMetaSchema,\n })\n .loose();\nexport type MCPTool = z.infer<typeof ToolSchema>;\nexport const ListToolsResultSchema = PaginatedResultSchema.extend({\n tools: z.array(ToolSchema),\n});\nexport type ListToolsResult = z.infer<typeof ListToolsResultSchema>;\n\nconst TextContentSchema = z\n .object({\n type: z.literal('text'),\n text: z.string(),\n })\n .loose();\nconst ImageContentSchema = z\n .object({\n type: z.literal('image'),\n data: z.base64(),\n mimeType: z.string(),\n })\n .loose();\nexport const ResourceSchema = z\n .object({\n uri: z.string(),\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n size: z.optional(z.number()),\n })\n .loose();\nexport type MCPResource = z.infer<typeof ResourceSchema>;\n\nexport const ListResourcesResultSchema = PaginatedResultSchema.extend({\n resources: z.array(ResourceSchema),\n});\nexport type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;\n\nconst ResourceContentsSchema = z\n .object({\n /**\n * The URI of this resource.\n */\n uri: z.string(),\n /**\n * Optional display name of the resource content.\n */\n name: z.optional(z.string()),\n /**\n * Optional human readable title.\n */\n title: z.optional(z.string()),\n /**\n * The MIME type of this resource, if known.\n */\n mimeType: z.optional(z.string()),\n })\n .loose();\nconst TextResourceContentsSchema = ResourceContentsSchema.extend({\n text: z.string(),\n});\nconst BlobResourceContentsSchema = ResourceContentsSchema.extend({\n blob: z.base64(),\n});\nconst EmbeddedResourceSchema = z\n .object({\n type: z.literal('resource'),\n resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),\n })\n .loose();\nconst ResourceLinkContentSchema = z\n .object({\n type: z.literal('resource_link'),\n uri: z.string(),\n name: z.string(),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n })\n .loose();\nconst UnknownContentSchema = z\n .object({ type: z.string() })\n .loose()\n .refine(\n content =>\n !['text', 'image', 'resource', 'resource_link'].includes(content.type),\n { message: 'Known content types must match their schema' },\n );\n\nconst CallToolResultWithContentSchema = ResultSchema.extend({\n content: z.array(\n z.union([\n TextContentSchema,\n ImageContentSchema,\n EmbeddedResourceSchema,\n ResourceLinkContentSchema,\n UnknownContentSchema,\n ]),\n ),\n /**\n * @see https://modelcontextprotocol.io/specification/2026-07-28/server/tools#structured-content\n */\n structuredContent: z.optional(z.unknown()),\n isError: z.boolean().default(false).optional(),\n});\n\nconst CallToolResultWithStructuredContentSchema = ResultSchema.extend({\n content: z.never().optional(),\n structuredContent: z.json(),\n isError: z.boolean().default(false).optional(),\n})\n .transform(\n (result): z.infer<typeof CallToolResultWithContentSchema> => ({\n ...result,\n content: [\n {\n type: 'text',\n text: JSON.stringify(result.structuredContent),\n },\n ],\n }),\n )\n .pipe(CallToolResultWithContentSchema);\n\nexport const CallToolResultSchema = CallToolResultWithContentSchema.or(\n CallToolResultWithStructuredContentSchema,\n).or(\n ResultSchema.extend({\n toolResult: z.unknown().nonoptional(),\n }),\n);\nexport type CallToolResult = z.infer<typeof CallToolResultSchema>;\n\nconst ResourceTemplateSchema = z\n .object({\n uriTemplate: z.string(),\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n })\n .loose();\n\nexport const ListResourceTemplatesResultSchema = ResultSchema.extend({\n resourceTemplates: z.array(ResourceTemplateSchema),\n});\nexport type ListResourceTemplatesResult = z.infer<\n typeof ListResourceTemplatesResultSchema\n>;\n\nexport const ReadResourceResultSchema = ResultSchema.extend({\n contents: z.array(\n z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),\n ),\n});\nexport type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;\n\n// Completions\nconst PromptReferenceSchema = z\n .object({\n type: z.literal('ref/prompt'),\n name: z.string(),\n })\n .loose();\n\nconst ResourceReferenceSchema = z\n .object({\n type: z.literal('ref/resource'),\n uri: z.string(),\n })\n .loose();\n\nconst CompletionArgumentSchema = z\n .object({\n name: z.string(),\n value: z.string(),\n })\n .loose();\n\nexport const CompleteRequestParamsSchema = BaseParamsSchema.extend({\n ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),\n argument: CompletionArgumentSchema,\n context: z.optional(\n z\n .object({\n arguments: z.record(z.string(), z.string()),\n })\n .loose(),\n ),\n});\nexport type CompleteRequestParams = z.infer<typeof CompleteRequestParamsSchema>;\n\nexport const CompleteResultSchema = ResultSchema.extend({\n completion: z\n .object({\n values: z.array(z.string()).max(100),\n total: z.optional(z.number().int()),\n hasMore: z.optional(z.boolean()),\n })\n .loose(),\n});\nexport type CompleteResult = z.infer<typeof CompleteResultSchema>;\n\n// Prompts\nconst PromptArgumentSchema = z\n .object({\n name: z.string(),\n description: z.optional(z.string()),\n required: z.optional(z.boolean()),\n })\n .loose();\n\nexport const PromptSchema = z\n .object({\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n arguments: z.optional(z.array(PromptArgumentSchema)),\n })\n .loose();\nexport type MCPPrompt = z.infer<typeof PromptSchema>;\n\nexport const ListPromptsResultSchema = PaginatedResultSchema.extend({\n prompts: z.array(PromptSchema),\n});\nexport type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;\n\nconst PromptMessageSchema = z\n .object({\n role: z.union([z.literal('user'), z.literal('assistant')]),\n content: z.union([\n TextContentSchema,\n ImageContentSchema,\n EmbeddedResourceSchema,\n ResourceLinkContentSchema,\n ]),\n })\n .loose();\nexport type MCPPromptMessage = z.infer<typeof PromptMessageSchema>;\n\nexport const GetPromptResultSchema = ResultSchema.extend({\n description: z.optional(z.string()),\n messages: z.array(PromptMessageSchema),\n});\nexport type GetPromptResult = z.infer<typeof GetPromptResultSchema>;\n\nconst ElicitationRequestParamsSchema = BaseParamsSchema.extend({\n message: z.string(),\n requestedSchema: z.unknown(),\n});\n\nexport const ElicitationRequestSchema = RequestSchema.extend({\n method: z.literal('elicitation/create'),\n params: ElicitationRequestParamsSchema,\n});\n\nexport type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;\n\nexport const ElicitResultSchema = ResultSchema.extend({\n action: z.union([\n z.literal('accept'),\n z.literal('decline'),\n z.literal('cancel'),\n ]),\n content: z.optional(z.record(z.string(), z.unknown())),\n});\n\nexport type ElicitResult = z.infer<typeof ElicitResultSchema>;\n","import { parseJSON } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { BaseParamsSchema, RequestSchema, ResultSchema } from './types';\n\nconst JSONRPC_VERSION = '2.0';\n\nconst JSONRPCRequestSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.union([z.string(), z.number().int()]),\n })\n .merge(RequestSchema)\n .strict();\n\nexport type JSONRPCRequest = z.infer<typeof JSONRPCRequestSchema>;\n\nconst JSONRPCResponseSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.union([z.string(), z.number().int()]),\n result: ResultSchema,\n })\n .strict();\n\nexport type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;\n\nconst JSONRPCErrorSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.optional(z.union([z.string(), z.number().int()])),\n error: z.object({\n code: z.number().int(),\n message: z.string(),\n data: z.optional(z.unknown()),\n }),\n })\n .strict();\n\nexport type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;\n\nconst JSONRPCNotificationSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n })\n .merge(\n z.object({\n method: z.string(),\n params: z.optional(BaseParamsSchema),\n }),\n )\n .strict();\n\nexport type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;\n\nexport const JSONRPCMessageSchema = z.union([\n JSONRPCRequestSchema,\n JSONRPCNotificationSchema,\n JSONRPCResponseSchema,\n JSONRPCErrorSchema,\n]);\n\nexport type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;\n\nexport function validateJSONRPCMessage(message: unknown): JSONRPCMessage {\n return JSONRPCMessageSchema.parse(message);\n}\n\nexport async function parseJSONRPCMessage(\n text: string,\n): Promise<JSONRPCMessage> {\n return validateJSONRPCMessage(await parseJSON({ text }));\n}\n","import { AISDKError } from '@ai-sdk/provider';\n\nconst name = 'AI_MCPClientError';\nconst marker = `vercel.ai.error.${name}`;\nconst symbol = Symbol.for(marker);\n\n/**\n * An error occurred with the MCP client.\n */\nexport class MCPClientError extends AISDKError {\n private readonly [symbol] = true;\n readonly data?: unknown;\n\n /**\n * JSON-RPC error code from the server response, per the JSON-RPC 2.0\n * spec (e.g. `-32601` method-not-found, `-32602` invalid-params, or\n * MCP-specific codes such as `-32002` resource-not-found). This is the\n * application-level error code populated from `error.code` in the\n * server's JSON-RPC error payload. Distinct from `statusCode`, which\n * is the HTTP transport status.\n */\n readonly code?: number;\n\n /**\n * HTTP status code from the failed response, when the error originated\n * from an HTTP-based transport. Undefined for stdio transport\n * errors and for failures that do not have an associated response\n * status (e.g. network errors, abort). Distinct from `code`, which is\n * the JSON-RPC application error code.\n */\n readonly statusCode?: number;\n\n /**\n * URL of the MCP endpoint the failing request was sent to, when the\n * error originated from an HTTP transport failure.\n */\n readonly url?: string;\n\n /**\n * Body of the failing HTTP response, decoded as text, when available.\n * Undefined when the body could not be read or the error did not have\n * an associated response.\n */\n readonly responseBody?: string;\n\n constructor({\n name = 'MCPClientError',\n message,\n cause,\n data,\n code,\n statusCode,\n url,\n responseBody,\n }: {\n name?: string;\n message: string;\n cause?: unknown;\n data?: unknown;\n code?: number;\n statusCode?: number;\n url?: string;\n responseBody?: string;\n }) {\n super({ name, message, cause });\n this.data = data;\n this.code = code;\n this.statusCode = statusCode;\n this.url = url;\n this.responseBody = responseBody;\n }\n\n static isInstance(error: unknown): error is MCPClientError {\n return AISDKError.hasMarker(error, marker);\n }\n}\n","/**\n * Constructs the environment variables for the child process.\n *\n * @param customEnv - Custom environment variables to merge with default environment variables.\n * @returns The environment variables for the child process.\n */\nexport function getEnvironment(\n customEnv?: Record<string, string>,\n): Record<string, string> {\n const isWindows = globalThis.process.platform === 'win32';\n const DEFAULT_INHERITED_ENV_VARS = isWindows\n ? [\n 'APPDATA',\n 'HOMEDRIVE',\n 'HOMEPATH',\n 'LOCALAPPDATA',\n 'PATH',\n 'PROCESSOR_ARCHITECTURE',\n 'SYSTEMDRIVE',\n 'SYSTEMROOT',\n 'TEMP',\n 'USERNAME',\n 'USERPROFILE',\n ]\n : ['HOME', 'LOGNAME', 'PATH', 'SHELL', 'TERM', 'USER'];\n\n const env: Record<string, string> = customEnv ? { ...customEnv } : {};\n const customEnvKeys = new Set(\n Object.keys(env).map(key => (isWindows ? key.toUpperCase() : key)),\n );\n\n for (const key of DEFAULT_INHERITED_ENV_VARS) {\n if (customEnvKeys.has(key)) {\n continue;\n }\n\n const value = globalThis.process.env[key];\n if (value === undefined) {\n continue;\n }\n\n if (value.startsWith('()')) {\n continue;\n }\n\n env[key] = value;\n }\n\n return env;\n}\n","import type { ChildProcess } from 'node:child_process';\nimport spawn from 'cross-spawn';\nimport { getEnvironment } from './get-environment';\nimport type { StdioConfig } from './mcp-stdio-transport';\n\nexport function createChildProcess(\n config: StdioConfig,\n signal: AbortSignal,\n): ChildProcess {\n if (\n globalThis.process.platform === 'win32' &&\n [config.command, ...(config.args ?? [])].some(value => /[\\r\\n]/.test(value))\n ) {\n throw new TypeError(\n 'Stdio MCP commands and arguments must not contain line breaks on Windows.',\n );\n }\n\n return spawn(config.command, config.args ?? [], {\n env: getEnvironment(config.env),\n stdio: ['pipe', 'pipe', config.stderr ?? 'inherit'],\n shell: config.shell ?? false,\n signal,\n windowsHide: globalThis.process.platform === 'win32' && isElectron(),\n cwd: config.cwd,\n });\n}\n\nfunction isElectron() {\n return 'type' in globalThis.process;\n}\n","import type { ChildProcess, IOType } from 'node:child_process';\nimport type { Stream } from 'node:stream';\nimport { parseJSONRPCMessage, type JSONRPCMessage } from '../json-rpc-message';\nimport type { MCPTransport } from '../mcp-transport';\nimport { MCPClientError } from '../../error/mcp-client-error';\nimport { createChildProcess } from './create-child-process';\n\nexport interface StdioConfig {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n stderr?: IOType | Stream | number;\n cwd?: string;\n shell?: boolean | string;\n}\n\nexport class StdioMCPTransport implements MCPTransport {\n readonly supportsProtocolVersionDiscovery = true;\n private process?: ChildProcess;\n private abortController: AbortController = new AbortController();\n private readBuffer: ReadBuffer = new ReadBuffer();\n private serverParams: StdioConfig;\n\n onclose?: () => void;\n onerror?: (error: unknown) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(server: StdioConfig) {\n this.serverParams = server;\n }\n\n async start(): Promise<void> {\n if (this.process) {\n throw new MCPClientError({\n message: 'StdioMCPTransport already started.',\n });\n }\n\n return new Promise((resolve, reject) => {\n try {\n const process = createChildProcess(\n this.serverParams,\n this.abortController.signal,\n );\n\n this.process = process;\n\n this.process.on('error', error => {\n if (error.name === 'AbortError') {\n this.onclose?.();\n return;\n }\n\n reject(error);\n this.onerror?.(error);\n });\n\n this.process.on('spawn', () => {\n resolve();\n });\n\n this.process.on('close', _code => {\n this.process = undefined;\n this.onclose?.();\n });\n\n this.process.stdin?.on('error', error => {\n this.onerror?.(error);\n });\n\n this.process.stdout?.on('data', chunk => {\n this.readBuffer.append(chunk);\n void this.processReadBuffer();\n });\n\n this.process.stdout?.on('error', error => {\n this.onerror?.(error);\n });\n } catch (error) {\n reject(error);\n this.onerror?.(error);\n }\n });\n }\n\n private async processReadBuffer() {\n while (true) {\n const line = this.readBuffer.readLine();\n if (line === null) {\n break;\n }\n\n try {\n const message = await deserializeMessage(line);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(error as Error);\n }\n }\n }\n\n async close(): Promise<void> {\n this.abortController.abort();\n this.process = undefined;\n this.readBuffer.clear();\n }\n\n send(message: JSONRPCMessage): Promise<void> {\n return new Promise(resolve => {\n if (!this.process?.stdin) {\n throw new MCPClientError({\n message: 'StdioClientTransport not connected',\n });\n }\n\n const json = serializeMessage(message);\n if (this.process.stdin.write(json)) {\n resolve();\n } else {\n this.process.stdin.once('drain', resolve);\n }\n });\n }\n}\n\nclass ReadBuffer {\n private buffer?: Buffer;\n\n append(chunk: Buffer): void {\n this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;\n }\n\n readLine(): string | null {\n if (!this.buffer) return null;\n\n const index = this.buffer.indexOf('\\n');\n if (index === -1) {\n return null;\n }\n\n const line = this.buffer.toString('utf8', 0, index);\n this.buffer = this.buffer.subarray(index + 1);\n return line;\n }\n\n clear(): void {\n this.buffer = undefined;\n }\n}\n\nfunction serializeMessage(message: JSONRPCMessage): string {\n return JSON.stringify(message) + '\\n';\n}\n\nexport async function deserializeMessage(\n line: string,\n): Promise<JSONRPCMessage> {\n return parseJSONRPCMessage(line);\n}\n"],"mappings":";;;;;;AA0CA,MAAM,iBAAiB,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;AA6CnE,MAAM,qCAAqC,EAAE,YAAY;CACvD,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,OAAO;CAClB,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC;AAC9B,CAAC;AAKD,MAAa,mBAAmB,EAAE,YAAY,EAC5C,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EACxC,CAAC;AAED,MAAa,eAAe,iBAAiB,OAAO,EAClD,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,EACnC,CAA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QAER,KAAK,QAAQ,MAAM,KAAK,SAAS,OAAO;EAE5C,CAAC;CACH;AACF;AAEA,IAAM,aAAN,MAAiB;CAGf,OAAO,OAAqB;EAC1B,KAAK,SAAS,KAAK,SAAS,OAAO,OAAO,CAAC,KAAK,QAAQ,KAAK,CAAC,IAAI;CACpE;CAEA,WAA0B;EACxB,IAAI,CAAC,KAAK,QAAQ,OAAO;EAEzB,MAAM,QAAQ,KAAK,OAAO,QAAQ,IAAI;EACtC,IAAI,UAAU,IACZ,OAAO;EAGT,MAAM,OAAO,KAAK,OAAO,SAAS,QAAQ,GAAG,KAAK;EAClD,KAAK,SAAS,KAAK,OAAO,SAAS,QAAQ,CAAC;EAC5C,OAAO;CACT;CAEA,QAAc;EACZ,KAAK,SAAS,KAAA;CAChB;AACF;AAEA,SAAS,iBAAiB,SAAiC;CACzD,OAAO,KAAK,UAAU,OAAO,IAAI;AACnC;AAEA,eAAsB,mBACpB,MACyB;CACzB,OAAO,oBAAoB,IAAI;AACjC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/tool/types.ts","../../src/tool/json-rpc-message.ts","../../src/error/mcp-client-error.ts","../../src/tool/mcp-stdio/get-environment.ts","../../src/tool/mcp-stdio/create-child-process.ts","../../src/tool/mcp-stdio/mcp-stdio-transport.ts","../../src/tool/mcp-stdio/index.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport type { JSONObject } from '@ai-sdk/provider';\nimport type {\n FlexibleSchema,\n Tool,\n ToolExecutionOptions,\n} from '@ai-sdk/provider-utils';\n\nexport const LATEST_PROTOCOL_VERSION = '2026-07-28';\nexport const LATEST_LEGACY_PROTOCOL_VERSION = '2025-11-25';\nexport const SUPPORTED_PROTOCOL_VERSIONS = [\n LATEST_PROTOCOL_VERSION,\n LATEST_LEGACY_PROTOCOL_VERSION,\n '2025-06-18',\n '2025-03-26',\n '2024-11-05',\n];\n\nexport type McpProviderMetadata = {\n clientName?: string;\n title?: string;\n toolName?: string;\n annotations?: McpToolAnnotations;\n app?: JSONObject;\n};\n\n/**\n * Behavioral hints reported by an MCP server for a tool.\n *\n * These annotations are untrusted unless the server itself is trusted.\n *\n * @see https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations\n */\nexport type McpToolAnnotations = {\n title?: string;\n readOnlyHint?: boolean;\n destructiveHint?: boolean;\n idempotentHint?: boolean;\n openWorldHint?: boolean;\n};\n\n/** MCP tool metadata - keys should follow MCP _meta key format specification */\nconst ToolMetaSchema = z.optional(z.record(z.string(), z.unknown()));\nexport type ToolMeta = z.infer<typeof ToolMetaSchema>;\n\nexport type ToolSchemas =\n | Record<\n string,\n {\n inputSchema: FlexibleSchema<JSONObject | unknown>;\n outputSchema?: FlexibleSchema<JSONObject | unknown>;\n }\n >\n | 'automatic'\n | undefined;\n\n/** Base MCP tool type with execute and _meta */\ntype McpToolBase<INPUT = unknown, OUTPUT = CallToolResult> = Tool<\n INPUT,\n OUTPUT\n> & {\n execute: (\n input: INPUT,\n options?: ToolExecutionOptions<{}>,\n ) => ReturnType<NonNullable<Tool<INPUT, OUTPUT>['execute']>>;\n _meta?: ToolMeta;\n};\n\nexport type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> =\n TOOL_SCHEMAS extends Record<\n string,\n { inputSchema: FlexibleSchema<any>; outputSchema?: FlexibleSchema<any> }\n >\n ? {\n [K in keyof TOOL_SCHEMAS]: TOOL_SCHEMAS[K] extends {\n inputSchema: FlexibleSchema<infer INPUT>;\n outputSchema: FlexibleSchema<infer OUTPUT>;\n }\n ? McpToolBase<INPUT, OUTPUT>\n : TOOL_SCHEMAS[K] extends {\n inputSchema: FlexibleSchema<infer INPUT>;\n }\n ? McpToolBase<INPUT, CallToolResult>\n : never;\n }\n : Record<string, McpToolBase<unknown, CallToolResult>>;\n\nconst ClientOrServerImplementationSchema = z.looseObject({\n name: z.string(),\n version: z.string(),\n title: z.optional(z.string()),\n});\n\n// Maps to `Implementation` in the MCP specification\nexport type Configuration = z.infer<typeof ClientOrServerImplementationSchema>;\n\nexport const BaseParamsSchema = z.looseObject({\n _meta: z.optional(z.object({}).loose()),\n});\ntype BaseParams = z.infer<typeof BaseParamsSchema>;\nexport const ResultSchema = BaseParamsSchema.extend({\n resultType: z.optional(z.string()),\n});\n\nexport const RequestSchema = z.object({\n method: z.string(),\n params: z.optional(BaseParamsSchema),\n});\nexport type Request = z.infer<typeof RequestSchema>;\nexport type RequestOptions = {\n signal?: AbortSignal;\n timeout?: number;\n maxTotalTimeout?: number;\n};\n\nexport type Notification = z.infer<typeof RequestSchema>;\n\n/** @see https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation */\nconst ElicitationCapabilitySchema = z\n .object({\n applyDefaults: z.optional(z.boolean()),\n })\n .loose();\n\nconst ServerCapabilitiesSchema = z.looseObject({\n events: z.looseObject({ listChanged: z.boolean().nullish() }).nullish(),\n experimental: z.optional(z.object({}).loose()),\n logging: z.optional(z.object({}).loose()),\n completions: z.optional(z.object({}).loose()),\n prompts: z.optional(\n z.looseObject({\n listChanged: z.optional(z.boolean()),\n }),\n ),\n resources: z.optional(\n z.looseObject({\n subscribe: z.optional(z.boolean()),\n listChanged: z.optional(z.boolean()),\n }),\n ),\n tools: z.optional(\n z.looseObject({\n listChanged: z.optional(z.boolean()),\n }),\n ),\n elicitation: z.optional(ElicitationCapabilitySchema),\n});\n\nexport type ServerCapabilities = z.infer<typeof ServerCapabilitiesSchema>;\nexport const ClientCapabilitiesSchema = z\n .object({\n elicitation: z.optional(ElicitationCapabilitySchema),\n })\n .loose();\n\nexport type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;\nexport type ElicitationCapability = z.infer<typeof ElicitationCapabilitySchema>;\n\nexport const DiscoverResultSchema = ResultSchema.extend({\n supportedVersions: z.array(z.string()),\n capabilities: ServerCapabilitiesSchema,\n instructions: z.optional(z.string()),\n ttlMs: z.optional(z.number()),\n cacheScope: z.optional(z.union([z.literal('public'), z.literal('private')])),\n});\nexport type DiscoverResult = z.infer<typeof DiscoverResultSchema>;\n\nexport const InitializeResultSchema = ResultSchema.extend({\n protocolVersion: z.string(),\n capabilities: ServerCapabilitiesSchema,\n serverInfo: ClientOrServerImplementationSchema,\n instructions: z.optional(z.string()),\n});\nexport type InitializeResult = z.infer<typeof InitializeResultSchema>;\n\nexport type PaginatedRequest = Request & {\n params?: BaseParams & {\n cursor?: string;\n };\n};\n\nconst PaginatedResultSchema = ResultSchema.extend({\n nextCursor: z.optional(z.string()),\n});\n\nconst ToolSchema = z\n .object({\n name: z.string(),\n /**\n * @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool\n */\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n inputSchema: z.looseObject({\n type: z.optional(z.unknown()),\n properties: z.optional(z.object({}).loose()),\n }),\n /**\n * @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema\n */\n outputSchema: z.optional(z.object({}).loose()),\n annotations: z.optional(\n z\n .object({\n title: z.optional(z.string()),\n readOnlyHint: z.optional(z.boolean()),\n destructiveHint: z.optional(z.boolean()),\n idempotentHint: z.optional(z.boolean()),\n openWorldHint: z.optional(z.boolean()),\n })\n .loose(),\n ),\n _meta: ToolMetaSchema,\n })\n .loose();\nexport type MCPTool = z.infer<typeof ToolSchema>;\nexport const ListToolsResultSchema = PaginatedResultSchema.extend({\n tools: z.array(ToolSchema),\n});\nexport type ListToolsResult = z.infer<typeof ListToolsResultSchema>;\n\nconst TextContentSchema = z\n .object({\n type: z.literal('text'),\n text: z.string(),\n })\n .loose();\nconst ImageContentSchema = z\n .object({\n type: z.literal('image'),\n data: z.base64(),\n mimeType: z.string(),\n })\n .loose();\nexport const ResourceSchema = z\n .object({\n uri: z.string(),\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n size: z.optional(z.number()),\n })\n .loose();\nexport type MCPResource = z.infer<typeof ResourceSchema>;\n\nexport const ListResourcesResultSchema = PaginatedResultSchema.extend({\n resources: z.array(ResourceSchema),\n});\nexport type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;\n\nconst ResourceContentsSchema = z\n .object({\n /**\n * The URI of this resource.\n */\n uri: z.string(),\n /**\n * Optional display name of the resource content.\n */\n name: z.optional(z.string()),\n /**\n * Optional human readable title.\n */\n title: z.optional(z.string()),\n /**\n * The MIME type of this resource, if known.\n */\n mimeType: z.optional(z.string()),\n })\n .loose();\nconst TextResourceContentsSchema = ResourceContentsSchema.extend({\n text: z.string(),\n});\nconst BlobResourceContentsSchema = ResourceContentsSchema.extend({\n blob: z.base64(),\n});\nconst EmbeddedResourceSchema = z\n .object({\n type: z.literal('resource'),\n resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),\n })\n .loose();\nconst ResourceLinkContentSchema = z\n .object({\n type: z.literal('resource_link'),\n uri: z.string(),\n name: z.string(),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n })\n .loose();\nconst UnknownContentSchema = z\n .object({ type: z.string() })\n .loose()\n .refine(\n content =>\n !['text', 'image', 'resource', 'resource_link'].includes(content.type),\n { message: 'Known content types must match their schema' },\n );\n\nconst CallToolResultWithContentSchema = ResultSchema.extend({\n content: z.array(\n z.union([\n TextContentSchema,\n ImageContentSchema,\n EmbeddedResourceSchema,\n ResourceLinkContentSchema,\n UnknownContentSchema,\n ]),\n ),\n /**\n * @see https://modelcontextprotocol.io/specification/2026-07-28/server/tools#structured-content\n */\n structuredContent: z.optional(z.unknown()),\n isError: z.boolean().default(false).optional(),\n});\n\nconst CallToolResultWithStructuredContentSchema = ResultSchema.extend({\n content: z.never().optional(),\n structuredContent: z.json(),\n isError: z.boolean().default(false).optional(),\n})\n .transform(\n (result): z.infer<typeof CallToolResultWithContentSchema> => ({\n ...result,\n content: [\n {\n type: 'text',\n text: JSON.stringify(result.structuredContent),\n },\n ],\n }),\n )\n .pipe(CallToolResultWithContentSchema);\n\nexport const CallToolResultSchema = CallToolResultWithContentSchema.or(\n CallToolResultWithStructuredContentSchema,\n).or(\n ResultSchema.extend({\n toolResult: z.unknown().nonoptional(),\n }),\n);\nexport type CallToolResult = z.infer<typeof CallToolResultSchema>;\n\nconst ResourceTemplateSchema = z\n .object({\n uriTemplate: z.string(),\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n mimeType: z.optional(z.string()),\n })\n .loose();\n\nexport const ListResourceTemplatesResultSchema = ResultSchema.extend({\n resourceTemplates: z.array(ResourceTemplateSchema),\n});\nexport type ListResourceTemplatesResult = z.infer<\n typeof ListResourceTemplatesResultSchema\n>;\n\nexport const ReadResourceResultSchema = ResultSchema.extend({\n contents: z.array(\n z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),\n ),\n});\nexport type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;\n\n// Completions\nconst PromptReferenceSchema = z\n .object({\n type: z.literal('ref/prompt'),\n name: z.string(),\n })\n .loose();\n\nconst ResourceReferenceSchema = z\n .object({\n type: z.literal('ref/resource'),\n uri: z.string(),\n })\n .loose();\n\nconst CompletionArgumentSchema = z\n .object({\n name: z.string(),\n value: z.string(),\n })\n .loose();\n\nexport const CompleteRequestParamsSchema = BaseParamsSchema.extend({\n ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),\n argument: CompletionArgumentSchema,\n context: z.optional(\n z\n .object({\n arguments: z.record(z.string(), z.string()),\n })\n .loose(),\n ),\n});\nexport type CompleteRequestParams = z.infer<typeof CompleteRequestParamsSchema>;\n\nexport const CompleteResultSchema = ResultSchema.extend({\n completion: z\n .object({\n values: z.array(z.string()).max(100),\n total: z.optional(z.number().int()),\n hasMore: z.optional(z.boolean()),\n })\n .loose(),\n});\nexport type CompleteResult = z.infer<typeof CompleteResultSchema>;\n\n// Prompts\nconst PromptArgumentSchema = z\n .object({\n name: z.string(),\n description: z.optional(z.string()),\n required: z.optional(z.boolean()),\n })\n .loose();\n\nexport const PromptSchema = z\n .object({\n name: z.string(),\n title: z.optional(z.string()),\n description: z.optional(z.string()),\n arguments: z.optional(z.array(PromptArgumentSchema)),\n })\n .loose();\nexport type MCPPrompt = z.infer<typeof PromptSchema>;\n\nexport const ListPromptsResultSchema = PaginatedResultSchema.extend({\n prompts: z.array(PromptSchema),\n});\nexport type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;\n\nconst PromptMessageSchema = z\n .object({\n role: z.union([z.literal('user'), z.literal('assistant')]),\n content: z.union([\n TextContentSchema,\n ImageContentSchema,\n EmbeddedResourceSchema,\n ResourceLinkContentSchema,\n ]),\n })\n .loose();\nexport type MCPPromptMessage = z.infer<typeof PromptMessageSchema>;\n\nexport const GetPromptResultSchema = ResultSchema.extend({\n description: z.optional(z.string()),\n messages: z.array(PromptMessageSchema),\n});\nexport type GetPromptResult = z.infer<typeof GetPromptResultSchema>;\n\nconst ElicitationRequestParamsSchema = BaseParamsSchema.extend({\n message: z.string(),\n requestedSchema: z.unknown(),\n});\n\nexport const ElicitationRequestSchema = RequestSchema.extend({\n method: z.literal('elicitation/create'),\n params: ElicitationRequestParamsSchema,\n});\n\nexport type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;\n\nexport const ElicitResultSchema = ResultSchema.extend({\n action: z.union([\n z.literal('accept'),\n z.literal('decline'),\n z.literal('cancel'),\n ]),\n content: z.optional(z.record(z.string(), z.unknown())),\n});\n\nexport type ElicitResult = z.infer<typeof ElicitResultSchema>;\n\nexport const InputRequiredResultSchema = ResultSchema.extend({\n resultType: z.literal('input_required'),\n inputRequests: z.record(z.string(), RequestSchema).optional(),\n requestState: z.string().optional(),\n}).refine(\n result =>\n result.inputRequests !== undefined || result.requestState !== undefined,\n { message: 'input_required must include inputRequests or requestState' },\n);\n\n// Only form elicitation is supported by the client's existing handler API.\nexport const InputRequiredElicitationSchema = ElicitationRequestSchema.extend({\n params: ElicitationRequestParamsSchema.extend({\n mode: z.literal('form').optional(),\n requestedSchema: z.looseObject({ type: z.literal('object') }),\n }),\n});\n","import { parseJSON } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { BaseParamsSchema, RequestSchema, ResultSchema } from './types';\n\nconst JSONRPC_VERSION = '2.0';\n\nconst JSONRPCRequestSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.union([z.string(), z.number().int()]),\n })\n .merge(RequestSchema)\n .strict();\n\nexport type JSONRPCRequest = z.infer<typeof JSONRPCRequestSchema>;\n\nconst JSONRPCResponseSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.union([z.string(), z.number().int()]),\n result: ResultSchema,\n })\n .strict();\n\nexport type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;\n\nconst JSONRPCErrorSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n id: z.optional(z.union([z.string(), z.number().int()])),\n error: z.object({\n code: z.number().int(),\n message: z.string(),\n data: z.optional(z.unknown()),\n }),\n })\n .strict();\n\nexport type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;\n\nconst JSONRPCNotificationSchema = z\n .object({\n jsonrpc: z.literal(JSONRPC_VERSION),\n })\n .merge(\n z.object({\n method: z.string(),\n params: z.optional(BaseParamsSchema),\n }),\n )\n .strict();\n\nexport type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;\n\nexport const JSONRPCMessageSchema = z.union([\n JSONRPCRequestSchema,\n JSONRPCNotificationSchema,\n JSONRPCResponseSchema,\n JSONRPCErrorSchema,\n]);\n\nexport type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;\n\nexport function validateJSONRPCMessage(message: unknown): JSONRPCMessage {\n return JSONRPCMessageSchema.parse(message);\n}\n\nexport async function parseJSONRPCMessage(\n text: string,\n): Promise<JSONRPCMessage> {\n return validateJSONRPCMessage(await parseJSON({ text }));\n}\n","import { AISDKError } from '@ai-sdk/provider';\n\nconst name = 'AI_MCPClientError';\nconst marker = `vercel.ai.error.${name}`;\nconst symbol = Symbol.for(marker);\n\n/**\n * An error occurred with the MCP client.\n */\nexport class MCPClientError extends AISDKError {\n private readonly [symbol] = true;\n readonly data?: unknown;\n\n /**\n * JSON-RPC error code from the server response, per the JSON-RPC 2.0\n * spec (e.g. `-32601` method-not-found, `-32602` invalid-params, or\n * MCP-specific codes such as `-32002` resource-not-found). This is the\n * application-level error code populated from `error.code` in the\n * server's JSON-RPC error payload. Distinct from `statusCode`, which\n * is the HTTP transport status.\n */\n readonly code?: number;\n\n /**\n * HTTP status code from the failed response, when the error originated\n * from an HTTP-based transport. Undefined for stdio transport\n * errors and for failures that do not have an associated response\n * status (e.g. network errors, abort). Distinct from `code`, which is\n * the JSON-RPC application error code.\n */\n readonly statusCode?: number;\n\n /**\n * URL of the MCP endpoint the failing request was sent to, when the\n * error originated from an HTTP transport failure.\n */\n readonly url?: string;\n\n /**\n * Body of the failing HTTP response, decoded as text, when available.\n * Undefined when the body could not be read or the error did not have\n * an associated response.\n */\n readonly responseBody?: string;\n\n constructor({\n name = 'MCPClientError',\n message,\n cause,\n data,\n code,\n statusCode,\n url,\n responseBody,\n }: {\n name?: string;\n message: string;\n cause?: unknown;\n data?: unknown;\n code?: number;\n statusCode?: number;\n url?: string;\n responseBody?: string;\n }) {\n super({ name, message, cause });\n this.data = data;\n this.code = code;\n this.statusCode = statusCode;\n this.url = url;\n this.responseBody = responseBody;\n }\n\n static isInstance(error: unknown): error is MCPClientError {\n return AISDKError.hasMarker(error, marker);\n }\n}\n","/**\n * Constructs the environment variables for the child process.\n *\n * @param customEnv - Custom environment variables to merge with default environment variables.\n * @returns The environment variables for the child process.\n */\nexport function getEnvironment(\n customEnv?: Record<string, string>,\n): Record<string, string> {\n const isWindows = globalThis.process.platform === 'win32';\n const DEFAULT_INHERITED_ENV_VARS = isWindows\n ? [\n 'APPDATA',\n 'HOMEDRIVE',\n 'HOMEPATH',\n 'LOCALAPPDATA',\n 'PATH',\n 'PROCESSOR_ARCHITECTURE',\n 'SYSTEMDRIVE',\n 'SYSTEMROOT',\n 'TEMP',\n 'USERNAME',\n 'USERPROFILE',\n ]\n : ['HOME', 'LOGNAME', 'PATH', 'SHELL', 'TERM', 'USER'];\n\n const env: Record<string, string> = customEnv ? { ...customEnv } : {};\n const customEnvKeys = new Set(\n Object.keys(env).map(key => (isWindows ? key.toUpperCase() : key)),\n );\n\n for (const key of DEFAULT_INHERITED_ENV_VARS) {\n if (customEnvKeys.has(key)) {\n continue;\n }\n\n const value = globalThis.process.env[key];\n if (value === undefined) {\n continue;\n }\n\n if (value.startsWith('()')) {\n continue;\n }\n\n env[key] = value;\n }\n\n return env;\n}\n","import type { ChildProcess } from 'node:child_process';\nimport spawn from 'cross-spawn';\nimport { getEnvironment } from './get-environment';\nimport type { StdioConfig } from './mcp-stdio-transport';\n\nexport function createChildProcess(\n config: StdioConfig,\n signal: AbortSignal,\n): ChildProcess {\n if (\n globalThis.process.platform === 'win32' &&\n [config.command, ...(config.args ?? [])].some(value => /[\\r\\n]/.test(value))\n ) {\n throw new TypeError(\n 'Stdio MCP commands and arguments must not contain line breaks on Windows.',\n );\n }\n\n return spawn(config.command, config.args ?? [], {\n env: getEnvironment(config.env),\n stdio: ['pipe', 'pipe', config.stderr ?? 'inherit'],\n shell: config.shell ?? false,\n signal,\n windowsHide: globalThis.process.platform === 'win32' && isElectron(),\n cwd: config.cwd,\n });\n}\n\nfunction isElectron() {\n return 'type' in globalThis.process;\n}\n","import type { ChildProcess, IOType } from 'node:child_process';\nimport type { Stream } from 'node:stream';\nimport { parseJSONRPCMessage, type JSONRPCMessage } from '../json-rpc-message';\nimport type { MCPTransport } from '../mcp-transport';\nimport { MCPClientError } from '../../error/mcp-client-error';\nimport { createChildProcess } from './create-child-process';\n\nexport interface StdioConfig {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n stderr?: IOType | Stream | number;\n cwd?: string;\n shell?: boolean | string;\n}\n\nexport class StdioMCPTransport implements MCPTransport {\n readonly supportsProtocolVersionDiscovery = true;\n private process?: ChildProcess;\n private abortController: AbortController = new AbortController();\n private readBuffer: ReadBuffer = new ReadBuffer();\n private serverParams: StdioConfig;\n\n onclose?: () => void;\n onerror?: (error: unknown) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(server: StdioConfig) {\n this.serverParams = server;\n }\n\n async start(): Promise<void> {\n if (this.process) {\n throw new MCPClientError({\n message: 'StdioMCPTransport already started.',\n });\n }\n\n return new Promise((resolve, reject) => {\n try {\n const process = createChildProcess(\n this.serverParams,\n this.abortController.signal,\n );\n\n this.process = process;\n\n this.process.on('error', error => {\n if (error.name === 'AbortError') {\n this.onclose?.();\n return;\n }\n\n reject(error);\n this.onerror?.(error);\n });\n\n this.process.on('spawn', () => {\n resolve();\n });\n\n this.process.on('close', _code => {\n this.process = undefined;\n this.onclose?.();\n });\n\n this.process.stdin?.on('error', error => {\n this.onerror?.(error);\n });\n\n this.process.stdout?.on('data', chunk => {\n this.readBuffer.append(chunk);\n void this.processReadBuffer();\n });\n\n this.process.stdout?.on('error', error => {\n this.onerror?.(error);\n });\n } catch (error) {\n reject(error);\n this.onerror?.(error);\n }\n });\n }\n\n private async processReadBuffer() {\n while (true) {\n const line = this.readBuffer.readLine();\n if (line === null) {\n break;\n }\n\n try {\n const message = await deserializeMessage(line);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(error as Error);\n }\n }\n }\n\n async close(): Promise<void> {\n this.abortController.abort();\n this.process = undefined;\n this.readBuffer.clear();\n }\n\n send(message: JSONRPCMessage): Promise<void> {\n return new Promise(resolve => {\n if (!this.process?.stdin) {\n throw new MCPClientError({\n message: 'StdioClientTransport not connected',\n });\n }\n\n const json = serializeMessage(message);\n if (this.process.stdin.write(json)) {\n resolve();\n } else {\n this.process.stdin.once('drain', resolve);\n }\n });\n }\n}\n\nclass ReadBuffer {\n private buffer?: Buffer;\n\n append(chunk: Buffer): void {\n this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;\n }\n\n readLine(): string | null {\n if (!this.buffer) return null;\n\n const index = this.buffer.indexOf('\\n');\n if (index === -1) {\n return null;\n }\n\n const line = this.buffer.toString('utf8', 0, index);\n this.buffer = this.buffer.subarray(index + 1);\n return line;\n }\n\n clear(): void {\n this.buffer = undefined;\n }\n}\n\nfunction serializeMessage(message: JSONRPCMessage): string {\n return JSON.stringify(message) + '\\n';\n}\n\nexport async function deserializeMessage(\n line: string,\n): Promise<JSONRPCMessage> {\n return parseJSONRPCMessage(line);\n}\n","import { StdioMCPTransport } from './mcp-stdio-transport';\n\nexport { StdioMCPTransport, type StdioConfig } from './mcp-stdio-transport';\n\n/**\n * @deprecated Use `StdioMCPTransport` instead.\n */\nexport const Experimental_StdioMCPTransport = StdioMCPTransport;\n\n/**\n * @deprecated Use `StdioMCPTransport` instead.\n */\nexport type Experimental_StdioMCPTransport = StdioMCPTransport;\n"],"mappings":";;;;;;AA0CA,MAAM,iBAAiB,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;AA6CnE,MAAM,qCAAqC,EAAE,YAAY;CACvD,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,OAAO;CAClB,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC;AAC9B,CAAC;AAKD,MAAa,mBAAmB,EAAE,YAAY,EAC5C,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EACxC,CAAC;AAED,MAAa,eAAe,iBAAiB,OAAO,EAClD,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,EACnC,CAAC;AAED,MAAa,gBAAgB,EAAE,OAAO;CACpC,QAAQ,EAAE,OAAO;CACjB,QAAQ,EAAE,SAAS,gBAAgB;AACrC,CAAC;;AAWD,MAAM,8BAA8B,EACjC,OAAO,EACN,eAAe,EAAE,SAAS,EAAE,QAAQ,CAAC,EACvC,CAAC,CAAC,CACD,MAAM;AAET,MAAM,2BAA2B,EAAE,YAAY;CAC7C,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAA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,KAAK,SAAS,OACjB,MAAM,IAAI,eAAe,EACvB,SAAS,qCACX,CAAC;GAGH,MAAM,OAAO,iBAAiB,OAAO;GACrC,IAAI,KAAK,QAAQ,MAAM,MAAM,IAAI,GAC/B,QAAQ;QAER,KAAK,QAAQ,MAAM,KAAK,SAAS,OAAO;EAE5C,CAAC;CACH;AACF;AAEA,IAAM,aAAN,MAAiB;CAGf,OAAO,OAAqB;EAC1B,KAAK,SAAS,KAAK,SAAS,OAAO,OAAO,CAAC,KAAK,QAAQ,KAAK,CAAC,IAAI;CACpE;CAEA,WAA0B;EACxB,IAAI,CAAC,KAAK,QAAQ,OAAO;EAEzB,MAAM,QAAQ,KAAK,OAAO,QAAQ,IAAI;EACtC,IAAI,UAAU,IACZ,OAAO;EAGT,MAAM,OAAO,KAAK,OAAO,SAAS,QAAQ,GAAG,KAAK;EAClD,KAAK,SAAS,KAAK,OAAO,SAAS,QAAQ,CAAC;EAC5C,OAAO;CACT;CAEA,QAAc;EACZ,KAAK,SAAS,KAAA;CAChB;AACF;AAEA,SAAS,iBAAiB,SAAiC;CACzD,OAAO,KAAK,UAAU,OAAO,IAAI;AACnC;AAEA,eAAsB,mBACpB,MACyB;CACzB,OAAO,oBAAoB,IAAI;AACjC;;;;;;ACvJA,MAAa,iCAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.88",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ai-sdk/provider": "4.0.
|
|
35
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider": "4.0.35",
|
|
35
|
+
"@ai-sdk/provider-utils": "5.0.72",
|
|
36
36
|
"cross-spawn": "^7.0.6",
|
|
37
37
|
"pkce-challenge": "^5.0.1"
|
|
38
38
|
},
|
package/src/tool/mcp-client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
asSchema,
|
|
4
|
+
delay,
|
|
4
5
|
dynamicTool,
|
|
5
6
|
jsonSchema,
|
|
6
7
|
retryWithExponentialBackoff,
|
|
@@ -49,6 +50,8 @@ import {
|
|
|
49
50
|
ElicitationRequestSchema,
|
|
50
51
|
ElicitResultSchema,
|
|
51
52
|
InitializeResultSchema,
|
|
53
|
+
InputRequiredElicitationSchema,
|
|
54
|
+
InputRequiredResultSchema,
|
|
52
55
|
LATEST_LEGACY_PROTOCOL_VERSION,
|
|
53
56
|
LATEST_PROTOCOL_VERSION,
|
|
54
57
|
ListResourceTemplatesResultSchema,
|
|
@@ -56,6 +59,7 @@ import {
|
|
|
56
59
|
ListPromptsResultSchema,
|
|
57
60
|
ListToolsResultSchema,
|
|
58
61
|
ReadResourceResultSchema,
|
|
62
|
+
ResultSchema,
|
|
59
63
|
GetPromptResultSchema,
|
|
60
64
|
SUPPORTED_PROTOCOL_VERSIONS,
|
|
61
65
|
type CallToolResult,
|
|
@@ -87,6 +91,8 @@ import {
|
|
|
87
91
|
const CLIENT_VERSION = '1.0.0';
|
|
88
92
|
const DEFAULT_MAX_TOOL_CALL_RETRIES = 0;
|
|
89
93
|
const DEFAULT_PROTOCOL_DISCOVERY_TIMEOUT = 1000;
|
|
94
|
+
const MAX_INPUT_REQUIRED_ROUNDS = 10;
|
|
95
|
+
const INPUT_REQUIRED_RETRY_DELAY = 250;
|
|
90
96
|
const MODERN_PROTOCOL_ERROR_CODES = [-32020, -32021, -32022];
|
|
91
97
|
|
|
92
98
|
const DEFAULT_RETRY_ERROR_CODES = [
|
|
@@ -400,11 +406,24 @@ export interface MCPClient {
|
|
|
400
406
|
options?: RequestOptions;
|
|
401
407
|
}): Promise<ListResourceTemplatesResult>;
|
|
402
408
|
|
|
409
|
+
listPrompts(options?: {
|
|
410
|
+
params?: PaginatedRequest['params'];
|
|
411
|
+
options?: RequestOptions;
|
|
412
|
+
}): Promise<ListPromptsResult>;
|
|
413
|
+
|
|
414
|
+
getPrompt(args: {
|
|
415
|
+
name: string;
|
|
416
|
+
arguments?: Record<string, unknown>;
|
|
417
|
+
options?: RequestOptions;
|
|
418
|
+
}): Promise<GetPromptResult>;
|
|
419
|
+
|
|
420
|
+
/** @deprecated Use `listPrompts` instead. */
|
|
403
421
|
experimental_listPrompts(options?: {
|
|
404
422
|
params?: PaginatedRequest['params'];
|
|
405
423
|
options?: RequestOptions;
|
|
406
424
|
}): Promise<ListPromptsResult>;
|
|
407
425
|
|
|
426
|
+
/** @deprecated Use `getPrompt` instead. */
|
|
408
427
|
experimental_getPrompt(args: {
|
|
409
428
|
name: string;
|
|
410
429
|
arguments?: Record<string, unknown>;
|
|
@@ -470,6 +489,7 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
470
489
|
private protocolVersion = LATEST_LEGACY_PROTOCOL_VERSION;
|
|
471
490
|
private toolHeaderBindings = new Map<string, MCPToolHeaderBinding[]>();
|
|
472
491
|
private isClosed = true;
|
|
492
|
+
private readonly closeController = new AbortController();
|
|
473
493
|
private elicitationRequestHandler?: (
|
|
474
494
|
request: ElicitationRequest,
|
|
475
495
|
) => Promise<ElicitResult> | ElicitResult;
|
|
@@ -875,6 +895,139 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
875
895
|
request: Request;
|
|
876
896
|
resultSchema: T;
|
|
877
897
|
options?: RequestOptions;
|
|
898
|
+
}): Promise<z.infer<T>> {
|
|
899
|
+
if (
|
|
900
|
+
this.isClosed ||
|
|
901
|
+
this.protocolEra !== 'modern' ||
|
|
902
|
+
!['tools/call', 'prompts/get', 'resources/read'].includes(request.method)
|
|
903
|
+
) {
|
|
904
|
+
return this.requestOnce({ request, resultSchema, options });
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
options?.signal?.throwIfAborted();
|
|
908
|
+
const startedAt = Date.now();
|
|
909
|
+
let nextRequest = request;
|
|
910
|
+
|
|
911
|
+
for (let round = 0; ; round++) {
|
|
912
|
+
const timeout = getEffectiveTimeout({
|
|
913
|
+
timeout: options?.timeout,
|
|
914
|
+
maxTotalTimeout:
|
|
915
|
+
options?.maxTotalTimeout == null
|
|
916
|
+
? undefined
|
|
917
|
+
: Math.max(0, options.maxTotalTimeout - (Date.now() - startedAt)),
|
|
918
|
+
});
|
|
919
|
+
const timeoutController = new AbortController();
|
|
920
|
+
const signal = AbortSignal.any([
|
|
921
|
+
this.closeController.signal,
|
|
922
|
+
timeoutController.signal,
|
|
923
|
+
...(options?.signal == null ? [] : [options.signal]),
|
|
924
|
+
]);
|
|
925
|
+
const timeoutError = new MCPClientError({
|
|
926
|
+
message: `Request timed out after ${timeout}ms`,
|
|
927
|
+
});
|
|
928
|
+
const timeoutId =
|
|
929
|
+
timeout == null
|
|
930
|
+
? undefined
|
|
931
|
+
: setTimeout(() => timeoutController.abort(timeoutError), timeout);
|
|
932
|
+
|
|
933
|
+
try {
|
|
934
|
+
signal.throwIfAborted();
|
|
935
|
+
if (timeout === 0) throw timeoutError;
|
|
936
|
+
|
|
937
|
+
const result = await this.requestOnce({
|
|
938
|
+
request: nextRequest,
|
|
939
|
+
resultSchema: ResultSchema,
|
|
940
|
+
options: { signal },
|
|
941
|
+
allowInputRequired: true,
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
if (result.resultType !== 'input_required') {
|
|
945
|
+
return resultSchema.parse(result);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
const { inputRequests, requestState } =
|
|
949
|
+
InputRequiredResultSchema.parse(result);
|
|
950
|
+
if (round === MAX_INPUT_REQUIRED_ROUNDS) {
|
|
951
|
+
throw new MCPClientError({
|
|
952
|
+
message: `Request still requires input after ${MAX_INPUT_REQUIRED_ROUNDS} rounds`,
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
const responses: Record<string, ElicitResult> = Object.create(null);
|
|
957
|
+
for (const [key, inputRequest] of Object.entries(inputRequests ?? {})) {
|
|
958
|
+
signal.throwIfAborted();
|
|
959
|
+
if (
|
|
960
|
+
inputRequest.method !== 'elicitation/create' ||
|
|
961
|
+
(inputRequest.params?.mode != null &&
|
|
962
|
+
inputRequest.params.mode !== 'form')
|
|
963
|
+
) {
|
|
964
|
+
throw new MCPClientError({
|
|
965
|
+
message: `Unsupported input request: ${inputRequest.method}. Only form elicitation is supported.`,
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
if (!this.elicitationRequestHandler) {
|
|
969
|
+
throw new MCPClientError({
|
|
970
|
+
message:
|
|
971
|
+
'Server requested input, but no handler is registered. Use onElicitationRequest to handle elicitation.',
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
const parsedRequest =
|
|
976
|
+
InputRequiredElicitationSchema.parse(inputRequest);
|
|
977
|
+
const answer = await waitForAbort(
|
|
978
|
+
Promise.resolve(this.elicitationRequestHandler(parsedRequest)),
|
|
979
|
+
signal,
|
|
980
|
+
);
|
|
981
|
+
responses[key] = ElicitResultSchema.parse(answer);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const hasResponses = Object.keys(responses).length > 0;
|
|
985
|
+
if (!hasResponses) {
|
|
986
|
+
await delay(INPUT_REQUIRED_RETRY_DELAY, { abortSignal: signal });
|
|
987
|
+
}
|
|
988
|
+
signal.throwIfAborted();
|
|
989
|
+
|
|
990
|
+
// Rebuild from the original request so state and answers never leak
|
|
991
|
+
// from an earlier round into a later one.
|
|
992
|
+
nextRequest = {
|
|
993
|
+
...request,
|
|
994
|
+
params: {
|
|
995
|
+
...request.params,
|
|
996
|
+
...(hasResponses ? { inputResponses: responses } : {}),
|
|
997
|
+
...(requestState !== undefined ? { requestState } : {}),
|
|
998
|
+
},
|
|
999
|
+
};
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
if (signal.aborted) {
|
|
1002
|
+
throw options?.signal?.aborted
|
|
1003
|
+
? new MCPClientError({
|
|
1004
|
+
message: 'Request was aborted',
|
|
1005
|
+
cause: options.signal.reason,
|
|
1006
|
+
})
|
|
1007
|
+
: signal.reason;
|
|
1008
|
+
}
|
|
1009
|
+
throw MCPClientError.isInstance(error)
|
|
1010
|
+
? error
|
|
1011
|
+
: new MCPClientError({
|
|
1012
|
+
message: 'Failed to process server response',
|
|
1013
|
+
cause: error,
|
|
1014
|
+
});
|
|
1015
|
+
} finally {
|
|
1016
|
+
clearTimeout(timeoutId);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
private async requestOnce<T extends z.ZodType<object>>({
|
|
1022
|
+
request,
|
|
1023
|
+
resultSchema,
|
|
1024
|
+
options,
|
|
1025
|
+
allowInputRequired = false,
|
|
1026
|
+
}: {
|
|
1027
|
+
request: Request;
|
|
1028
|
+
resultSchema: T;
|
|
1029
|
+
options?: RequestOptions;
|
|
1030
|
+
allowInputRequired?: boolean;
|
|
878
1031
|
}): Promise<z.infer<T>> {
|
|
879
1032
|
return new Promise((resolve, reject) => {
|
|
880
1033
|
if (this.isClosed) {
|
|
@@ -980,10 +1133,12 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
980
1133
|
message: 'Modern MCP result is missing resultType',
|
|
981
1134
|
});
|
|
982
1135
|
}
|
|
983
|
-
if (
|
|
1136
|
+
if (
|
|
1137
|
+
response.result.resultType === 'input_required' &&
|
|
1138
|
+
!allowInputRequired
|
|
1139
|
+
) {
|
|
984
1140
|
throw new MCPClientError({
|
|
985
|
-
message:
|
|
986
|
-
'Server requested additional input, but multi round-trip requests are not supported yet',
|
|
1141
|
+
message: `Input-required results are not supported for ${request.method} on protocol ${this.protocolVersion}`,
|
|
987
1142
|
});
|
|
988
1143
|
}
|
|
989
1144
|
|
|
@@ -1474,7 +1629,7 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
1474
1629
|
return this.listResourceTemplatesInternal({ options });
|
|
1475
1630
|
}
|
|
1476
1631
|
|
|
1477
|
-
|
|
1632
|
+
listPrompts({
|
|
1478
1633
|
params,
|
|
1479
1634
|
options,
|
|
1480
1635
|
}: {
|
|
@@ -1484,7 +1639,7 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
1484
1639
|
return this.listPromptsInternal({ params, options });
|
|
1485
1640
|
}
|
|
1486
1641
|
|
|
1487
|
-
|
|
1642
|
+
getPrompt({
|
|
1488
1643
|
name,
|
|
1489
1644
|
arguments: args,
|
|
1490
1645
|
options,
|
|
@@ -1496,6 +1651,20 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
1496
1651
|
return this.getPromptInternal({ name, args, options });
|
|
1497
1652
|
}
|
|
1498
1653
|
|
|
1654
|
+
/** @deprecated Use `listPrompts` instead. */
|
|
1655
|
+
experimental_listPrompts(
|
|
1656
|
+
options?: Parameters<MCPClient['listPrompts']>[0],
|
|
1657
|
+
): Promise<ListPromptsResult> {
|
|
1658
|
+
return this.listPrompts(options);
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/** @deprecated Use `getPrompt` instead. */
|
|
1662
|
+
experimental_getPrompt(
|
|
1663
|
+
args: Parameters<MCPClient['getPrompt']>[0],
|
|
1664
|
+
): Promise<GetPromptResult> {
|
|
1665
|
+
return this.getPrompt(args);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1499
1668
|
complete(
|
|
1500
1669
|
args: CompleteRequestParams & {
|
|
1501
1670
|
options?: RequestOptions;
|
|
@@ -1609,6 +1778,8 @@ class DefaultMCPClient implements Omit<MCPClient, 'experimental_events'> {
|
|
|
1609
1778
|
message: 'Connection closed',
|
|
1610
1779
|
});
|
|
1611
1780
|
|
|
1781
|
+
this.closeController.abort(error);
|
|
1782
|
+
|
|
1612
1783
|
for (const handler of this.responseHandlers.values()) {
|
|
1613
1784
|
handler(error);
|
|
1614
1785
|
}
|
|
@@ -102,7 +102,7 @@ export class HttpMCPTransport implements MCPTransport {
|
|
|
102
102
|
this.onSessionIdChange = onSessionIdChange;
|
|
103
103
|
this.onSessionExpired = onSessionExpired;
|
|
104
104
|
this.terminateSessionOnClose = terminateSessionOnClose;
|
|
105
|
-
this.fetchFn = fetchFn ?? globalThis.fetch;
|
|
105
|
+
this.fetchFn = fetchFn ?? globalThis.fetch.bind(globalThis);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
setProtocolVersion(version: string): void {
|
|
@@ -58,7 +58,7 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
58
58
|
this.headers = headers;
|
|
59
59
|
this.authProvider = authProvider;
|
|
60
60
|
this.redirectMode = redirect;
|
|
61
|
-
this.fetchFn = fetchFn ?? globalThis.fetch;
|
|
61
|
+
this.fetchFn = fetchFn ?? globalThis.fetch.bind(globalThis);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
setProtocolVersion(version: string): void {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { StdioMCPTransport } from './mcp-stdio-transport';
|
|
2
|
+
|
|
3
|
+
export { StdioMCPTransport, type StdioConfig } from './mcp-stdio-transport';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `StdioMCPTransport` instead.
|
|
7
|
+
*/
|
|
8
|
+
export const Experimental_StdioMCPTransport = StdioMCPTransport;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `StdioMCPTransport` instead.
|
|
12
|
+
*/
|
|
13
|
+
export type Experimental_StdioMCPTransport = StdioMCPTransport;
|
package/src/tool/types.ts
CHANGED
|
@@ -478,3 +478,21 @@ export const ElicitResultSchema = ResultSchema.extend({
|
|
|
478
478
|
});
|
|
479
479
|
|
|
480
480
|
export type ElicitResult = z.infer<typeof ElicitResultSchema>;
|
|
481
|
+
|
|
482
|
+
export const InputRequiredResultSchema = ResultSchema.extend({
|
|
483
|
+
resultType: z.literal('input_required'),
|
|
484
|
+
inputRequests: z.record(z.string(), RequestSchema).optional(),
|
|
485
|
+
requestState: z.string().optional(),
|
|
486
|
+
}).refine(
|
|
487
|
+
result =>
|
|
488
|
+
result.inputRequests !== undefined || result.requestState !== undefined,
|
|
489
|
+
{ message: 'input_required must include inputRequests or requestState' },
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
// Only form elicitation is supported by the client's existing handler API.
|
|
493
|
+
export const InputRequiredElicitationSchema = ElicitationRequestSchema.extend({
|
|
494
|
+
params: ElicitationRequestParamsSchema.extend({
|
|
495
|
+
mode: z.literal('form').optional(),
|
|
496
|
+
requestedSchema: z.looseObject({ type: z.literal('object') }),
|
|
497
|
+
}),
|
|
498
|
+
});
|