Summary
The MCP server fails to list tools when using Zod v4, because z.record(z.unknown()) in
kg_create_node's schema crashes Zod v4's JSON schema generator.
Reproduction
The MCP SDK (v1.28) detects Zod v4 and uses zod/v4-mini's toJSONSchema() to serialize tool schemas.
When it hits the frontmatter parameter on kg_create_node:
frontmatter: z.record(z.unknown()).optional()
...it throws:
TypeError: Cannot read properties of undefined (reading '_zod')
at process (zod/v4/core/to-json-schema.js:33:24)
at Module.recordProcessor (zod/v4/core/json-schema-processors.js:432:37)
The server connects and initializes fine, but tools/list returns an error, so no tools are exposed to
the client.
Fix
Change z.unknown() to z.any() in src/mcp/index.ts line 242:
- frontmatter: z.record(z.unknown()).optional().describe('YAML frontmatter fields (type, tags, status,
related, etc.)'),
- frontmatter: z.record(z.string(), z.any()).optional().describe('YAML frontmatter fields (type, tags,
status, related, etc.)'),
This is likely a Zod v4 bug (z.unknown() lacks the _zod metadata that toJSONSchema expects), but the
workaround is simple and z.any() is semantically equivalent here.
Environment
- knowledge-graph v0.1.0
- zod 4.3.6
- @modelcontextprotocol/sdk 1.28.0
- Claude Code as MCP client
Summary
The MCP server fails to list tools when using Zod v4, because
z.record(z.unknown())inkg_create_node's schema crashes Zod v4's JSON schema generator.Reproduction
The MCP SDK (v1.28) detects Zod v4 and uses
zod/v4-mini'stoJSONSchema()to serialize tool schemas.When it hits the
frontmatterparameter onkg_create_node:...it throws:
The server connects and initializes fine, but tools/list returns an error, so no tools are exposed to
the client.
Fix
Change z.unknown() to z.any() in src/mcp/index.ts line 242:
related, etc.)'),
status, related, etc.)'),
This is likely a Zod v4 bug (z.unknown() lacks the _zod metadata that toJSONSchema expects), but the
workaround is simple and z.any() is semantically equivalent here.
Environment