From e5b12740dbd6ba709f7ed13b0d81035cfcf1fe79 Mon Sep 17 00:00:00 2001 From: Travis Bonnet Date: Mon, 16 Mar 2026 02:41:40 -0500 Subject: [PATCH] fix: widen elicitInput requestedSchema type to accept Zod's toJSONSchema output Zod v4's `.toJSONSchema()` produces standard JSON Schema output that includes fields like `$schema` and `additionalProperties`. The `requestedSchema` type in `ElicitRequestFormParams` was too narrow to accept these extra fields, forcing users to cast through `unknown`. This adds `.passthrough()` to the Zod runtime schema and an index signature to the spec type, allowing any additional JSON Schema fields through while keeping the required fields (`type`, `properties`) strictly typed. Fixes #1362 Co-Authored-By: Claude Opus 4.6 (1M context) --- .changeset/widen-elicit-requested-schema.md | 5 +++++ packages/core/src/types/spec.types.ts | 1 + packages/core/src/types/types.ts | 12 +++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/widen-elicit-requested-schema.md diff --git a/.changeset/widen-elicit-requested-schema.md b/.changeset/widen-elicit-requested-schema.md new file mode 100644 index 000000000..c0447b082 --- /dev/null +++ b/.changeset/widen-elicit-requested-schema.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/core': patch +--- + +Widen `requestedSchema` type in `ElicitRequestFormParams` to accept additional JSON Schema fields (e.g., `$schema`, `additionalProperties`) that tools like Zod's `.toJSONSchema()` produce. This removes the need for users to cast through `unknown` when passing Zod-generated schemas to `elicitInput()`. diff --git a/packages/core/src/types/spec.types.ts b/packages/core/src/types/spec.types.ts index f36434bef..89bacc20d 100644 --- a/packages/core/src/types/spec.types.ts +++ b/packages/core/src/types/spec.types.ts @@ -2795,6 +2795,7 @@ export interface ElicitRequestFormParams extends TaskAugmentedRequestParams { * Only top-level properties are allowed, without nesting. */ requestedSchema: { + [key: string]: unknown; $schema?: string; type: 'object'; properties: { diff --git a/packages/core/src/types/types.ts b/packages/core/src/types/types.ts index 6ac79777b..76929ab95 100644 --- a/packages/core/src/types/types.ts +++ b/packages/core/src/types/types.ts @@ -2024,11 +2024,13 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex * A restricted subset of JSON Schema. * Only top-level properties are allowed, without nesting. */ - requestedSchema: z.object({ - type: z.literal('object'), - properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), - required: z.array(z.string()).optional() - }) + requestedSchema: z + .object({ + type: z.literal('object'), + properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), + required: z.array(z.string()).optional() + }) + .passthrough() }); /**