-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Elicit primitive schemas reject extra JSON Schema keys (pattern, format, etc.) #1844
Copy link
Copy link
Open
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedfix proposedBot has a verified fix diff in the commentBot has a verified fix diff in the commentready for workEnough information for someone to start working onEnough information for someone to start working on
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedfix proposedBot has a verified fix diff in the commentBot has a verified fix diff in the commentready for workEnough information for someone to start working onEnough information for someone to start working on
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.