Skip to content

fix(core): fall back to z.toJSONSchema for zod schemas without ~standard.jsonSchema#1895

Draft
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/v2-bc-zod-trap
Draft

fix(core): fall back to z.toJSONSchema for zod schemas without ~standard.jsonSchema#1895
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/v2-bc-zod-trap

Conversation

@felixweinberger
Copy link
Copy Markdown
Contributor

Part of the v2 backwards-compatibility series — see reviewer guide.

Servers on zod 3.x or 4.0-4.1 crash at runtime on tools/list because ~standard.jsonSchema doesn't exist. This adds a fallback to z.toJSONSchema() for zod-vendor schemas and bumps the catalog to zod: ^4.2.0.

Motivation and Context

Servers on zod 3.x or 4.0-4.1 crash at runtime on tools/list because ~standard.jsonSchema doesn't exist. This adds a fallback to z.toJSONSchema() for zod-vendor schemas and bumps the catalog to zod: ^4.2.0.

v1 vs v2 pattern & evidence

v1 pattern:

Any zod version worked with `server.tool('x', {a: z.string()}, cb)`

v2-native:

v2 requires StandardSchemaWithJSON (`~standard.jsonSchema` field)  only on zod ≥4.2.0 via `zod/v4` import path

Evidence: Passes typecheck but crashes at runtime — found via real-repo migration testing. Affects any server whose zod doesn't expose ~standard.jsonSchema.

How Has This Been Tested?

  • packages/core/test/util/standardSchema.zodFallback.test.ts — 2 cases
  • Integration: validated bump-only against 5 OSS repos via the v2-bc-integration validation branch
  • pnpm typecheck:all && pnpm lint:all && pnpm test:all green

Breaking Changes

None — additive @deprecated shim. Removed in v3.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

Stacks on: none

…ard.jsonSchema

Schemas from zod <4.2.0 implement StandardSchemaV1 but not StandardJSONSchemaV1,
so standardSchemaToJsonSchema crashed at `undefined[io]` on tools/list. Detect
`vendor: 'zod'` without `jsonSchema` and fall back to the bundled z.toJSONSchema()
with a one-time warning. Non-zod libraries without jsonSchema get a clear error
pointing at fromJsonSchema(). Bumps catalog zod to ^4.2.0.
@felixweinberger felixweinberger added the v2-bc v2 backwards-compatibility series label Apr 15, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: b80761d

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/fastify Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node Patch

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

@felixweinberger felixweinberger added this to the v2.0.0-bc milestone Apr 15, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1895

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1895

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1895

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1895

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1895

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1895

commit: b80761d

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

Labels

v2-bc v2 backwards-compatibility series

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant