Skip to content

fix(schema-to-json): handle Zod 4 dates when converting to JSON Schema - #4944

Closed
MauryaQbit wants to merge 1 commit into
triggerdotdev:mainfrom
MauryaQbit:fix/mcp-zod4-date-json-schema
Closed

MauryaQbit wants to merge 1 commit into
triggerdotdev:mainfrom
MauryaQbit:fix/mcp-zod4-date-json-schema

Conversation

@MauryaQbit

Copy link
Copy Markdown

Fixes #4939

Hit this when a tool had a z.date() field - the whole tools/list call blew up with Date cannot be represented in JSON Schema, so no tools loaded at all. Turns out toJSONSchema throws on dates by default and that error took down the entire conversion.

Changed convertZod4Schema to pass unrepresentable any and map date fields to string/date-time in the existing override, same as what the Zod 3 path already produces. Other unrepresentable types now fall back to {} instead of killing the whole list too.

Added a test for an object with a date field and ran the schema-to-json suite, 22/22 pass. Also ran oxlint on the touched files, clean.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2f25ef9d-f555-48ce-b210-7ad816ce2aba

📥 Commits

Reviewing files that changed from the base of the PR and between 3f4ac50 and 671e40a.

📒 Files selected for processing (3)
  • .changeset/tidy-dates-shout.md
  • packages/schema-to-json/src/index.ts
  • packages/schema-to-json/tests/index.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (5)
**Public packages** (`packages/*`): Use `build`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/schema-to-json/tests/index.test.ts
  • packages/schema-to-json/src/index.ts
Use vitest for all tests in the Trigger.dev repository

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/schema-to-json/tests/index.test.ts
Use function declarations instead of default exports

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/schema-to-json/tests/index.test.ts
  • packages/schema-to-json/src/index.ts
Use types over interfaces for TypeScript Avoid using enums; prefer string unions or const objects instead

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/schema-to-json/tests/index.test.ts
  • packages/schema-to-json/src/index.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs Do not use high-cardinality attributes in OTEL metr...

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

Files:

  • packages/schema-to-json/tests/index.test.ts
  • packages/schema-to-json/src/index.ts
🧠 Learnings (1)
📚 Learning: 2026-06-16T09:19:47.637Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3960
File: apps/webapp/test/prismaInfrastructureErrorCapture.test.ts:0-0
Timestamp: 2026-06-16T09:19:47.637Z
Learning: In this repo’s Vitest setup, `vitest.config.ts` uses `globals: true`, so identifiers like `vi`, `describe`, `it`, and `expect` are available as globals in Vitest test files. During code review, do not flag missing `vi`/`describe`/`it`/`expect` imports as a runtime error or correctness issue when they’re used in `*.test.ts/tsx` or `*.spec.ts/tsx` files. Explicit imports are still preferred for consistency, but they’re not required for runtime behavior.

Applied to files:

  • packages/schema-to-json/tests/index.test.ts
🔇 Additional comments (3)
packages/schema-to-json/src/index.ts (1)

159-161: LGTM!

Also applies to: 164-168

packages/schema-to-json/tests/index.test.ts (1)

55-70: LGTM!

.changeset/tidy-dates-shout.md (1)

1-5: LGTM!


Walkthrough

The Zod 4 converter now maps date schemas to JSON Schema strings with the date-time format. It also represents other unrepresentable types as any instead of failing the conversion. A test verifies the date output and required property. A changeset declares a patch release for @trigger.dev/schema-to-json.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 671e4

The change addresses the reported Zod 4 date-conversion failure, and no concrete unresolved merge-blocking risk is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the schema-to-JSON fix and the affected Zod 4 date behavior.
Description check ✅ Passed The description explains the issue, implementation, testing results, and behavior changes. It omits the required checklist and screenshots sections, but the core technical and testing information is c…
Linked Issues check ✅ Passed The changes satisfy #4939. convertZod4Schema() now uses unrepresentable: "any", so unrepresentable types do not abort conversion. The override maps Zod 4 date fields to `{ type: "string", format: …
Out of Scope Changes check ✅ Passed The changes stay within #4939. The source update fixes Zod 4 schema conversion, the test covers the required date behavior, and the changeset documents the patch release. No unrelated behavior or file…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @MauryaQbit, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Sep 16, 2026

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

Devin Review

reused: useReferences ? "ref" : "inline",
// Dates (and other unrepresentable types) throw by default, which fails the
// whole conversion. Fall back to `any` and handle dates in override instead.
unrepresentable: "any",

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.

🟡 Unsupported types become unconstrained schemas

For unsupported Zod 4 types, unrepresentable now emits {} instead of failing conversion. Published schemas accept arbitrary JSON that the runtime parser rejects.

Learn more

Zod's unrepresentable: "any" converts every unrepresentable node to an unconstrained JSON Schema. The override repairs dates and rejects undefined, but it leaves other unsupported nodes unconstrained. The resulting schema no longer describes the parser used at runtime. Callers publish this result as task payload and prompt-variable schemas in convertSchemasToJsonSchemas and convertPromptSchemasToJsonSchemas.

Example: A field declared as z.bigint() becomes {}. A client can generate or submit a string or number because the published JSON Schema permits it, but z.bigint() rejects that JSON value.

Recommended fix: Keep the date override, but throw for every other unrepresentable Zod type so existing callers omit the inaccurate schema. If Zod requires unrepresentable: "any" for the date override to run, inspect each generated node in override and whitelist only def.type === "date"; reject the remaining unrepresentable definitions explicitly.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

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

1 participant