Skip to content

Comments

fix(core): allow additional JSON Schema properties in elicitInput requestedSchema#1561

Open
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/zod-json-schema-compat
Open

fix(core): allow additional JSON Schema properties in elicitInput requestedSchema#1561
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/zod-json-schema-compat

Conversation

@corvid-agent
Copy link
Contributor

Summary

  • Adds .catchall(z.unknown()) to the requestedSchema object type in ElicitRequestFormParamsSchema, matching the existing pattern used by inputSchema and outputSchema for tool definitions
  • This allows Zod v4's .toJSONSchema() output (which includes extra properties like $schema and additionalProperties) to be passed directly to elicitInput() without type errors

Problem

When using Zod v4's .toJSONSchema() to generate a schema for elicitInput, the resulting object includes standard JSON Schema properties like $schema and additionalProperties that are not present in the requestedSchema TypeScript type. This works at runtime but fails type-checking, forcing users to use type casts.

// This fails type-checking today:
const result = await server.elicitInput({
  mode: 'form',
  message: 'Enter info',
  requestedSchema: z.object({ name: z.string() }).toJSONSchema()
  //                ^^^^^^^^ Type error: $schema, additionalProperties not assignable
});

Fix

The fix follows the same pattern already established in this codebase for inputSchema and outputSchema (lines 1391-1409 of types.ts), which use .catchall(z.unknown()) to accept additional JSON Schema properties beyond the required type, properties, and required fields.

The spec type in spec.types.ts already includes $schema?: string in its requestedSchema definition (line 2155), confirming that additional properties are expected.

Fixes #1362

Test plan

  • Existing elicitation tests continue to pass (no behavioral change -- .catchall(z.unknown()) only widens the accepted type)
  • Spec type compatibility test (spec.types.test.ts) continues to pass (.catchall(z.unknown()) adds an index signature which is structurally compatible)
  • Verify that z.object({ name: z.string() }).toJSONSchema() is now accepted by elicitInput without type errors

🤖 Generated with Claude Code

…uestedSchema

Add .catchall(z.unknown()) to the requestedSchema object type in
ElicitRequestFormParamsSchema, matching the existing pattern used by
inputSchema and outputSchema. This fixes a type incompatibility when
passing Zod v4's .toJSONSchema() output (which includes $schema,
additionalProperties, etc.) to elicitInput's requestedSchema parameter.

Fixes modelcontextprotocol#1362

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@corvid-agent corvid-agent requested a review from a team as a code owner February 20, 2026 17:02
@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: 5725802

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 Feb 20, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 5725802

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