Allow extra JSON Schema keys in elicit primitive schemas#1856
Allow extra JSON Schema keys in elicit primitive schemas#1856Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add .passthrough() to all primitive schema Zod definitions (BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, and all enum schema variants) so that standard JSON Schema keywords like pattern, format, exclusiveMinimum, const, default, etc. are not rejected during validation. Also add index signatures to the corresponding TypeScript interfaces in spec.types.ts, and remove now-unnecessary @ts-expect-error comments in elicitation tests. Fixes modelcontextprotocol#1844
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
Hi @Christian-Sidak thanks for working on this - I realize I jumped the gun on calling #1849 "ready for work" as the recommended approaches all imply spec changes. Needs a bit of a deeper think of what the right solution here is, probably requires a protocol level change (this PR highlights it already given we're changing protocol types). I'm going to punt this issue and close this PR as a result, apologies for the churn. |
Summary
Fixes #1844
The property-level primitive schemas (
StringSchemaSchema,NumberSchemaSchema,BooleanSchemaSchema, and all enum schema variants) in the elicitation form params were strict Zod objects that rejected any keys not explicitly defined. This meant standard JSON Schema keywords likepattern,format(beyond the 4 allowed values),exclusiveMinimum,exclusiveMaximum,const, etc. were silently stripped or caused validation failures.This PR adds
.passthrough()to each primitive schema variant so that extra JSON Schema keys are preserved through validation, matching the behavior already applied to the top-levelrequestedSchemavia.catchall(z.unknown())in #1768.Changes
.passthrough()toBooleanSchemaSchema,StringSchemaSchema,NumberSchemaSchema.passthrough()to all enum schema variants:UntitledSingleSelectEnumSchemaSchema,TitledSingleSelectEnumSchemaSchema,LegacyTitledEnumSchemaSchema,UntitledMultiSelectEnumSchemaSchema,TitledMultiSelectEnumSchemaSchema.passthrough()to the nesteditemsobjects in multi-select enum schemas[key: string]: unknownindex signatures to all corresponding TypeScript interfaces inspec.types.ts@ts-expect-errorcomments in elicitation testsTest plan