KBCodeKB
Unverified

Fix MCP SDK Zod v4 Incompatibility: "_parse is not a function" and "_def" Errors (-32603) in Claude Desktop, Cursor, VS Code, and Cline

The MCP TypeScript SDK (v1.17.5 and earlier) is incompatible with Zod v4.x due to breaking changes in Zod's internal API. When a project has Zod v4 installed, MCP servers fail with JSON-RPC error code -32603: 'w._parse is not a function' or 'null is not an object (evaluating F._def)'. The MCP SDK has a hard dependency on Zod ^3.23.8 and directly calls internal Zod v3 methods (_parse, _def) that were removed or changed in Zod v4. Package manager hoisting can cause silent runtime mismatches: even when `npm list zod` shows v3, a hoisted Zod v4 from another dependency may win at runtime in monorepos. The error manifests in ALL MCP client applications: Claude Desktop, Cursor, VS Code, Cline, and any tool using the MCP TypeScript SDK. MCP maintainer felixweinberger shipped a backward-compatible fix in v1.23.0-beta.0 (November 2025) that supports both Zod v3 and v4 via dependency change to `^3.25 || ^4.0`, stable in v1.23.1+. Verified: `npm view @modelcontextprotocol/sdk@1.17.5 dependencies.zod` returns `^3.23.8`, `npm view @modelcontextprotocol/sdk@1.23.1 dependencies.zod` returns `^3.25 || ^4.0`. Latest SDK as of June 2026 is v1.29.0.

Symptoms

  • JSON-RPC error -32603: "w._parse is not a function. (In 'w._parse(new y6(W,F,W.path,U))', 'w._parse' is undefined)"
  • JSON-RPC error -32603: "null is not an object (evaluating 'F._def')"
  • MCP server tools fail to execute or list when Zod v4 is installed as a project dependency
  • keyValidator._parse is not a function when calling MCP tools
  • MCP server starts but tool calls return internal error -32603
  • Error only occurs when Zod v4.x is installed; Zod v3.x works correctly

Error signatures

w._parse is not a function
_parse is not a function
null is not an object (evaluating 'F._def')
keyValidator._parse is not a function
keyValidator.parse is not a function
-32603

