fix pdf-server outputSchema draft-07 dialect rejection - #766
Open
bonallure wants to merge 1 commit into
Open
Conversation
@modelcontextprotocol/sdk always reports "$schema": draft-07 on Zod-derived tool schemas with no way to configure it, which strict 2020-12-only client validators reject before a tool call ever reaches the server. Adds fixOutputSchemaDialect() to rewrite the dialect and wires it into pdf-server, whose display_pdf/read_pdf_bytes/save_pdf tools hit this. Upstream bug: modelcontextprotocol/typescript-sdk#2721
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 #765
Motivation
display_pdfandinteractinexamples/pdf-serverfail client-side on any client with a strict JSON Schema 2020-12-only output-schema validator (Claude Desktop, Claude Code), before the tool call ever reaches the server:Root cause is in the pinned
@modelcontextprotocol/sdk(^1.29.0, still present in latest1.30.0): thetools/listhandler always emits"$schema": "http://json-schema.org/draft-07/schema#"on Zod-derivedinputSchema/outputSchema, with noregisterTool/registerAppTooloption to configure it (zod-json-schema-compat.js'smapMiniTarget()falls back to'draft-7'sincemcp.jsnever passes atarget). This is an already-filed, still-open upstream bug: modelcontextprotocol/typescript-sdk#2721 — there is no released SDK version that fixes it, so this can't be resolved by a version bump.What changed
src/server/index.ts: new exportedfixOutputSchemaDialect(server). Wraps the low-levelServer.setRequestHandlerto intercept the handlerMcpServerregisters forListToolsRequestSchema, rewriting"$schema": "http://json-schema.org/draft-07/schema#"to"https://json-schema.org/draft/2020-12/schema"on every tool'sinputSchema/outputSchemabefore the response goes out. Must be called immediately after constructingMcpServer, before any tool registration (documented in the JSDoc, with an@example).src/server/index.examples.ts: companionfixOutputSchemaDialect_basicUsageregion for the JSDoc example.src/server/index.test.ts: unit tests covering the rewrite and the pass-through case for other request schemas.examples/pdf-server/server.ts: callsfixOutputSchemaDialect(server)right afternew McpServer(...), beforelist_pdfsregisters.How it was verified
npm test— 376 pass, 1 pre-existing skip, 0 fail.npm run build— clean, no type errors.createServer()fromexamples/pdf-server, connected viaInMemoryTransport+ a real SDKClient, calledlistTools(). Confirmeddisplay_pdf/read_pdf_bytes/save_pdf'soutputSchema.$schema(and every tool'sinputSchema.$schema) is now2020-12,list_pdfs/interactunaffected, and a real tool call (list_pdfs) still round-trips correctly — the fix only touchestools/listschema metadata, not tool invocation.fixOutputSchemaDialectafter the first tool registration (instead of before) leaves the dialect at draft-07, sinceMcpServeronly installs its realtools/listhandler once, lazily, on first registration.Scope note: other examples (
budget-allocator-server,cohort-heatmap-server,system-monitor-server, etc.) declareoutputSchemaand hit the same bug but aren't touched here — kept this PR focused on the reportedpdf-serverfailure; noted them as follow-up in #765."Allow edits by maintainers" is checked.