Skip to content

fix(core): allow extra JSON Schema keywords on elicitation primitive schemas#1949

Open
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:mainfrom
Zelys-DFKH:fix/elicit-primitive-schema-passthrough
Open

fix(core): allow extra JSON Schema keywords on elicitation primitive schemas#1949
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:mainfrom
Zelys-DFKH:fix/elicit-primitive-schema-passthrough

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Summary

Servers sending elicitation/create with standard JSON Schema keywords on primitive fields — pattern on a string, exclusiveMinimum on a number, const on a boolean — get them silently stripped. In stricter validator configs, the request fails outright. The spec describes requestedSchema as a "JSON Schema object" with no restriction on valid keywords, so the SDK was being stricter than the spec.

The fix is three .passthrough() calls on BooleanSchemaSchema, StringSchemaSchema, and NumberSchemaSchema. Also added [key: string]: unknown index signatures to the matching interfaces in spec.types.ts to keep the types consistent, and removed two @ts-expect-error comments in the elicitation tests that were papering over the resulting assignability errors.

Test plan

  • pnpm --filter @modelcontextprotocol/core test: all 489 existing tests pass
  • pnpm typecheck:all: clean
  • New regression tests in test/integration/test/server/elicitation.test.ts cover all three primitive types with extra keywords (pattern on string, exclusiveMinimum/exclusiveMaximum on number, const on boolean)

Fixes #1844

Primitive schema Zod validators (BooleanSchemaSchema, StringSchemaSchema,
NumberSchemaSchema) stripped any key not explicitly listed, rejecting valid
JSON Schema keywords like `pattern`, `exclusiveMinimum`, `const`, etc.

Added .passthrough() to all three so extra keys are preserved, and added
[key: string]: unknown index signatures to the matching spec.types interfaces
to maintain bidirectional type compatibility.

Closes modelcontextprotocol#1844

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Zelys-DFKH Zelys-DFKH requested a review from a team as a code owner April 23, 2026 16:03
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: a88c75a

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
Copy Markdown

pkg-pr-new Bot commented Apr 23, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1949

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1949

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1949

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1949

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1949

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1949

commit: a88c75a

Prettier formats long z.object({...}).passthrough() as a broken chain
with .passthrough() on its own line.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Elicit primitive schemas reject extra JSON Schema keys (pattern, format, etc.)

1 participant