Skip to content

MCP tools/list fails with "Date cannot be represented in JSON Schema" when a tool schema uses z.date() (Zod 4) #4939

Description

@brentshulman-silkline

What happens

The MCP server fails tools/list outright — clients load zero tools — whenever any tool's input schema contains a z.date() field. With trigger.dev@4.6.0:

trigger: npx trigger.dev@latest mcp - ! Connected · tools fetch failed — Date cannot be represented in JSON Schema

Reproduce directly against the CLI:

printf '%s\n' \
 '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"p","version":"1"}}}' \
 '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
 '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
 | npx trigger.dev@4.6.0 mcp
# -> {"jsonrpc":"2.0","id":2,"error":{"code":-32603,"message":"Date cannot be represented in JSON Schema"}}

Expected

tools/list succeeds and date fields serialize to a JSON Schema string (e.g. { "type": "string", "format": "date-time" }), matching how the Zod 3 path already handles z.date().

Root cause

In @trigger.dev/schema-to-json, convertZod4Schema() (packages/schema-to-json/src/index.ts) calls z4.toJSONSchema() without the unrepresentable option, so it defaults to "throw". Any z.date() throws Date cannot be represented in JSON Schema, which aborts the entire conversion and fails the whole tools/list response.

Version info

  • Broken: trigger.dev@4.6.0 (also present on main).
  • Works: 4.5.16, 4.5.0, 4.4.6.

Suggested fix

Pass unrepresentable: "any" to z4.toJSONSchema() so unrepresentable nodes emit {} and reach the existing override callback, and add a date case to override rewriting to { type: "string", format: "date-time" }. (Happy to open a PR.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions