Skip to content

Conversation

pierreliefauche
Copy link
Contributor

@pierreliefauche pierreliefauche commented Sep 23, 2025

When converting Zod schema to JSONSchema, set the pipe strategy to the mode corresponding to the schema being generated, either input or output.
This should help fix issues when the Zod schema has transforms.

Motivation and Context

Some Zod schemas have transforms in the form of pipes.
When generating a JSONSchema, zod-to-json-schema needs to be instructed as to which "side" of the pipe it should select for the JSON schema. For example z.string().pipe(z.number()) will be a string as input but number as output.

How Has This Been Tested?

I've been applying this patch-package for a couple months in production.

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

When converting Zod schema to JSONSchema, set the pipe strategy to the mode corresponding to the schema being generated, either input or output.
This should help fix issues when the Zod schema has transforms.
@pierreliefauche pierreliefauche marked this pull request as ready for review September 23, 2025 16:33
@pierreliefauche pierreliefauche requested review from a team and ihrpr September 23, 2025 16:33
@pierreliefauche pierreliefauche changed the title Zod to JSONSchema pipe strategies fix: Zod to JSONSchema pipe strategies Sep 23, 2025
@felixweinberger felixweinberger requested review from a team and ochafik September 25, 2025 14:52
@pierreliefauche pierreliefauche requested a review from a team as a code owner October 8, 2025 19:05
@pierreliefauche
Copy link
Contributor Author

cc @ihrpr 🙏

Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sorry about the delays in review, appreciate your contribution!

@ihrpr ihrpr merged commit c543095 into modelcontextprotocol:main Oct 18, 2025
2 checks passed
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.

2 participants