Add Zod 4 schema support - #49
Open
fredericbarthelet wants to merge 5 commits into
Open
Conversation
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
marked this pull request as ready for review
August 28, 2026 15:29
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
inputSchemainstead ofinputbecause 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 usesz4.toJSONSchema({ io: "input", target: "draft-7", reused: "inline" })so the advertised MCPinputSchemastays aligned with the existingzodToJsonSchema({ $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 throughzod-to-json-schema, because nativetoJSONSchemacannot walk them.Let me know what you think of this proposal !