From 9f455cdd20cd9817c4b931e4a4d279d730baf575 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Thu, 26 Mar 2026 16:25:32 +0000 Subject: [PATCH] fix(core): allow additional JSON Schema properties in elicitInput requestedSchema Adds .catchall(z.unknown()) to requestedSchema, matching the pattern used by inputSchema/outputSchema (SEP-1613). Fixes type incompatibility when using Zod v4's .toJSONSchema() output which includes extra properties like $schema and additionalProperties. Fixes #1362 --- .changeset/zod-json-schema-compat.md | 5 +++++ packages/core/src/types/schemas.ts | 12 +++++++----- packages/core/test/types.test.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 .changeset/zod-json-schema-compat.md diff --git a/.changeset/zod-json-schema-compat.md b/.changeset/zod-json-schema-compat.md new file mode 100644 index 000000000..5ca1470e8 --- /dev/null +++ b/.changeset/zod-json-schema-compat.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/core': patch +--- + +Allow additional JSON Schema properties in elicitInput's requestedSchema type by adding .catchall(z.unknown()), matching the pattern used by inputSchema. This fixes type incompatibility when using Zod v4's .toJSONSchema() output which includes extra properties like $schema and additionalProperties. diff --git a/packages/core/src/types/schemas.ts b/packages/core/src/types/schemas.ts index 1c0e6086d..85854e69a 100644 --- a/packages/core/src/types/schemas.ts +++ b/packages/core/src/types/schemas.ts @@ -1855,11 +1855,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() + }) + .catchall(z.unknown()) }); /** diff --git a/packages/core/test/types.test.ts b/packages/core/test/types.test.ts index 429b3ecdd..9383f7d5e 100644 --- a/packages/core/test/types.test.ts +++ b/packages/core/test/types.test.ts @@ -6,6 +6,7 @@ import { CreateMessageRequestSchema, CreateMessageResultSchema, CreateMessageResultWithToolsSchema, + ElicitRequestFormParamsSchema, LATEST_PROTOCOL_VERSION, PromptMessageSchema, ResourceLinkSchema, @@ -983,4 +984,31 @@ describe('Types', () => { } }); }); + + describe('ElicitRequestFormParamsSchema', () => { + test('accepts requestedSchema with extra JSON Schema metadata keys', () => { + // Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc. + // See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362 + const params = { + message: 'Please provide your name', + requestedSchema: { + $schema: 'https://json-schema.org/draft/2020-12/schema', + type: 'object', + properties: { + name: { type: 'string' } + }, + required: ['name'], + additionalProperties: false + } + }; + + const result = ElicitRequestFormParamsSchema.safeParse(params); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.requestedSchema.type).toBe('object'); + expect(result.data.requestedSchema.$schema).toBe('https://json-schema.org/draft/2020-12/schema'); + expect(result.data.requestedSchema.additionalProperties).toBe(false); + } + }); + }); });