Skip to content

fix: widen elicitInput requestedSchema type for Zod compatibility#1685

Closed
travisbreaks wants to merge 1 commit intomodelcontextprotocol:mainfrom
travisbreaks:fix/widen-elicit-requested-schema-type
Closed

fix: widen elicitInput requestedSchema type for Zod compatibility#1685
travisbreaks wants to merge 1 commit intomodelcontextprotocol:mainfrom
travisbreaks:fix/widen-elicit-requested-schema-type

Conversation

@travisbreaks
Copy link

Summary

Widens the requestedSchema type in elicitInput to accept standard JSON Schema output from Zod's .toJSONSchema(), fixing the type incompatibility reported in #1362.

The problem: Zod v4's .toJSONSchema() returns objects with extra standard JSON Schema fields ($schema, additionalProperties, etc.). The SDK's requestedSchema type was a closed object that rejected these at the type level, forcing users to cast through unknown.

The fix (minimal, two changes):

  • types.ts: Added .passthrough() to the Zod schema so extra fields pass runtime validation
  • spec.types.ts: Added [key: string]: unknown index signature to match the widened Zod type

Required fields (type: 'object', properties) remain strictly typed.

Test plan

  • All 440 core tests pass
  • All 386 integration tests pass
  • Lint passes
  • Typecheck passes (including spec.types.test.ts mutual-assignability checks)
  • Changeset included (patch for @modelcontextprotocol/core)

Fixes #1362.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

…ema output

Zod v4's `.toJSONSchema()` produces standard JSON Schema output that includes
fields like `$schema` and `additionalProperties`. The `requestedSchema` type
in `ElicitRequestFormParams` was too narrow to accept these extra fields,
forcing users to cast through `unknown`.

This adds `.passthrough()` to the Zod runtime schema and an index signature
to the spec type, allowing any additional JSON Schema fields through while
keeping the required fields (`type`, `properties`) strictly typed.

Fixes modelcontextprotocol#1362

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@travisbreaks travisbreaks requested a review from a team as a code owner March 16, 2026 07:42
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: e5b1274

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 16, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1685

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1685

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1685

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1685

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1685

commit: e5b1274

@travisbreaks
Copy link
Author

Duplicate of #1686. Closing this one in favor of the cleaner 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.

[TypeScript] Zod's .toJSONSchema() output type incompatible with elicitInput's requestedSchema parameter

1 participant