Repository navigation
fix: emit JSON Schema draft 2020-12 for tools/list (#32) - #33
Merged
Siumauricio merged 1 commit intoMay 13, 2026
Merged
Siumauricio merged 1 commit into
Siumauricio merged 1 commit into
Conversation
Claude's API rejects the default draft-07 output from the MCP SDK's Zod→JSON Schema converter with: tools.N.custom.input_schema: JSON schema is invalid. It must match JSON Schema draft 2020-12 Bypass the SDK's auto-registered tools/list handler with one that pre-generates schemas via zod-to-json-schema (targeting jsonSchema2019-09), strips any nested $schema keys, and sets the top-level $schema to https://json-schema.org/draft/2020-12/schema. The per-tool CallTool dispatch registered by server.tool() is untouched; only the schema serialization path changes.
|
+1 This solved my issues in claude code desktop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #32.
When an MCP client (e.g. Anthropic's Claude API) calls
tools/list, the server currently returns tool schemas tagged as"$schema": "http://json-schema.org/draft-07/schema#". Claude's API strictly requires JSON Schema draft 2020-12 and rejects the whole response with a 400InvalidRequestError, making every tool in this server unusable.Root cause:
McpServer.tool()auto-registers atools/listhandler that converts each Zod schema through the SDK's built-intoJsonSchemaCompat(). That helper delegates tozod-to-json-schemawhich emits draft-07 by default. Zod v3'sz.toJSONSchema(draft 2020-12) lives only in@modelcontextprotocol/[email protected], so every consumer of the stable SDK inherits the draft-07 output.Fix (Option A — pragmatic, ships today)
This PR overrides the auto-registered handler with a custom one that does the Zod → JSON Schema conversion in this package, then stamps the correct
$schemadraft. It does not touch SDK internals and does not require any alpha dependency.Concretely,
src/server.ts:server.tool(...)as before (so call handlers keep working).ListToolsRequestSchemahandler that replaces the SDK default:zodToJsonSchema(..., { target: "jsonSchema2019-09", strictUnions: true }).$schemakeys.$schematohttps://json-schema.org/draft/2020-12/schema.Draft 2019-09 is intentional: the
zod-to-json-schemapackage doesn't expose a"draft-2020-12"target, but 2019-09 is a strict subset of 2020-12 for the features emitted here (type,properties,required,enum,anyOf,description, etc.), so relabeling is safe.Verification
Built the fixed server and connected a fresh Claude Code MCP client to it. All 87 tools now load:
Checks:
Dependencies
Adds
zod-to-json-schemaas a direct dependency (it was already transitive via the SDK) so the explicit import is covered.Notes / Option B
An alternative would be to route through Standard Schema, which is the path newer MCP SDKs are taking. That support lives in
@modelcontextprotocol/[email protected], which is an alpha release with breaking API changes. Once that lands in a stable SDK, this local conversion can be removed. Until then, Option A keeps the project on the current stable SDK and unblocks Claude clients immediately.🤖 Generated with Claude Code