Skip to content

fix(mcp): drop JSON Schema annotations from tool schemas - #3560

Open
jsiu93 wants to merge 1 commit into
apache:mainfrom
jsiu93:fix/capability-provider-schema-annotations
Open

fix(mcp): drop JSON Schema annotations from tool schemas#3560
jsiu93 wants to merge 1 commit into
apache:mainfrom
jsiu93:fix/capability-provider-schema-annotations

Conversation

@jsiu93

@jsiu93 jsiu93 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

MCP servers built with the TypeScript SDK advertise Zod-derived input schemas with a root $schema. The capability provider copied those schemas into Client Capability frames, and the protocol's strict keyword allowlist rejected them, so publication stopped before the first tool.

This normalizes tool descriptors at MCP discovery (descriptorFromTool in packages/mcp): clone the input schema and delete exactly $schema and $comment from the root and from the child positions the validator walks (properties, items, additionalProperties, propertyNames, $defs/definitions, allOf/anyOf/oneOf). $id stays because it changes $ref base resolution; every other unsupported keyword still fails closed. The validator itself is unchanged.

The descriptor is the one place every MCP consumer reads from. Desktop's Client Capability projection covers Desktop-native Zod tools, not MCP descriptors, and already strips the $schema it generates.

Evidence for how common this is: a direct tools/list from XcodeBuildMCP 2.7.0 had $schema on 44/44 tools and no other disallowed keyword; an earlier probe through mcp_router saw it on 31/31. The SDK's server/zod-json-schema-compat.js emits it on both the zod-to-json-schema and z.toJSONSchema paths.

Fixes #3559

Verification

Regression test drops non-semantic JSON Schema annotations from discovered tools (stdio fixture with root $schema, nested $schema, $comment, $id): red before the change (descriptor still carried all three annotations), green after ($schema and $comment gone, $id kept).

npm --workspace @maka/mcp test           # tests 171, pass 171, fail 0
npm --workspace @maka/runtime-host test  # tests 1084, pass 1084, fail 0
npm --workspace maka-agent test          # tests 382, pass 382, fail 0
npm --workspace @maka/mcp run typecheck  # pass
npm run build                            # pass

biome lint and biome format on the three changed files reported no fixes.

Live, with fresh Runtime Host roots and bunx xcodebuildmcp mcp as the server:

before: CapabilityProviderPublicationError: Unsupported Client Capability tool schema keyword, exit 1
after:  Runtime Host capability provider is connected (24 MCP tools)

The live server advertised 24 tools in that fresh environment (XcodeBuildMCP exposes tools by workflow); the fixed provider published all 24 it received. The 44-tool figure comes from a separate direct capture of the same server.

Not run: the full monorepo npm test, root-wide typecheck, the Desktop and runtime workspace suites, Windows or Linux, a model turn that invokes a published tool.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: pi (gpt-5.6-sol) traced the MCP-to-Client-Capability path, wrote the regression test and the normalization helper, ran the live publication and the suites, and drafted this description. Claude Code chose the design, reviewed the diff, re-ran the mcp and CLI suites, and edited this text. The commit carries the trailer.

Generated-by: pi (gpt-5.6-sol)

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Client Capability validation intentionally keeps a strict keyword
allowlist. Normalize MCP tool descriptors during discovery by removing
only the non-semantic $schema and $comment annotations from supported
schema positions.

Keep $id because it changes $ref base resolution and must remain
subject to protocol validation.

Generated-by: pi (gpt-5.6-sol)
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.

bug(mcp): tools whose input schema carries $schema cannot be published as Client Capabilities

1 participant