fix: do not use references in Zod to JSON Schema #1082
+4
−2
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.
Many LLMs do not support references in the JSON Schemas for tool inputs/outputs and if they do, they mostly only support root-level references. Schemas produced with Zod to JSON Schema do not comply with this restriction thus, if using strict tool calling (e.g. in OpenAI), the request fails. While this is not documented as a limitation in the MCP Specification, for convenience we should avoid triggering this issue.
Motivation and Context
When trying out the TypeScript SDK we have used nested definitions for a group of fields. While I cannot provide the exact schema, but here's a quick mock:
How Has This Been Tested?
I have tested my code with the lines from this PR and without it. Without my change, strict tool calling ends up in:
With my changes, the code runs properly.
Breaking Changes
No breaking changes and, to the best of my knowledge, no LLM providers charge extra for longer JSON Schemas, so this should not impact the users negatively.
Types of changes
Checklist
Additional context