Allow extra JSON Schema keys in elicit primitive schemas#1856
Open
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Allow extra JSON Schema keys in elicit primitive schemas#1856Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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