fix: throw error when plain JSON Schema is passed as inputSchema to server.tool()#1598
Open
giulio-leone wants to merge 4 commits intomodelcontextprotocol:v1.xfrom
Open
Conversation
🦋 Changeset detectedLatest commit: 98010e1 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
added 4 commits
February 28, 2026 15:50
…erver.tool()
Previously, passing a plain JSON Schema object (e.g. { type: 'object', properties: {...} })
as the inputSchema parameter to server.tool() would silently misinterpret it as
ToolAnnotations, causing the schema to be dropped entirely. Tools would register
with empty parameter schemas ({ type: 'object', properties: {} }), leading to
silent data loss at runtime.
This adds a looksLikeJsonSchema() check that detects objects with JSON Schema
characteristic fields (type, properties, $schema, etc.) and throws a descriptive
error instructing users to use Zod schemas instead.
Fixes modelcontextprotocol#1585
Author
|
All CI checks pass. Ready for review. |
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.
Summary
server.tool()silently dropsinputSchemawhen a plain JSON Schema object is passed instead of a Zod schema. The object is misinterpreted asToolAnnotations, and the tool registers with an empty parameter schema — a silent data-loss bug.Root Cause
In
mcp.ts, the tool registration overload resolution checksisZodRawShapeCompat(firstArg). When this returnsfalse(as it does for plain JSON Schema objects, which lack.parse()/.safeParse()methods), the fallbackelse ifbranch unconditionally treats the object asToolAnnotations:Fix
Added a
looksLikeJsonSchema()helper that detects objects with JSON Schema characteristic fields (type,properties,$schema,items,allOf,anyOf,oneOf). When detected, a descriptive error is thrown:Tests
Added 3 new tests:
type/properties/required$schemapropertyToolAnnotations(readOnlyHint,destructiveHint)Verification
2 consecutive clean test runs: 1553/1553 tests passed, 0 failures.
Fixes #1585