Skip to content

Conversation

@tlgimenes
Copy link

Background

I need tighter MCP ↔ LLM integration so tool call results can be better consumed without overflowing the context window. This enables downstream behaviors like reading specific properties, filtering, and validating/parsing results based on a tool’s declared output shape.

Summary

  • Normalized MCP tools/call results into LLM-friendly ToolResultOutput:
    • If the MCP server returns structured output (toolResult or structuredContent), we return it as JSON model output so the LLM (and app code) can work directly with properties.
    • If the MCP server marks the result as an error (isError), we return error text extracted from text content for better surfaced failures.
    • Otherwise we pass through the regular MCP content array.
  • Added support for outputSchema on MCP tool definitions and plumbed it through when building AI SDK tools, so consumers can parse/validate tool outputs using the declared schema.

Manual Verification

  • Fetched tools from the mock MCP server and verified the generated AI SDK tool includes the server-provided schemas (including outputSchema when present).
  • Executed a tool and verified the client produces a structured JSON model output when the MCP response contains structured results (and returns error text when isError is set).

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

  • Add docs/examples showing recommended patterns for consuming structured tool output (property access/filtering) and using outputSchema to parse results.

Related Issues

- Added a new function `toModelOutputFromMcpCallToolResult` to standardize the output processing from MCP calls, supporting various output formats.
- Updated `ToolSchemas` type to include optional `outputSchema` for better flexibility in tool definitions.
- Modified the `tools` method in `DefaultMCPClient` to utilize the new output handling function and improved schema handling for tool execution.

This update improves the robustness of tool output management and aligns with the evolving requirements of the MCP client.
@vercel-ai-sdk vercel-ai-sdk bot added the ai/mcp label Dec 30, 2025
@aayush-kapoor
Copy link
Contributor

marking this as closed since this has been fixed via #11543

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants