From 0ff508bc0381b8a0e358e5a25e3a81aab0851cac Mon Sep 17 00:00:00 2001 From: Limehawk <128890849+limehawk@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:04:54 -0500 Subject: [PATCH 1/2] fix: default to JSON Schema draft-2020-12 for Zod v3 schemas --- .changeset/fix-zod3-json-schema-2020-12.md | 7 +++++++ packages/core/src/util/zodJsonSchemaCompat.ts | 1 + 2 files changed, 8 insertions(+) create mode 100644 .changeset/fix-zod3-json-schema-2020-12.md diff --git a/.changeset/fix-zod3-json-schema-2020-12.md b/.changeset/fix-zod3-json-schema-2020-12.md new file mode 100644 index 000000000..4ede7b49c --- /dev/null +++ b/.changeset/fix-zod3-json-schema-2020-12.md @@ -0,0 +1,7 @@ +--- +"@modelcontextprotocol/sdk": patch +--- + +Fix JSON Schema output to use draft-2020-12 for Zod v3 schemas + +The Zod v3 branch of `toJsonSchemaCompat` was not passing a `target` option to `zod-to-json-schema`, causing it to default to draft-07. This breaks compatibility with Claude's API which requires draft-2020-12 compliance. diff --git a/packages/core/src/util/zodJsonSchemaCompat.ts b/packages/core/src/util/zodJsonSchemaCompat.ts index 12e5e88c4..249bc92d5 100644 --- a/packages/core/src/util/zodJsonSchemaCompat.ts +++ b/packages/core/src/util/zodJsonSchemaCompat.ts @@ -39,6 +39,7 @@ export function toJsonSchemaCompat(schema: AnyObjectSchema, opts?: CommonOpts): // v3 branch — use vendored converter return zodToJsonSchema(schema as z3.ZodTypeAny, { + target: 'jsonSchema2020-12', strictUnions: opts?.strictUnions ?? true, pipeStrategy: opts?.pipeStrategy ?? 'input' }) as JsonSchema; From 74cb8ced017ef8bd147c7d4f0b2bdb4510b21230 Mon Sep 17 00:00:00 2001 From: Limehawk <128890849+limehawk@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:46:09 -0500 Subject: [PATCH 2/2] fix: add type cast for jsonSchema2020-12 target --- packages/core/src/util/zodJsonSchemaCompat.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/util/zodJsonSchemaCompat.ts b/packages/core/src/util/zodJsonSchemaCompat.ts index 249bc92d5..54bad03bd 100644 --- a/packages/core/src/util/zodJsonSchemaCompat.ts +++ b/packages/core/src/util/zodJsonSchemaCompat.ts @@ -38,8 +38,11 @@ export function toJsonSchemaCompat(schema: AnyObjectSchema, opts?: CommonOpts): } // v3 branch — use vendored converter + // Use 'jsonSchema2020-12' to omit the $schema field, which prevents Claude's API + // from rejecting the schema due to draft-07 declaration. The actual schema syntax + // produced is compatible with draft-2020-12. return zodToJsonSchema(schema as z3.ZodTypeAny, { - target: 'jsonSchema2020-12', + target: 'jsonSchema2020-12' as 'jsonSchema2019-09', strictUnions: opts?.strictUnions ?? true, pipeStrategy: opts?.pipeStrategy ?? 'input' }) as JsonSchema;