Skip to content

Commit 89b7552

Browse files
fix(schema-to-json): represent z.date() as string/date-time instead of throwing
1 parent f46c5cd commit 89b7552

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/schema-to-json": patch
3+
---
4+
5+
Fix Zod 4 schema conversion throwing "Date cannot be represented in JSON Schema". `z.date()` fields now convert to `{ type: "string", format: "date-time" }` instead of aborting the whole conversion, which was causing the MCP server's `tools/list` to fail (no tools loaded) whenever a tool schema contained a date.

‎packages/schema-to-json/src/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,19 @@ function convertZod4Schema(schema: any, options?: ConversionOptions): JSONSchema
156156
target: "draft-7",
157157
io: "output",
158158
reused: useReferences ? "ref" : "inline",
159+
// Emit `{}` for otherwise-unrepresentable types so `override` can rewrite
160+
// them, instead of Zod throwing and failing the whole conversion.
161+
unrepresentable: "any",
159162
override: ({ zodSchema, jsonSchema }) => {
160163
const def = zodSchema._zod.def;
161164
if (def.type === "undefined") {
162165
throw new Error("Undefined cannot be represented in JSON Schema");
163166
}
164167

168+
if (def.type === "date") {
169+
Object.assign(jsonSchema, { type: "string", format: "date-time" });
170+
}
171+
165172
if (def.type === "object" && jsonSchema.required) {
166173
// Early Zod 4 permalinks do not propagate optional output through unions.
167174
const required = jsonSchema.required.filter((key) => {

‎packages/schema-to-json/tests/index.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ describe("schemaToJsonSchema", () => {
110110
"Undefined cannot be represented in JSON Schema"
111111
);
112112
});
113+
114+
it("represents dates as ISO date-time strings instead of throwing", () => {
115+
const schema = z.object({ from: z.date() });
116+
const result = schemaToJsonSchema(schema);
117+
expect((result?.jsonSchema.properties as Record<string, unknown>).from).toMatchObject({
118+
type: "string",
119+
format: "date-time",
120+
});
121+
});
113122
});
114123

115124
it("preserves explicitly required metadata on current optional schemas", () => {

0 commit comments

Comments
 (0)