From 3fd356f4338574d7f0b797860bbf8ca14a0819b0 Mon Sep 17 00:00:00 2001 From: kai-agent-free Date: Sun, 29 Mar 2026 08:42:31 +0000 Subject: [PATCH] fix: allow $schema and additionalProperties in elicitation requestedSchema Zod's .toJSONSchema() adds $schema and additionalProperties fields which are not harmful but cause TypeScript errors when passed directly to elicitInput(). This adds both as optional fields to the schema definition and TypeScript interface. Fixes #1362 --- .changeset/zod-elicit-compat.md | 5 +++++ packages/core/src/types/schemas.ts | 4 +++- packages/core/src/types/spec.types.ts | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/zod-elicit-compat.md diff --git a/.changeset/zod-elicit-compat.md b/.changeset/zod-elicit-compat.md new file mode 100644 index 000000000..5274b825f --- /dev/null +++ b/.changeset/zod-elicit-compat.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/core": patch +--- + +Allow `$schema` and `additionalProperties` in elicitation `requestedSchema` for Zod `.toJSONSchema()` compatibility diff --git a/packages/core/src/types/schemas.ts b/packages/core/src/types/schemas.ts index 309b6ade2..dba423361 100644 --- a/packages/core/src/types/schemas.ts +++ b/packages/core/src/types/schemas.ts @@ -1862,9 +1862,11 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex * Only top-level properties are allowed, without nesting. */ requestedSchema: z.object({ + $schema: z.string().optional(), type: z.literal('object'), properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), - required: z.array(z.string()).optional() + required: z.array(z.string()).optional(), + additionalProperties: z.boolean().optional() }) }); diff --git a/packages/core/src/types/spec.types.ts b/packages/core/src/types/spec.types.ts index ba849c546..6e35eaaea 100644 --- a/packages/core/src/types/spec.types.ts +++ b/packages/core/src/types/spec.types.ts @@ -1740,6 +1740,7 @@ export interface Tool extends BaseMetadata, Icons { type: 'object'; properties?: { [key: string]: JSONValue }; required?: string[]; + additionalProperties?: boolean; }; /** @@ -1759,6 +1760,7 @@ export interface Tool extends BaseMetadata, Icons { type: 'object'; properties?: { [key: string]: JSONValue }; required?: string[]; + additionalProperties?: boolean; }; /** @@ -2801,6 +2803,7 @@ export interface ElicitRequestFormParams extends TaskAugmentedRequestParams { [key: string]: PrimitiveSchemaDefinition; }; required?: string[]; + additionalProperties?: boolean; }; }