Skip to content

Conversation

@limehawk
Copy link

Summary

Fixes #745

The Zod v3 branch of toJsonSchemaCompat doesn't pass a target option to zod-to-json-schema, causing it to default to draft-07. This breaks compatibility with Claude's API (and other modern MCP clients) which require strict JSON Schema draft-2020-12 compliance.

Users see errors like:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools.31.custom.input_schema: JSON schema is invalid. It must match JSON Schema draft 2020-12"}}

Changes

  • Add target: 'jsonSchema2020-12' to the zodToJsonSchema call for Zod v3 schemas in packages/core/src/util/zodJsonSchemaCompat.ts

Testing

Verified that MCP tools now work with Claude Code without the "JSON schema is invalid" error after applying this fix as a patch to node_modules.

@limehawk limehawk requested a review from a team as a code owner January 30, 2026 20:05
@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: 74cb8ce

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 30, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1432

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1432

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1432

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1432

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1432

commit: 74cb8ce

@limehawk
Copy link
Author

Note: This is a workaround, not a comprehensive fix.

As mentioned in #745, the proper solution would be to upgrade to Zod v4's native toJSONSchema({ target: "draft-2020-12" }) which has first-class support for draft-2020-12.

This PR works by passing an unrecognized target value ('jsonSchema2020-12') to zod-to-json-schema, which causes it to omit the $schema field entirely. Without the $schema: "http://json-schema.org/draft-07/schema#" declaration, Claude's API accepts the schema since the actual syntax is compatible.

This is a stopgap to unblock users hitting the 400 error today. A proper migration to Zod v4's native JSON Schema generation would be the better long-term fix.

@limehawk limehawk closed this Jan 30, 2026
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.

MCP TypeScript SDK generates JSON Schema draft-07, breaking compatibility with modern MCP clients requiring draft-2020-12

1 participant