Skip to content

fix(mcp): declare 2020-12 dialect for tools/list schemas - #787

Open
chiliec wants to merge 1 commit into
pascalorg:mainfrom
chiliec:fix/mcp-tools-list-schema-dialect
Open

fix(mcp): declare 2020-12 dialect for tools/list schemas#787
chiliec wants to merge 1 commit into
pascalorg:mainfrom
chiliec:fix/mcp-tools-list-schema-dialect

Conversation

@chiliec

@chiliec chiliec commented Sep 8, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #696 — every tool call against the local @pascal-app/mcp server fails on clients that enforce JSON Schema 2020-12, because tools/list declares draft-07.

The MCP SDK's McpServer builds each tool's inputSchema/outputSchema with toJsonSchemaCompat and no target, so the compat layer falls back to draft-07. There's no version bump or registerTool option that changes this. The generated schemas contain no draft-07-only keywords (definitions, dependencies, $ref), so the fix re-registers the tools/list handler after tool registration and retargets the declared $schema to https://json-schema.org/draft/2020-12/schema on the way out — the approach the maintainer outlined in the issue.

How to test

  1. cd packages/core && bun run build (mcp tests import built @pascal-app/core/schema)
  2. cd ../mcp && bun test

New regression test src/tools/schema-dialect.test.ts asserts the raw tools/list payload 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)
  • New test alone: pass
  • RED→GREEN: removing normalizeToolSchemaDialect(server) makes the new test fail with the raw dialect showing http://json-schema.org/draft-07/schema#; restoring it turns it green.
  • biome check clean on the changed files; tsc -p tsconfig.json clean.

Screenshots / screen recording

N/A — headless MCP/server change, covered by the test above.

Checklist

  • I've tested this locally (bun test)
  • My code follows the existing code style (bun check)
  • I've updated relevant documentation (CHANGELOG)
  • This PR targets the main branch

Note

Low Risk
Response-shaping middleware on tools/list only; 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/list advertised the SDK default draft-07 $schema.

After tools, resources, and prompts are registered, normalizeToolSchemaDialect wraps the existing tools/list handler and recursively rewrites every $schema URL in the listed tool input/output schemas to https://json-schema.org/draft/2020-12/schema before 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.

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
@pascal

pascal Bot commented Sep 8, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tool output schemas declare draft-07 dialect — rejected by clients enforcing JSON Schema 2020-12

1 participant