Skip to content

Commit 2408bf3

Browse files
committed
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
1 parent df4b6cc commit 2408bf3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/core': patch
3+
---
4+
5+
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.

packages/core/src/types/schemas.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ export const BooleanSchemaSchema = z.object({
17221722
title: z.string().optional(),
17231723
description: z.string().optional(),
17241724
default: z.boolean().optional()
1725-
});
1725+
}).passthrough();
17261726

17271727
/**
17281728
* Primitive schema definition for string fields.
@@ -1735,7 +1735,7 @@ export const StringSchemaSchema = z.object({
17351735
maxLength: z.number().optional(),
17361736
format: z.enum(['email', 'uri', 'date', 'date-time']).optional(),
17371737
default: z.string().optional()
1738-
});
1738+
}).passthrough();
17391739

17401740
/**
17411741
* Primitive schema definition for number fields.
@@ -1747,7 +1747,7 @@ export const NumberSchemaSchema = z.object({
17471747
minimum: z.number().optional(),
17481748
maximum: z.number().optional(),
17491749
default: z.number().optional()
1750-
});
1750+
}).passthrough();
17511751

17521752
/**
17531753
* Schema for single-selection enumeration without display titles for options.
@@ -1758,7 +1758,7 @@ export const UntitledSingleSelectEnumSchemaSchema = z.object({
17581758
description: z.string().optional(),
17591759
enum: z.array(z.string()),
17601760
default: z.string().optional()
1761-
});
1761+
}).passthrough();
17621762

17631763
/**
17641764
* Schema for single-selection enumeration with display titles for each option.
@@ -1774,7 +1774,7 @@ export const TitledSingleSelectEnumSchemaSchema = z.object({
17741774
})
17751775
),
17761776
default: z.string().optional()
1777-
});
1777+
}).passthrough();
17781778

17791779
/**
17801780
* Use {@linkcode TitledSingleSelectEnumSchema} instead.
@@ -1787,7 +1787,7 @@ export const LegacyTitledEnumSchemaSchema = z.object({
17871787
enum: z.array(z.string()),
17881788
enumNames: z.array(z.string()).optional(),
17891789
default: z.string().optional()
1790-
});
1790+
}).passthrough();
17911791

17921792
// Combined single selection enumeration
17931793
export const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
@@ -1806,7 +1806,7 @@ export const UntitledMultiSelectEnumSchemaSchema = z.object({
18061806
enum: z.array(z.string())
18071807
}),
18081808
default: z.array(z.string()).optional()
1809-
});
1809+
}).passthrough();
18101810

18111811
/**
18121812
* Schema for multiple-selection enumeration with display titles for each option.
@@ -1826,7 +1826,7 @@ export const TitledMultiSelectEnumSchemaSchema = z.object({
18261826
)
18271827
}),
18281828
default: z.array(z.string()).optional()
1829-
});
1829+
}).passthrough();
18301830

18311831
/**
18321832
* Combined schema for multiple-selection enumeration

0 commit comments

Comments
 (0)