fix pdf-server outputSchema draft-07 dialect rejection - #766
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
|
Thanks Laurent! Good news is this went away with the SDK 2.0 migration (#720, just merged): |
|
Thanks @ochafik! Opened this for my team at Netflix looking to use the connector. Glad it's resolved. |
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.