From a1f80ed3d5670d0b0201b5d5757fe4c39014eda7 Mon Sep 17 00:00:00 2001 From: wucm667 Date: Tue, 28 Apr 2026 11:36:13 +0800 Subject: [PATCH] fix(mcp): pass tool outputSchema to Vercel AI SDK dynamicTool MCP tools can declare an outputSchema in their tool description, but the inspector was only using it for client-side validation and UI display. The outputSchema was never included in the structured tool definitions sent to the LLM via the Vercel AI SDK. This fixes the tool converters in both convertMCPToolsToVercelTools and the TestAgent tool conversion to include outputSchema when available, enabling LLMs to correctly interpret all response fields. --- sdk/src/TestAgent.ts | 1 + sdk/src/mcp-client-manager/tool-converters.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/TestAgent.ts b/sdk/src/TestAgent.ts index c8bb46321..7d092e86a 100644 --- a/sdk/src/TestAgent.ts +++ b/sdk/src/TestAgent.ts @@ -89,6 +89,7 @@ function convertToToolSet(tools: Tool[]): ToolSet { const converted = dynamicTool({ description: tool.description, inputSchema: jsonSchema(ensureJsonSchemaObject(tool.inputSchema)), + ...(tool.outputSchema ? { outputSchema: jsonSchema(tool.outputSchema as any) } : {}), execute: async (args, options) => { options?.abortSignal?.throwIfAborted?.(); const result = await tool.execute(args as Record); diff --git a/sdk/src/mcp-client-manager/tool-converters.ts b/sdk/src/mcp-client-manager/tool-converters.ts index 2a4dfff6f..cde10d422 100644 --- a/sdk/src/mcp-client-manager/tool-converters.ts +++ b/sdk/src/mcp-client-manager/tool-converters.ts @@ -215,7 +215,7 @@ export async function convertMCPToolsToVercelTools( const tools: ToolSet = {}; for (const toolDescription of listToolsResult.tools) { - const { name, description, inputSchema } = toolDescription; + const { name, description, inputSchema, outputSchema } = toolDescription; const toolMeta = toolDescription._meta as | Record | undefined; @@ -257,6 +257,7 @@ export async function convertMCPToolsToVercelTools( description, inputSchema: jsonSchema(normalizedInputSchema), execute, + ...(outputSchema ? { outputSchema: jsonSchema(outputSchema as any) } : {}), ...(toModelOutput ? { toModelOutput } : {}), ...(needsApproval != null ? { needsApproval } : {}), });