Repository navigation
fix(core): accept MCP tools whose output schema is not a root object - #58224
Merged
Merged
Conversation
The MCP client SDK validates legacy tools/list results with an outputSchema that must be `type: "object"`. One tool with a top-level anyOf/oneOf schema makes the whole result invalid, so the server fails and none of its tools load. 2026-07-28 allows any JSON Schema here, and the SDK's own 2026-07-28 schema already accepts any object. Use that same shape for legacy connections in our SDK patch. Fixes #57643
Contributor
There was a problem hiding this comment.
Looks good. I reproduced #57643 from source on the base (Invalid result for tools/list … expected "object", server fails). With this change the same server connects. The new test fails on the base and passes here, and packages/core type-checks cleanly. The one failing test in mcp.test.ts (descendant termination) fails the same way on the base.
The patch only loosens the legacy outputSchema shape to match the SDK's own 2026-07-28 schema. inputSchema still requires type: "object", and the SDK's legacy wrapping happens only on the server side, so client-side structuredContent handling isn't affected.
Public API: unchanged.
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 #57643
Problem
If one tool in an MCP server's
tools/listhas anoutputSchemawith a top-levelanyOf/oneOfand no"type": "object", the whole server fails to connect and none of its tools load:The MCP client SDK validates legacy (pre-2026-07-28)
tools/listresults with a tool schema whoseoutputSchemamust betype: "object". 2025-06-18 and 2025-11-25 did declare that restriction, but 2026-07-28 allows any JSON Schema 2020-12 here, and real servers (cqs, 10 of 31 tools) already use it. The SDK rejects the whole list over one tool's metadata, and SDK 2.3.1 behaves the same, so upgrading would not fix this.Change
Our
@modelcontextprotocol/client@2.0.0patch now gives the legacy tool schema the sameoutputSchemashape as the SDK's own 2026-07-28 schema in the same file:const ToolSchema$1 = z.object({ ... inputSchema: z.object({ type: z.literal("object"), ... }).catchall(z.unknown()), - outputSchema: z.object({ - type: z.literal("object"), - properties: z.record(z.string(), JSONValueSchema$1).optional(), - required: z.array(z.string()).optional() - }).catchall(z.unknown()).optional(), + outputSchema: z.looseObject({ $schema: z.string().optional() }).optional(),inputSchemakeeps itstype: "object"requirement.listTools()still caches the schemas, socallToolstill validatesstructuredContentagainst them. Only the root-shape restriction onoutputSchemais gone.Out of scope
structuredContentmismatch is handled (mcp: output schema mismatch hard-fails tool calls instead of degrading gracefully #56116). Calls still fail on a mismatch, as before.Verification
accepts legacy MCP tools whose output schema is not a root object, using a raw JSON-RPC stdio fixture. The server SDK can't be used here, because it rewrites non-object output schemas for legacy clients. With the patch, the tool lists with itsanyOfschema intact and the call returns its structured result. Without it, the test fails with the error from the issue.type: "object"tool and one$defs+anyOftool: unpatched 2.0.0 and 2.3.1 both fail withInvalid result for tools/list; patched 2.0.0 lists both tools and calls theanyOfone successfully.bun test test/mcp.test.ts test/mcp-oauth.test.ts test/mcp-instructions.test.ts test/mcp-import-boundary.test.tsinpackages/core: 97 pass, 0 fail.bun run checkfrom the repo root: 34/34 tasks pass.