Skip to content

fix(mcp): pass tool outputSchema to Vercel AI SDK dynamicTool#1964

Open
wucm667 wants to merge 2 commits intoMCPJam:mainfrom
wucm667:fix/pass-output-schema-to-llm
Open

fix(mcp): pass tool outputSchema to Vercel AI SDK dynamicTool#1964
wucm667 wants to merge 2 commits intoMCPJam:mainfrom
wucm667:fix/pass-output-schema-to-llm

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented Apr 28, 2026

Fixes #1956

Problem

When an MCP server declares a tool with an outputSchema, the inspector reads it for client-side validation and UI display, but does NOT include it in the structured tool definitions sent to the LLM via the Vercel AI SDK. As a result, the LLM cannot interpret custom response fields defined in the output schema.

Changes

  • File 1: sdk/src/mcp-client-manager/tool-converters.ts

    • Extract outputSchema from the MCP tool description alongside name, description, and inputSchema
    • Pass outputSchema to dynamicTool() when available (automatic mode)
  • File 2: sdk/src/TestAgent.ts

    • Same fix: include outputSchema in the dynamicTool() call for the test agent's tool conversion

Impact

Before this fix, an MCP tool like:

@mcp.tool()
def get_weather(city: str) -> WeatherData:
    ...

Where WeatherData has a custom field x: int, would not pass the output schema to the LLM. The LLM could not interpret the x field in the response.

After this fix, the output schema is included in the tool definition, allowing the LLM to correctly understand and use all response fields.

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.
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 28, 2026
@chelojimenez
Copy link
Copy Markdown
Contributor

chelojimenez commented Apr 28, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4eb49ffa-6e2d-4c3d-a937-af8f366b4496

📥 Commits

Reviewing files that changed from the base of the PR and between 621323b and a1f80ed.

📒 Files selected for processing (2)
  • sdk/src/TestAgent.ts
  • sdk/src/mcp-client-manager/tool-converters.ts

Walkthrough

This change enhances tool conversion by introducing support for outputSchema. The conversion mechanism now extracts outputSchema from MCP tool descriptions and forwards it to Vercel's dynamicTool configuration in automatic conversion scenarios. When an outputSchema is present, it gets passed through; otherwise, the existing behavior is preserved. The change affects tool configuration within the SDK's tool conversion pipeline, enabling more complete schema information to be carried through the conversion process.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chelojimenez
Copy link
Copy Markdown
Contributor

thanks for putting this up @wucm667! i'll merge this tomorrow 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tool output schema is not passed to LLM

2 participants