From 2408bf33ff55ee7cdf3c50a1909f2e39cb3408d5 Mon Sep 17 00:00:00 2001 From: kmaclip Date: Fri, 3 Apr 2026 13:17:34 -0400 Subject: [PATCH] fix(core): allow extra JSON Schema keys in elicit primitive schemas Add .passthrough() to all primitive schema definitions used in ElicitRequestFormParamsSchema. Schemas generated by z.toJSONSchema() with constraints like .regex(), .min(), .max() produce extra keys (pattern, exclusiveMinimum, format, const, etc.) that were rejected by the strict z.object() definitions. .passthrough() preserves type safety for known fields while allowing unknown JSON Schema keywords to flow through, matching how inputSchema/outputSchema already handle this. Closes #1844 --- .changeset/elicit-schema-passthrough.md | 5 +++++ packages/core/src/types/schemas.ts | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changeset/elicit-schema-passthrough.md diff --git a/.changeset/elicit-schema-passthrough.md b/.changeset/elicit-schema-passthrough.md new file mode 100644 index 000000000..c4e891225 --- /dev/null +++ b/.changeset/elicit-schema-passthrough.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/core': patch +--- + +Allow extra JSON Schema keys (pattern, exclusiveMinimum, format, const, etc.) in elicit primitive schemas. Schemas generated by z.toJSONSchema() with constraints like .regex() or .min() are now accepted instead of rejected. diff --git a/packages/core/src/types/schemas.ts b/packages/core/src/types/schemas.ts index 86acf11d7..5e02e76d1 100644 --- a/packages/core/src/types/schemas.ts +++ b/packages/core/src/types/schemas.ts @@ -1722,7 +1722,7 @@ export const BooleanSchemaSchema = z.object({ title: z.string().optional(), description: z.string().optional(), default: z.boolean().optional() -}); +}).passthrough(); /** * Primitive schema definition for string fields. @@ -1735,7 +1735,7 @@ export const StringSchemaSchema = z.object({ maxLength: z.number().optional(), format: z.enum(['email', 'uri', 'date', 'date-time']).optional(), default: z.string().optional() -}); +}).passthrough(); /** * Primitive schema definition for number fields. @@ -1747,7 +1747,7 @@ export const NumberSchemaSchema = z.object({ minimum: z.number().optional(), maximum: z.number().optional(), default: z.number().optional() -}); +}).passthrough(); /** * Schema for single-selection enumeration without display titles for options. @@ -1758,7 +1758,7 @@ export const UntitledSingleSelectEnumSchemaSchema = z.object({ description: z.string().optional(), enum: z.array(z.string()), default: z.string().optional() -}); +}).passthrough(); /** * Schema for single-selection enumeration with display titles for each option. @@ -1774,7 +1774,7 @@ export const TitledSingleSelectEnumSchemaSchema = z.object({ }) ), default: z.string().optional() -}); +}).passthrough(); /** * Use {@linkcode TitledSingleSelectEnumSchema} instead. @@ -1787,7 +1787,7 @@ export const LegacyTitledEnumSchemaSchema = z.object({ enum: z.array(z.string()), enumNames: z.array(z.string()).optional(), default: z.string().optional() -}); +}).passthrough(); // Combined single selection enumeration export const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]); @@ -1806,7 +1806,7 @@ export const UntitledMultiSelectEnumSchemaSchema = z.object({ enum: z.array(z.string()) }), default: z.array(z.string()).optional() -}); +}).passthrough(); /** * Schema for multiple-selection enumeration with display titles for each option. @@ -1826,7 +1826,7 @@ export const TitledMultiSelectEnumSchemaSchema = z.object({ ) }), default: z.array(z.string()).optional() -}); +}).passthrough(); /** * Combined schema for multiple-selection enumeration