fix(mcp): declare 2020-12 dialect for tools/list schemas - #787
Open
chiliec wants to merge 1 commit into
Open
Conversation
The MCP SDK emits tool schemas with a draft-07 dialect, so clients that enforce JSON Schema 2020-12 reject every tool call. The generated schemas use no draft-07-only keywords, so re-registering the tools/list handler to retarget the declared $schema is sufficient. Fixes pascalorg#696
|
I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…). Please try again, rephrase, or reach out if it keeps failing. Error id: 869d0816-2995-4c88-9905-72e3600722da |
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.
What does this PR do?
Fixes #696 — every tool call against the local
@pascal-app/mcpserver fails on clients that enforce JSON Schema 2020-12, becausetools/listdeclaresdraft-07.The MCP SDK's
McpServerbuilds each tool'sinputSchema/outputSchemawithtoJsonSchemaCompatand notarget, so the compat layer falls back todraft-07. There's no version bump orregisterTooloption that changes this. The generated schemas contain no draft-07-only keywords (definitions,dependencies,$ref), so the fix re-registers thetools/listhandler after tool registration and retargets the declared$schematohttps://json-schema.org/draft/2020-12/schemaon the way out — the approach the maintainer outlined in the issue.How to test
cd packages/core && bun run build(mcp tests import built@pascal-app/core/schema)cd ../mcp && bun testNew regression test
src/tools/schema-dialect.test.tsasserts the rawtools/listpayload only declares 2020-12 (validating through the SDK client — as the existing contract test does — would not catch this, since the client uses the SDK's own validator).Validation (real results)
bun test(packages/mcp): 357 pass, 0 fail (52 files)normalizeToolSchemaDialect(server)makes the new test fail with the raw dialect showinghttp://json-schema.org/draft-07/schema#; restoring it turns it green.biome checkclean on the changed files;tsc -p tsconfig.jsonclean.Screenshots / screen recording
N/A — headless MCP/server change, covered by the test above.
Checklist
bun test)bun check)mainbranchNote
Low Risk
Response-shaping middleware on
tools/listonly; behavior is covered by a regression test, though it depends on SDK-internal handler registration.Overview
Fixes #696: MCP clients that require JSON Schema 2020-12 were rejecting all tool calls because
tools/listadvertised the SDK default draft-07$schema.After tools, resources, and prompts are registered,
normalizeToolSchemaDialectwraps the existingtools/listhandler and recursively rewrites every$schemaURL in the listed tool input/output schemas tohttps://json-schema.org/draft/2020-12/schemabefore the response is returned—without changing schema structure (no draft-07-only keywords in play).A new integration test asserts the raw
listTools()payload only exposes the 2020-12 dialect; the Unreleased changelog entry documents the fix.Reviewed by Cursor Bugbot for commit 9509c9b. Bugbot is set up for automated code reviews on this repo. Configure here.