Follow-up to #1768 (see #1768 (comment)).
#1768 added .catchall(z.unknown()) to the top-level requestedSchema in ElicitRequestFormParamsSchema, so keys like $schema / additionalProperties emitted by z.toJSONSchema() are now accepted. However, the property-level primitive schemas — StringSchemaSchema, NumberSchemaSchema, BooleanSchemaSchema, EnumSchemaSchema (packages/core/src/types/schemas.ts ~L1720-1829) — are still strict objects.
That means a server doing:
const schema = z.object({ name: z.string().regex(/^[a-z]+$/) });
client.elicitInput({ requestedSchema: z.toJSONSchema(schema), ... });
produces properties.name = { type: "string", pattern: "^[a-z]+$" }, and pattern is rejected by StringSchemaSchema. Same for format, exclusiveMinimum/exclusiveMaximum, default, const, etc.
Complication
Simply adding .catchall(z.unknown()) to each variant in PrimitiveSchemaDefinitionSchema risks ambiguous union discrimination, since the variants are distinguished by type. Options:
- Per-variant
.passthrough() while keeping type as the discriminator
- Explicitly add only the spec-listed JSON Schema keys to each variant
- Switch the union to
z.discriminatedUnion("type", ...) so extra keys don't affect matching
Scope
requestedSchema property-level primitives only. inputSchema / outputSchema already use .catchall() at the top level and don't constrain property shapes, so they're unaffected.
Follow-up to #1768 (see #1768 (comment)).
#1768 added
.catchall(z.unknown())to the top-levelrequestedSchemainElicitRequestFormParamsSchema, so keys like$schema/additionalPropertiesemitted byz.toJSONSchema()are now accepted. However, the property-level primitive schemas —StringSchemaSchema,NumberSchemaSchema,BooleanSchemaSchema,EnumSchemaSchema(packages/core/src/types/schemas.ts~L1720-1829) — are still strict objects.That means a server doing:
produces
properties.name = { type: "string", pattern: "^[a-z]+$" }, andpatternis rejected byStringSchemaSchema. Same forformat,exclusiveMinimum/exclusiveMaximum,default,const, etc.Complication
Simply adding
.catchall(z.unknown())to each variant inPrimitiveSchemaDefinitionSchemarisks ambiguous union discrimination, since the variants are distinguished bytype. Options:.passthrough()while keepingtypeas the discriminatorz.discriminatedUnion("type", ...)so extra keys don't affect matchingScope
requestedSchemaproperty-level primitives only.inputSchema/outputSchemaalready use.catchall()at the top level and don't constrain property shapes, so they're unaffected.