Skip to content

Add Zod 4 schema support - #49

Open
fredericbarthelet wants to merge 5 commits into
agentcathq:mainfrom
fredericbarthelet:fix/zod-4-schema-support
Open

Add Zod 4 schema support#49
fredericbarthelet wants to merge 5 commits into
agentcathq:mainfrom
fredericbarthelet:fix/zod-4-schema-support

Conversation

@fredericbarthelet

@fredericbarthelet fredericbarthelet commented Aug 28, 2026

Copy link
Copy Markdown

Hey there 👋
Awesome lib! Starting to use it on alpic.ai :)
Recently put together a https://github.com/alpic-ai/webmcp skill and wanted to recommand webmcp-react for react code base.
However, I got stuck using inputSchema instead of input because my project was already depending on Zod 4 and you're using depreacted zod-to-json-schema.

Relying on either zod@3.25 or 4 and higher enable using the underlying zod API to convert natively to JSON Schema.

For Zod 4 / Mini schemas (_zod), conversion uses z4.toJSONSchema({ io: "input", target: "draft-7", reused: "inline" }) so the advertised MCP inputSchema stays aligned with the existing zodToJsonSchema({ $refStrategy: "none" }) path:

  • reused: "inline" is the native equivalent of $refStrategy: "none" — shared sub-schemas are expanded in place, so agents see full object shapes instead of $ref / $defs.
  • target: "draft-7" is the spelling accepted across the whole peer range (^3.25.0 || ^4.0.0). Zod 3.25's bundled core only knows "draft-7" | "draft-2020-12"; the "draft-07" alias was added later in Zod 4 and would warn + skip draft-07 rules on 3.25.
  • io: "input" matches how tool arguments are validated (the schema's input type, not its output after transforms/defaults).

Classic Zod 3 instances (no _zod) still go through zod-to-json-schema, because native toJSONSchema cannot walk them.

Let me know what you think of this proposal !

fredericbarthelet and others added 4 commits August 28, 2026 15:42
Use Zod's versioned entry points to preserve Zod 3 compatibility while converting and validating Zod 4 and Zod Mini schemas through the core API.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep handler args aligned with z.infer (parsed output), explicitly inline
reused Zod 4 JSON Schema nodes, and document the dual peer range.

Co-authored-by: Cursor <cursoragent@cursor.com>
Zod 3.25's bundled v4 core only knows "draft-7"; passing the "draft-07"
alias made it warn on every conversion and skip draft-07 output rules.

Co-authored-by: Cursor <cursoragent@cursor.com>
Zod 3.25 does ship toJSONSchema, but only for zod/v4 schemas; classic
Zod 3 instances have no _zod internals for it to walk.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fredericbarthelet
fredericbarthelet marked this pull request as ready for review August 28, 2026 15:29
Co-authored-by: Cursor <cursoragent@cursor.com>
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