Possible causes

  • The MCP TypeScript SDK v1.17.5 has a hard dependency on Zod ^3.23.8 in its package.json and directly calls internal Zod methods (_parse, _def, _zod) that are NOT part of Zod's public API. Zod v4 removed or restructured these internal methods per the Zod v4 Library Authors Guide (https://zod.dev/library-authors).
  • Package manager hoisting causes silent version mismatches: npm, yarn, pnpm, and bun may hoist a root-level Zod v4 above the MCP SDK's Zod v3. Even when `npm list zod` shows v3, the runtime may load the hoisted v4. This is common in monorepos where another package depends on Zod v4 and the package manager deduplicates to v4 at the root, overriding the MCP SDK's v3 constraint.
  • The npm caret range `^3.23.8` explicitly excludes Zod v4.x (semver major version change). However, `npm install zod@4` followed by `npm install @modelcontextprotocol/sdk` may leave Zod v4 in node_modules if the package manager doesn't force-deduplicate to v3.
  • The error `w._parse is not a function` comes from the minified SDK bundle where the Zod schema's internal `_parse` method is called during tool input validation. In Zod v4, this method no longer exists on schema objects — validation must use the top-level `parse()` or `safeParse()` functions.
  • The MCP SDK uses `_def` (Zod's internal schema definition property) for schema introspection. In Zod v4, the `_def` structure changed significantly, causing the `null is not an object (evaluating 'F._def')` error.

Solutions

Use Zod v4 Compatibility Import (zod/v3 Entry Point)

risk: lowofficialpublished

Zod v4 provides a backward-compatibility entry point at `zod/v3` that re-exports the v3 API surface. If your project MUST use Zod v4 but you want MCP SDK compatibility without upgrading the SDK, redirect Zod imports through `zod/v3`. This works for many (but not all) v3 consumers.

  1. Install Zod v4: `npm install zod@^4.0.0`.
  2. In your MCP server entry file, import from `zod/v3` instead of `zod`: `import { z } from 'zod/v3'`.
  3. Note: This only helps if YOUR code imports Zod. The MCP SDK internally imports `zod` directly and will still load v4 if it's the resolved version.
  4. Combine with npm overrides (Solution 2) for full coverage if `zod/v3` doesn't resolve the SDK's internal imports.

Commands

npm install zod@^4.0.0
node -e "const {z} = require('zod/v3'); console.log('zod/v3 loaded:', typeof z.string)"

Config examples

// Replace:
import { z } from 'zod';

// With:
import { z } from 'zod/v3';

Risks

  • The `zod/v3` compat layer does NOT fix the MCP SDK's own internal Zod imports — the SDK will still load whatever Zod version is resolved.
  • Some Zod v4 features (`z.toJSONSchema()`) are not available through the `zod/v3` compat path.
  • This is a partial fix. For full resolution, upgrade the MCP SDK (Solution 1) or use npm overrides (Solution 2).

Verification

  • Step 1: Run `node -e "const {z}=require('zod/v3'); console.log(typeof z.string)" 2>&1; echo exit=$?` → expect stdout: 'function', exit code 0. Confirms zod/v3 compat path works.
  • Step 2: Start MCP server with zod/v3 imports → call a tool → expect no -32603 error IF the SDK also resolves Zod v3 (check with overrides if it doesn't).
0 verified0 failed

Pin Zod to v3 with npm Overrides (Temporary Workaround)

risk: lowgithubpublished

If you cannot immediately upgrade the MCP SDK, force Zod v3 across all dependencies using npm overrides or yarn resolutions. This prevents Zod v4 from being hoisted above the MCP SDK's Zod v3, eliminating the `_parse is not a function` error. Useful for monorepos where another package requires Zod v4 — the override ensures the MCP SDK always receives v3.

  1. Add to package.json: `"overrides": { "zod": "^3.23.8" }` (npm) or `"resolutions": { "zod": "^3.23.8" }` (yarn).
  2. Delete node_modules and lockfile: `rm -rf node_modules package-lock.json` (or yarn.lock / pnpm-lock.yaml).
  3. Reinstall: `npm install`.
  4. Verify: `npm ls zod` should show Zod v3.x everywhere — no v4 anywhere.
  5. Restart MCP server and test tool calls.

Commands

npm install zod@^3.23.8
rm -rf node_modules package-lock.json && npm install
npm ls zod
node -e "const z = require('zod'); console.log('Zod version:', z.version || 'v3.x')"

Config examples

{
  "name": "my-mcp-server",
  "dependencies": {
    "@modelcontextprotocol/sdk": "^1.17.5",
    "zod": "^4.1.5"
  },
  "overrides": {
    "zod": "^3.23.8"
  }
}

Risks

  • Other dependencies that genuinely require Zod v4 (e.g., using `z.toJSONSchema()`) will break.
  • This is temporary — the MCP SDK should be upgraded eventually to support both Zod versions natively.

Verification

  • Step 1: Run `npm ls zod 2>&1` → expect all entries show Zod ^3.x. If any entry shows Zod v4, the override didn't apply correctly.
  • Step 2: Run `node -e "const z=require('zod'); console.log(typeof z._parse)" 2>&1; echo exit=$?` → expect stdout: 'function', exit code 0. Confirms `_parse` exists (Zod v3). If output is 'undefined', Zod v4 is loaded — override failed.
  • Step 3: Call any MCP tool → expect no -32603 error.
0 verified0 failed

Upgrade MCP SDK to v1.23.1+ (Official Fix — Backward Compatible Zod v4 Support)

risk: lowofficialpublished

MCP SDK maintainer felixweinberger shipped backwards-compatible Zod v4 support in v1.23.0-beta.0 (Nov 2025), with stable release v1.23.1+. The dependency changed from `^3.23.8` to `^3.25 || ^4.0`, supporting both Zod v3 and v4 simultaneously. Upgrade your MCP server's SDK dependency to v1.23.1 or later. The latest stable as of June 2026 is v1.29.0.

  1. Upgrade: `npm install @modelcontextprotocol/sdk@latest` (or `@1.29.0` for a specific version).
  2. Verify the dependency range: `npm view @modelcontextprotocol/sdk@1.29.0 dependencies.zod` should return `^3.25 || ^4.0`.
  3. Delete node_modules and lockfile to ensure clean resolution: `rm -rf node_modules package-lock.json && npm install`.
  4. Verify the resolved Zod version: `npm ls zod` should show a single Zod version (v3 or v4, both are fine).
  5. Restart your MCP server and test tool calls with both Zod v3 and v4 clients.

Commands

npm install @modelcontextprotocol/sdk@latest
npm view @modelcontextprotocol/sdk@1.17.5 dependencies.zod
npm view @modelcontextprotocol/sdk@1.23.1 dependencies.zod
rm -rf node_modules package-lock.json && npm install
npm ls zod

Risks

  • Upgrading from v1.17.x to v1.29.0 may introduce other breaking changes in the MCP SDK API. Review the changelog at https://github.com/modelcontextprotocol/typescript-sdk/releases.
  • TypeScript type signatures may have changed between major SDK versions.

Verification

  • Step 1: Run `npm view @modelcontextprotocol/sdk@1.17.5 dependencies.zod 2>&1; echo exit=$?` → expect stdout: '^3.23.8', exit code 0. Confirms old version only supports Zod v3.
  • Step 2: Run `npm view @modelcontextprotocol/sdk@1.23.1 dependencies.zod 2>&1; echo exit=$?` → expect stdout: '^3.25 || ^4.0', exit code 0. Confirms fix version supports both Zod v3 and v4.
  • Step 3: After upgrading, run `npm ls zod 2>&1` → expect no version conflicts or unmet peer dependency warnings.
  • Step 4: Start your MCP server, call any tool → expect successful response without '-32603' or '_parse is not a function' errors.
0 verified0 failed

Agent JSON

Canonical machine-readable representation of this issue:

{
  "issue_id": "001da997-496c-4ea8-87a5-bc1ab9ce9641",
  "slug": "fix-mcp-sdk-zod-v4-incompatibility-parse-is-not-a-function-and-def-errors-32603-in-claude-desktop-cursor-vs-code-and-cli-yvhwvp",
  "verification_status": "unverified",
  "canonical_json": "https://codekb.dev/v1/issues/fix-mcp-sdk-zod-v4-incompatibility-parse-is-not-a-function-and-def-errors-32603-in-claude-desktop-cursor-vs-code-and-cli-yvhwvp"
}
← Back to all issuesPowered by CodeKB