fix: resolve Zod v4 toJSONSchema crash on z.record(z.unknown())#4
fix: resolve Zod v4 toJSONSchema crash on z.record(z.unknown())#4samcolmanetti wants to merge 1 commit intoobra:mainfrom
Conversation
z.record(z.unknown()) crashes Zod v4's toJSONSchema() because z.unknown() lacks the _zod metadata the serializer expects. The MCP SDK calls toJSONSchema() on every tool schema during tools/list, so this silently hides all tools from clients. Replace with z.record(z.string(), z.any()) which is semantically equivalent and serializes correctly. Add regression test that verifies the fixed schema serializes and documents the upstream Zod v4 bug. Fixes obra#2
|
+1 — applied this locally on macOS and Worth flagging that minor nit on the PR description: in zod v4, Would be great to get this merged — it's been five weeks and the broken |
Problem
The MCP server connects and initializes successfully, but
tools/listreturns an internal error — silently hiding all 14 tools from clients.The root cause is that Zod v4's
toJSONSchema()crashes onz.record(z.unknown())in thekg_create_nodetool schema:z.unknown()in Zod v4 lacks the_zodmetadata thattoJSONSchemaexpects. The MCP SDK (v1.27+) callstoJSONSchema()on every tool schema duringtools/list, so this single schema issue breaks all tool registration.Fix
Replace
z.record(z.unknown())withz.record(z.string(), z.any())inkg_create_node's frontmatter parameter.z.any()is semantically equivalent but has the_zodmetadata thattoJSONSchemarequires.Tests
Added
test/mcp-schemas.test.tswith two cases:z.record(z.unknown())throws)Fixes #2