Skip to content

fix(server): accept structurally compatible Zod v4 schemas#1990

Open
Genmin wants to merge 3 commits intomodelcontextprotocol:v1.xfrom
Genmin:fix/zod-44-registertool-types
Open

fix(server): accept structurally compatible Zod v4 schemas#1990
Genmin wants to merge 3 commits intomodelcontextprotocol:v1.xfrom
Genmin:fix/zod-44-registertool-types

Conversation

@Genmin
Copy link
Copy Markdown

@Genmin Genmin commented Apr 30, 2026

Summary

Fixes #1987 on the v1.x branch by avoiding a type-identity leak from the SDK's own zod/v4/core import in the public Zod compatibility types.

AnySchema now accepts Zod v4 schemas structurally via the _zod.input / _zod.output contract. This preserves inference for registerTool raw shapes while allowing projects whose package manager resolves a different compatible Zod v4 copy than the SDK's copy.

Validation

  • Reproduced the issue in an external consumer with top-level zod@4.4.1 and a nested SDK-resolved zod@4.3.6: registerTool failed with ZodString not assignable to AnySchema.
  • Packed this branch and re-ran the same duplicate-Zod consumer repro: npx tsc --noEmit passed and callback args inferred correctly.
  • npm run typecheck
  • npm run build
  • npm test -- test/issues/test_1987_zod_v4_type_identity.test.ts test/server/mcp.test.ts test/server/completable.test.ts
  • npm run lint

@Genmin Genmin requested a review from a team as a code owner April 30, 2026 05:39
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: bfc7eb8

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@1990

commit: bfc7eb8

@Genmin
Copy link
Copy Markdown
Author

Genmin commented Apr 30, 2026

Added the missing patch changeset for the v1.x SDK package so the release-metadata blocker should clear on the next checks run. The code checks were already green before this metadata-only update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant