From 6c078e7e3d8af3006739a39b2f8a49b30e3d5d98 Mon Sep 17 00:00:00 2001 From: kai-agent-free Date: Mon, 16 Mar 2026 17:39:43 +0000 Subject: [PATCH] fix: widen requestedSchema type to accept standard JSON Schema output Zod's .toJSONSchema() and other JSON Schema generators produce extra fields like $schema and additionalProperties that were rejected by the narrow requestedSchema type in elicitInput(). Changes: - Add additionalProperties as explicit optional field in both the TypeScript interface (spec.types.ts) and Zod schema (types.ts) - Add index signature [key: string]: unknown to the interface to allow any additional JSON Schema fields - Add .passthrough() to Zod schema so extra fields survive validation Fixes modelcontextprotocol/typescript-sdk#1362 --- .changeset/fix-elicit-json-schema-compat.md | 9 +++++++++ packages/core/src/types/spec.types.ts | 6 ++++++ packages/core/src/types/types.ts | 13 ++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .changeset/fix-elicit-json-schema-compat.md diff --git a/.changeset/fix-elicit-json-schema-compat.md b/.changeset/fix-elicit-json-schema-compat.md new file mode 100644 index 000000000..649b42655 --- /dev/null +++ b/.changeset/fix-elicit-json-schema-compat.md @@ -0,0 +1,9 @@ +--- +"@modelcontextprotocol/sdk": patch +--- + +Widen `requestedSchema` type in `elicitInput()` to accept standard JSON Schema output from generators like Zod's `.toJSONSchema()`. + +Added `additionalProperties` as an explicit optional field and an index signature `[key: string]: unknown` to allow extra JSON Schema fields (e.g., `$schema`, `additionalProperties`) that schema generators commonly produce. Also added `.passthrough()` to the Zod validation schema so these extra fields are preserved at runtime. + +Fixes modelcontextprotocol/typescript-sdk#1362 diff --git a/packages/core/src/types/spec.types.ts b/packages/core/src/types/spec.types.ts index f36434bef..8251f1a57 100644 --- a/packages/core/src/types/spec.types.ts +++ b/packages/core/src/types/spec.types.ts @@ -1740,6 +1740,8 @@ export interface Tool extends BaseMetadata, Icons { type: 'object'; properties?: { [key: string]: JSONValue }; required?: string[]; + additionalProperties?: boolean | { [key: string]: unknown }; + [key: string]: unknown; }; /** @@ -1759,6 +1761,8 @@ export interface Tool extends BaseMetadata, Icons { type: 'object'; properties?: { [key: string]: JSONValue }; required?: string[]; + additionalProperties?: boolean | { [key: string]: unknown }; + [key: string]: unknown; }; /** @@ -2801,6 +2805,8 @@ export interface ElicitRequestFormParams extends TaskAugmentedRequestParams { [key: string]: PrimitiveSchemaDefinition; }; required?: string[]; + additionalProperties?: boolean | { [key: string]: unknown }; + [key: string]: unknown; }; } diff --git a/packages/core/src/types/types.ts b/packages/core/src/types/types.ts index 6ac79777b..468229af7 100644 --- a/packages/core/src/types/types.ts +++ b/packages/core/src/types/types.ts @@ -2024,11 +2024,14 @@ 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(), + additionalProperties: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional() + }) + .passthrough() }); /**