-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: zod v4 #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: zod v4 #869
Conversation
src/server/mcp.ts
Outdated
enum?: string[]; | ||
}; | ||
|
||
function zodToJsonSchema(schema: ZodObject<ZodRawShape>): JsonSchema { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to think about this PR more broadly, e.g. what the impacts of this potentially breaking change will be.
But I think for this we could use https://zod.dev/json-schema instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to give it a shot today!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domdomegg
So I definitely just had a misunderstanding of how the new toJSONSchema
method from Zod 4 worked -- just updated and stripped out the custom code in favor of that. Tests passed without issue. Check it out!
Thanks for working on this. We are preparing for Typescript V2, this potentially can be included there |
Let me know if I can help! @ihrpr |
@@ -25,8 +25,8 @@ const getServer = () => { | |||
'start-notification-stream', | |||
'Starts sending periodic notifications', | |||
{ | |||
interval: z.number().describe('Interval in milliseconds between notifications').default(1000), | |||
count: z.number().describe('Number of notifications to send').default(10), | |||
interval: z.number().describe('Interval in milliseconds between notifications').prefault(1000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is prefault
preferred in this case?
as far as I understand from https://zod.dev/v4/changelog#default-updates it's about expected input type (in their example it's a string) and output type (in their example the string goes through transform to output a number)
looks like here default will work as well since input type is same as output type - number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we can use default! let me get it updated. the util I used defaults to prefault
to preserve default functionality so I left it as is.
@avivnakar / all Updated with main, resolved conflicts, reverted to use |
Upgrade to Zod v4 for compatibility with v3 and v4.
Note, it wasn't clear which formatter to use so some commas changed and some lines I did not intend to.
Motivation and Context
This has been a blocking issue for my team and many others. When versions mismatch across dependencies with older Zod versions, memory leaks become present and can slow or stall development.
This also will help unblock downstream dependencies, such as with vercel's AI SDK and mcp-tools.
#494
vercel/ai#7160
vercel/mcp-adapter#93
How Has This Been Tested?
Breaking Changes
Users will need to use Zod 3.25.76+ or Zod 4 and import from either /v3 or /v4.
Types of changes
Checklist
Additional context