Skip to content

z.preprocess() causes "Mixed Zod versions detected" error #1190

@EDjur

Description

@EDjur

When using Zod v4's z.preprocess() with McpServer.registerTool(), the SDK throws:

Error: Mixed Zod versions detected in object shape.

This happens even when only a single Zod version is installed.

To Reproduce

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";

const server = new McpServer({
  name: "test-server",
  version: "1.0.0",
});

// This works fine - regular z.object schema
const WorkingSchema = z.object({
  name: z.string(),
});

// This fails - z.preprocess schema
const BrokenSchema = z.preprocess(
  (input) => input,
  z.object({
    name: z.string(),
  })
);

console.log("Registering tool with z.object schema...");
server.registerTool(
  "working-tool",
  {
    description: "A tool with a regular z.object schema",
    inputSchema: WorkingSchema,
  },
  async (args) => ({ content: [{ type: "text", text: "OK" }] })
);
console.log("Success: z.object schema works\n");

// Register a tool with the broken schema - this throws
console.log("Registering tool with z.preprocess schema...");
try {
  server.registerTool(
    "broken-tool",
    {
      description: "A tool with a z.preprocess schema",
      inputSchema: BrokenSchema,
    },
    async (args) => ({ content: [{ type: "text", text: "OK" }] })
  );
  console.log("Success: z.preprocess schema works");
} catch (error) {
  console.log("Error:", error.message);
}

Output from the above example:

Registering tool with z.object schema...
Success: z.object schema works

Registering tool with z.preprocess schema...
Error: Mixed Zod versions detected in object shape.

Expected behavior
Tools with z.preprocess() schemas should register successfully, just like tools with z.object() schemas.

Logs
If applicable, add logs to help explain your problem.

Additional context

- @modelcontextprotocol/sdk: 1.23.0
- zod: 4.1.x
- Node.js: 24.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Broken core functionality, security issues, critical missing featurebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions