[v1.x] fix(server): emit JSON Schema 2020-12 in tools/list (SEP-1613)#2085
Open
rsalus wants to merge 2 commits into
Open
[v1.x] fix(server): emit JSON Schema 2020-12 in tools/list (SEP-1613)#2085rsalus wants to merge 2 commits into
rsalus wants to merge 2 commits into
Conversation
McpServer's tools/list handler called toJsonSchemaCompat() without the target option, so mapMiniTarget(undefined) fell back to 'draft-7' and every inputSchema/outputSchema advertised draft-07, contradicting SEP-1613 / MCP 2025-11-25 spec. Pass target: 'draft-2020-12' at both call sites. For the Zod v4 branch, this surfaces native 2020-12 output (including prefixItems for tuples). For the Zod v3 branch — which uses zod-to-json-schema, a library with no 2020-12 target — overlay $schema in toJsonSchemaCompat when 2020-12 is requested; the emitted keyword subset (type, properties, required, additionalProperties, oneOf/anyOf/allOf, enum, const) is unchanged between draft-07 and 2020-12. Tests cover inputSchema and outputSchema $schema across both Zod versions, plus Zod v4 tuples emitting prefixItems. Fixes modelcontextprotocol#2084
🦋 Changeset detectedLatest commit: 4f16599 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 |
commit: |
Wrap long line in .changeset/fix-sep-1613-emit-2020-12.md to satisfy the repo's prettier config. No semantic change.
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.
Fixes #2084.
Summary
McpServer'stools/listhandler callstoJsonSchemaCompat()without atarget, somapMiniTarget(undefined)returns'draft-7'and everyinputSchema/outputSchemaadvertises draft-07 instead of the 2020-12 dialect SEP-1613 requires.The
target: 'draft-2020-12'plumbing was added in #1135, but themcp.tscall sites weren't updated to use it. This PR does that, plus an extra fix for the Zod v3 path that the 2-liner doesn't reach.What changed
src/server/mcp.ts— passtarget: 'draft-2020-12'at both call sites. That's the 2-line patch from the issue. For Zod v4 it's the whole fix:z4mini.toJSONSchemathen emits the right$schemaand usesprefixItemsfor tuples.src/server/zod-json-schema-compat.ts— the v3 branch needed more.zod-to-json-schemahas nodraft-2020-12target (onlyjsonSchema7andjsonSchema2019-09), so passing the option through is a silent no-op. The v3 branch now overrides$schematohttps://json-schema.org/draft/2020-12/schemawhen 2020-12 is requested.A caveat on the v3 override: the keywords
zod-to-json-schemaactually emits (type,properties,required,additionalProperties,oneOf/anyOf/allOf,enum,const) have identical semantics in draft-07 and 2020-12. The one keyword that diverges is tuples.items: [...]is a positional tuple in draft-07 but means "every item matches one of these schemas" in 2020-12. A Zod v3 tuple stamped as 2020-12 is therefore subtly wrong; an inline comment in the file flags this and points at Zod v4 for nativeprefixItems. IMO, leaving v3 stuck on draft-07 is worse than the caveat.test/server/mcp.test.ts: three new tests in the existingzodTestMatrixblock so they run on v3 and v4: inputSchema$schema, outputSchema$schema, and a v4-only tuple →prefixItemscheck..changeset/fix-sep-1613-emit-2020-12.md: patch-level changeset.Tests
npm test: 1584 / 1584 passnpm run typecheck: cleannpm run lint: cleanOn v2.0.0-alpha
maindoesn't have this bug.standardSchemaToJsonSchemahardcodestarget: 'draft-2020-12'at the conversion site, and v2 dropped Zod v3.Test plan
npm test(1584 / 1584)npm run typecheckpassesnpm run lintpasses