Skip to content

Commit 0c9b2bc

Browse files
Dave-Londonclaude
andcommitted
fix: widen requestedSchema type to accept additional JSON Schema fields
The `requestedSchema` object in `ElicitRequestFormParamsSchema` was too narrow, rejecting valid JSON Schema fields like `additionalProperties` that Zod v4's `.toJSONSchema()` and other JSON Schema generators produce. Add `.passthrough()` to the `requestedSchema` Zod object and include the `$schema` field (already present in the spec types) so that standard JSON Schema output is accepted without type errors. Fixes #1362 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65bbcea commit 0c9b2bc

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

packages/core/src/types/types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,11 +1993,14 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex
19931993
* A restricted subset of JSON Schema.
19941994
* Only top-level properties are allowed, without nesting.
19951995
*/
1996-
requestedSchema: z.object({
1997-
type: z.literal('object'),
1998-
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1999-
required: z.array(z.string()).optional()
2000-
})
1996+
requestedSchema: z
1997+
.object({
1998+
$schema: z.string().optional(),
1999+
type: z.literal('object'),
2000+
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
2001+
required: z.array(z.string()).optional()
2002+
})
2003+
.passthrough()
20012004
});
20022005

20032006
/**

packages/core/test/spec.types.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ type MakeUnknownsNotOptional<T> =
5353
}
5454
: T;
5555

56+
// Targeted fix: in spec, requestedSchema needs index signature to match SDK's .passthrough()
57+
// which allows additional JSON Schema fields like `additionalProperties` from Zod's .toJSONSchema()
58+
type FixSpecRequestedSchema<T> = T extends { requestedSchema: infer R }
59+
? Omit<T, 'requestedSchema'> & { requestedSchema: R & { [x: string]: unknown } }
60+
: T;
61+
5662
// Targeted fix: in spec, treat ClientCapabilities.elicitation?: object as Record<string, unknown>
5763
type FixSpecClientCapabilities<T> = T extends { elicitation?: object }
5864
? Omit<T, 'elicitation'> & { elicitation?: Record<string, unknown> }
@@ -160,11 +166,14 @@ const sdkTypeChecks = {
160166
sdk = spec;
161167
spec = sdk;
162168
},
163-
ElicitRequestParams: (sdk: SDKTypes.ElicitRequestParams, spec: SpecTypes.ElicitRequestParams) => {
169+
ElicitRequestParams: (
170+
sdk: SDKTypes.ElicitRequestParams,
171+
spec: FixSpecRequestedSchema<SpecTypes.ElicitRequestFormParams> | SpecTypes.ElicitRequestURLParams
172+
) => {
164173
sdk = spec;
165174
spec = sdk;
166175
},
167-
ElicitRequestFormParams: (sdk: SDKTypes.ElicitRequestFormParams, spec: SpecTypes.ElicitRequestFormParams) => {
176+
ElicitRequestFormParams: (sdk: SDKTypes.ElicitRequestFormParams, spec: FixSpecRequestedSchema<SpecTypes.ElicitRequestFormParams>) => {
168177
sdk = spec;
169178
spec = sdk;
170179
},

0 commit comments

Comments
 (0)