Skip to content

fix(agent): send an MCP tool's own JSON Schema to the model - #146

Open
w0nche0l wants to merge 2 commits into
mainfrom
dennisjeong/mcp-wire-input-schema
Open

w0nche0l wants to merge 2 commits into
mainfrom
dennisjeong/mcp-wire-input-schema

Conversation

@w0nche0l

@w0nche0l w0nche0l commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Linear: DEV-1381

Problem

wrapMcpTool converts an MCP tool's inputSchema to Zod (z.fromJSONSchema). convertToolsToAPIFormat then regenerates the model-facing parameters from that Zod schema (z.toJSONSchema, draft-07). Zod prints everything its validators check, so the model receives constraints the server never declared:

Server sends Model received
"format": "date-time" format plus a 400-character pattern (date 203, uuid 166, email 96)
"type": "integer" "minimum": -9007199254740991, "maximum": 9007199254740991
$ref + $defs the definition inlined at every use
object with no additionalProperties "additionalProperties": {}
$schema 2020-12 $schema draft-07

Change

MCP tools keep both schemas:

  • Wire: the server's JSON Schema is stored as function.wireInputSchema and serialized verbatim (still sanitized of ~-prefixed keys).
  • Validation: the Zod inputSchema is unchanged and still validates call arguments before callTool.

wireInputSchema already existed for manual tools (#118). It moves from ManualToolFunction to BaseToolFunction, convertToolsToAPIFormat drops the manual-only check, and markMcp accepts it as an option next to loopKey. The public tool() config still accepts wireInputSchema for manual tools only.

A server schema whose root is not type: "object" keeps the old behavior: the Zod conversion degrades it to an object, and that object is serialized.

Behavior change to review

Providers now receive the MCP server's schema as written. Before, the Zod pass normalized it to draft-07. A server schema that uses keywords a provider rejects (for example prefixItems) now reaches that provider unchanged. Before, such a schema was either rewritten to draft-07 or, where Zod could not convert it, replaced per property with z.unknown().

Validation is not loosened: the Zod schema still applies its own checks (format regexes, safe-integer bounds) to the model's arguments, as before.

How to test

pnpm --filter @openrouter/agent test — tests/unit/mcp/wire-input-schema.test.ts covers: the server's schema reaches parameters unchanged for format, integer, prefixItems and $ref/$defs; arguments are still validated by the Zod schema; a non-object root falls back to the Zod-derived object.

wrapMcpTool converted the server's inputSchema to Zod and the wire
parameters were regenerated from that Zod schema, which added a pattern
per string format, safe-integer bounds, and additionalProperties, and
inlined $ref/$defs. Keep both: serialize the server's schema, validate
with the Zod one.

Linear: DEV-1380

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant