Skip to content

add zDateRangeInclude and zFlexibleDate as factory functions - #48

Merged
gregsaab merged 2 commits into
mainfrom
lee/no-pointers
Jul 24, 2026
Merged

gregsaab merged 2 commits into
mainfrom
lee/no-pointers

Conversation

@LeeHampton

Copy link
Copy Markdown
Contributor

zod-to-json-schema emits pointers when a Zod schema instance is reused across multiple fields. Several LLM providers (e.g. Moonshot/Kimi K3) reject values that don't start with "#//", breaking tool use for any MCP server that shares a Zod singleton across parameters.

These factory functions return a fresh instance on every call so the generated JSON Schema is always inlined — zero references. Downstream MCP servers can import them instead of defining their own, avoiding a class of compatibility bugs that are hard to diagnose.

See: modelcontextprotocol/typescript-sdk#1563
modelcontextprotocol/typescript-sdk#2100

We initially took at a stab at fixing a very specific issue we saw around the billing MCP in this PR
https://github.com/timescale/tiger-billing-mcp-server/pull/7

But changing it here will get ahead of any other MCPs that end up implementing a similar pattern. This does not however change any future schema changes that result in references. If it becomes an issue we might have to think of a broader fix.

@LeeHampton
LeeHampton requested a review from gregsaab July 24, 2026 16:26
@LeeHampton
LeeHampton requested a review from a team as a code owner July 24, 2026 16:26
@CLAassistant

CLAassistant commented Jul 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

gregsaab
gregsaab previously approved these changes Jul 24, 2026

@gregsaab gregsaab left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sweet -- I'll handle the deployment and updating billing mcp

Edit: failing typecheck

zod-to-json-schema emits $ref pointers when a Zod schema instance is
reused across multiple fields. Several LLM providers (e.g. Moonshot/Kimi K3)
reject $ref values that don't start with "#/$defs/", breaking tool use
for any MCP server that shares a Zod singleton across parameters.

These factory functions return a fresh instance on every call so the
generated JSON Schema is always inlined — zero $ref references.
Downstream MCP servers can import them instead of defining their own,
avoiding a class of compatibility bugs that are hard to diagnose.

See: modelcontextprotocol/typescript-sdk#1563
     modelcontextprotocol/typescript-sdk#2100
The SDK's wildcard export map does not append extensions, so
'@modelcontextprotocol/sdk/server/zod-json-schema-compat' only resolves
with the explicit .js suffix.

Co-Authored-By: Claude Fable 5 <[email protected]>

@gregsaab gregsaab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

@gregsaab
gregsaab merged commit 1b6147b into main Jul 24, 2026
3 checks passed
@gregsaab
gregsaab deleted the lee/no-pointers branch July 24, 2026 18:13
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.

3 participants