Skip to content

fix(server): preserve plain JSON Schema in deprecated server.tool() overload#1617

Open
stakeswky wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
stakeswky:fix/tool-json-schema-1585
Open

fix(server): preserve plain JSON Schema in deprecated server.tool() overload#1617
stakeswky wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
stakeswky:fix/tool-json-schema-1585

Conversation

@stakeswky
Copy link

Summary

Fixes #1585.

When using deprecated server.tool(name, description, inputSchema, callback) with a plain JSON Schema object, the schema was misclassified as ToolAnnotations and silently discarded.

This PR updates the overload parsing logic to:

  • Accept plain JSON Schema objects (detected via type: 'object' or properties) as inputSchema
  • Validate annotation objects before treating them as ToolAnnotations
  • Throw a descriptive error for invalid non-schema object arguments

It also ensures listed tool schemas preserve plain JSON Schema definitions rather than converting them through Zod-shape normalization.

Changes

  • src/server/mcp.ts
    • Add isToolAnnotations() runtime guard
    • Add isLikelyJsonSchema() runtime guard
    • Update deprecated tool() overload argument parsing to distinguish schema vs annotations safely
    • Emit descriptive error for invalid object argument
    • Preserve plain JSON Schema in tools/list response path
  • test/server/mcp.test.ts
    • Add regression test for plain JSON Schema via deprecated tool() overload
    • Add test that invalid non-schema/non-annotation object throws

Validation

  • pnpm exec vitest run test/server/mcp.test.ts (230 passed)

@stakeswky stakeswky requested a review from a team as a code owner March 2, 2026 22:48
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

⚠️ No Changeset found

Latest commit: 84331b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant