trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

bug: MCP server --dev-only cannot list tools on v4.6.0 — "Date cannot be represented in JSON Schema"

Open SleepTimeGRT opened this issue 2 months ago • 1 comments

Provide environment information

  System:
    OS: macOS 26.6.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 6.78 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.20.0
    npm: 11.19.0
    pnpm: 11.26.0
    bun: 1.3.11

CLI: [email protected] (current latest, published 2026-09-14)

Describe the bug

Starting with v4.6.0, the MCP server started with --dev-only fails every tools/list request:

{"jsonrpc":"2.0","id":2,"error":{"code":-32603,"message":"Date cannot be represented in JSON Schema"}}

The process starts and the initialize handshake succeeds (serverInfo reports 4.6.0), but because tool definitions are serialized to JSON Schema as one batch, a single unserializable schema takes down the entire listing — all 40 tools disappear, not just the offending one.

--readonly is unaffected.

Root cause

v4.6.0 switched the CLI to Zod 4 (zod: 3.25.76 → 4.5.4, per the "Zod 4 by default" changelog entry). The trigger_task input schema in packages/cli-v3/src/mcp/schemas.ts#L88-L91 contains a ZodDate:

delay: z
  .string()
  .or(z.coerce.date())
  .describe("The delay before the task run is executed")
  .optional(),

Zod 3's zodToJsonSchema approximated ZodDate as {"type":"string","format":"date-time"}. Zod 4's z.toJSONSchema() treats it as unrepresentable and throws unless unrepresentable: "any" is passed. The schema itself did not change — the Zod upgrade surfaced a latent problem.

--readonly is unaffected because trigger_task is a write tool and is excluded from the readonly tool set, so no ZodDate is ever reached.

Impact

For MCP clients this is not a degraded experience but a hard failure:

  • Codex CLI with required = true on the server aborts session creation entirely: thread/start failed: required MCP servers failed to initialize: trigger: Mcp error: -32603: Date cannot be represented in JSON Schema
  • Claude Code silently drops the server — all dev tools vanish with no visible error.

Anyone whose MCP config pins trigger.dev@latest (which is what npx trigger.dev@latest install-mcp and the docs suggest) was moved onto 4.6.0 automatically and lost every dev-mode tool.

Reproduction repo

No repo required — a single command reproduces it (see below).

To reproduce

printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"t","version":"1"}}}' \
  '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
  | npx -y [email protected] mcp --dev-only

Actual output for id: 2:

{"jsonrpc":"2.0","id":2,"error":{"code":-32603,"message":"Date cannot be represented in JSON Schema"}}

Expected: a tool list (40 tools on 4.5.16).

Swapping the version reproduces the boundary exactly:

CLI version bundled zod mcp --dev-only → tools/list
4.5.9 3.25.76 OK (38 tools)
4.5.16 3.25.76 OK (40 tools)
4.6.0 4.5.4 -32603 Date cannot be represented in JSON Schema
4.6.0 --readonly 4.5.4 OK
0.0.0-prerelease-20260911153544 — same failure

Isolating it to the schema

Running the exact delay schema through each Zod version, using the CLI's own bundled zod:

const delay = z.string().or(z.coerce.date());

// zod 4.5.4
z.toJSONSchema(z.object({ delay }));
// => throws: Date cannot be represented in JSON Schema

// zod 4.5.4 with the escape hatch
z.toJSONSchema(z.object({ delay }), { unrepresentable: "any" });
// => {"delay":{"anyOf":[{"type":"string"},{}]}}     // note: the date branch degrades to {}

// zod 3.25.76
zodToJsonSchema(z.object({ delay }));
// => {"delay":{"anyOf":[{"type":"string"},{"type":"string","format":"date-time"}]}}

Additional information

Suggested fix — replacing the ZodDate keeps the JSON Schema meaningful, whereas unrepresentable: "any" would erase the date branch to {} and lose it from the tool contract:

delay: z
  .string()
  .or(z.iso.datetime())
  .describe("The delay before the task run is executed")
  .optional(),

Since MCP transports every argument as JSON anyway, a Date instance could never arrive over the wire — the z.coerce.date() branch only ever received a string in practice.

Worth grepping the rest of the MCP tool schemas for other ZodDate / z.coerce.date() usages that Zod 4 would now reject; trigger_task is the only one I found in packages/cli-v3/src/mcp/, but the same class of change could affect other unrepresentable types introduced by the Zod 4 migration.

SleepTimeGRT avatar Sep 15 '26 08:09 SleepTimeGRT

Fixed in https://github.com/triggerdotdev/trigger.dev/commit/6c90639f2 — your diagnosis was exactly right, and the fix is the one you suggested.

delay on trigger_task is now z.string().or(z.iso.datetime()). As you noted, the z.coerce.date() branch was already unreachable: z.string() matches first and MCP arguments always arrive as JSON, so it only ever received strings. Verified against a local build — mcp, mcp --dev-only all list 40 tools again, and --readonly is unchanged at 26.

Also added a test that runs toJSONSchema over every exported MCP schema, so this class of failure is caught rather than shipping.

This will go out with the next release; until then, pinning [email protected] in your MCP config is the workaround.

Thanks for the write-up — the version boundary table and the isolated Zod repro made this trivial to confirm.

isshaddad avatar Sep 15 '26 15:09 isshaddad