Switch from Zod to Standard Schema#27
Conversation
ca8da64 to
032679e
Compare
| "yargs": "^17.7.2", | ||
| "zod": "^3.24.2", | ||
| "zod-to-json-schema": "^3.24.3" | ||
| "zod-to-json-schema": "^3.24.5" |
There was a problem hiding this comment.
This library is a peer dependency of xsschema and isn't strictly required anymore but I left it because removing it would be a breaking change for Zod users.
There was a problem hiding this comment.
I would remove it. The whole idea behind all of this is not to add a new dependency all-together.
And it won't break in runtime but at the install moment. Seems safe enough.
|
@jacksteamdev Awesome contribution. Thank you ❤️ |
|
@punkpeye Happy to help. Thanks for all your work in the MCP scene! |
| "yargs": "^17.7.2", | ||
| "zod": "^3.24.2", | ||
| "zod-to-json-schema": "^3.24.3" | ||
| "zod-to-json-schema": "^3.24.5" |
There was a problem hiding this comment.
I would remove it. The whole idea behind all of this is not to add a new dependency all-together.
And it won't break in runtime but at the install moment. Seems safe enough.
| "@types/node": "^22.13.5", | ||
| "@types/uri-templates": "^0.1.34", | ||
| "@types/yargs": "^17.0.33", | ||
| "@valibot/to-json-schema": "^1.0.0", |
There was a problem hiding this comment.
adding all of these dependencies seems wrong.
They should be optional peer dependencies.
There was a problem hiding this comment.
These are dev dependencies for src/examples/addition.ts
There was a problem hiding this comment.
I agree @qcho we need to add @valibot/to-json-schema to optional peer deps.
And, I'd love to add zod/zod-to-json-schema to peer deps
|
Core Issue: When a single bundle file is too large, asynchronously importing dependencies can significantly increase loading time. If the server is started before asynchronous loading is complete, toJsonSchema will be undefined. FastMCP registers multiple tools upon startup. Each tool's parameter definition (such as Zod, ArkType, and Valibot schema) triggers the asynchronous import mechanism of xsschema. xsschema dynamically loads a converter library (such as zod-to-json-schema and @valibot/to-json-schema) based on the schema type. The schema is then converted to JSON Schema for tool parameter validation. Finally, the server is started and the client waits for calls. It is recommended to precompile the package for static import, or at least check and wait for the package to be imported before calling toJsonSchema. |
Overview
This PR replaces direct Zod usage with Standard Schema support, allowing users to choose their preferred validation library while maintaining existing functionality.
Changes
@standard-schema/specandxsschemadependenciesToolParameterstype to useStandardSchemaV1zodToJsonSchemawithtoJsonSchemaBenefits
Todo
Related Issues
Resolves #26