fix: wrap MCP tool schemas with jsonSchema() in _buildNativeTools#473
fix: wrap MCP tool schemas with jsonSchema() in _buildNativeTools#473
Conversation
MCP tools returned by getVercelTools() have raw JSON Schema inputSchema objects. When passed directly to the Vercel AI SDK, asSchema() misidentifies them as Zod schemas and crashes with TypeError: Cannot read 'typeName'. Fix: wrap MCP tool schemas with jsonSchema() and tool() before adding to nativeTools, matching how wrapTool() handles native tool schemas. Adds 8 regression tests covering raw JSON Schema, empty schema, no schema, no description, nested schemas, mixed Zod/JSON Schema, and execute function preservation. Closes #472 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Overview: Fix MCP Tool Schema WrappingSummaryThis PR fixes a Root CauseThe Fix AppliedIn
Files Changed Analysis
Pattern: Minimal production code change (8 net lines) with comprehensive regression test coverage (8 new tests). Architecture & Impact AssessmentWhat This PR Accomplishes
Key Technical Changes
Affected System Componentsflowchart LR
subgraph "MCP Layer"
A[MCP Server] --> B[McpBridge]
B --> C[getVercelTools]
end
subgraph "Agent Layer"
D[ProbeAgent] --> E[_buildNativeTools]
E --> F{Schema Type?}
F -->|Zod _def| G[Pass through]
F -->|Raw JSON| H[Wrap with jsonSchema]
G --> I[tool wrapper]
H --> I
end
subgraph "Vercel AI SDK"
I --> J[streamText]
J --> K[prepareToolsAndToolChoice]
K --> L[asSchema]
end
C --> E
style H fill:#90EE90
style I fill:#87CEEB
Scope Discovery & Context ExpansionDirectly Related Files
Test Coverage Added8 new tests in
Potential Related Areas (not requiring changes)
Review Notes
Metadata
Powered by Visor from Probelabs Last updated: 2026-03-04T07:00:04.505Z | Triggered by: pr_opened | Commit: 80b6bd8 💡 TIP: You can chat with Visor using |
Security Issues (1)
Security Issues (1)
Performance Issues (1)
Quality Issues (1)
Powered by Visor from Probelabs Last updated: 2026-03-04T06:47:50.427Z | Triggered by: pr_opened | Commit: 80b6bd8 💡 TIP: You can chat with Visor using |
Summary
TypeError: Cannot read properties of undefined (reading 'typeName')when MCP tools with raw JSON Schema are passed to Vercel AI SDKjsonSchema()andtool()in_buildNativeTools()Closes #472
Root cause
mcpBridge.getVercelTools()returns MCP tools with raw JSON SchemainputSchemaobjects (e.g.{ type: 'object', properties: {...} }). These were added directly tonativeToolswithout wrapping. WhenstreamText()callsprepareToolsAndToolChoice(), the SDK'sasSchema()function misidentifies raw JSON Schema as Zod schemas (since they lack theschemaSymbolmarker), falls through tozodSchema(), and crashes onparseDef()readingdef.typeNamefrom undefined.Fix
Test plan
mcp-message-history.test.js:🤖 Generated with Claude Code