Skip to content

Conversation

pierreliefauche
Copy link

@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 few weeks 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
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