Description:
Bug Report
When using mcpServers in createAgent(), network.run() throws:
TypeError: Cannot read properties of undefined (reading 'def')
The error occurs because listMCPTools converts MCP tool JSON Schemas into Zod schemas using @dmitryrechkin/json-schema-to-zod, which bundles Zod v3 (zod@^3.23.8). These Zod v3 schemas are then stored as parameters on the tool object.
Later, the model adapters (Anthropic, OpenAI, Gemini) call Zod v4's toJSONSchema() on these schemas to build the LLM API request. Zod v4's toJSONSchema() expects v4 schema internals (.def.type) which don't exist on v3 schemas, causing the crash.
Code path
listMCPTools (chunk-BSWKEFTT.js ~L1650): JSONSchemaToZod.convert(t.inputSchema) → produces a Zod v3 schema
Anthropic adapter (L374): z.toJSONSchema(t.parameters, ...) → calls Zod v4 toJSONSchema on the v3 schema → 💥
Same issue in OpenAI adapter (L499) and Gemini adapter (L607)
Reproduction
import { createAgent, createNetwork } from '@inngest/agent-kit';const agent = createAgent({ name: 'test', system: 'You are a test agent.', model: openai({ model: 'gpt-4o' }), mcpServers: [ { name: 'my-server', transport: { type: 'streamable-http', url: 'http://localhost:3000/api/mcp', }, }, ],});const network = createNetwork({ name: 'test-network', agents: [agent],});// This throws: Cannot read properties of undefined (reading 'def')await network.run('hello');
Any MCP server that returns tools with an inputSchema triggers this.
Root cause
@dmitryrechkin/json-schema-to-zod@1.0.1 declares "zod": "^3.23.8" as a hard dependency and imports ZodSchema from Zod — a named export that doesn't exist in Zod v4. So the conversion always produces Zod v3 schemas, even though agent-kit's peer dependency is zod >= 4 < 5.
The round-trip (JSON Schema → Zod v3 schema → Zod v4 toJSONSchema() → JSON Schema) is unnecessary for MCP tools since the original JSON Schema is already available on t.mcp.tool.inputSchema.
Suggested fix
In the model adapters, when t.parameters is falsy (which it always is for MCP tools now that JSONSchemaToZod.convert produces incompatible schemas), fall back to t.mcp.tool.inputSchema directly:
// Anthropic adapter — before:input_schema: t.parameters ? z.toJSONSchema(t.parameters, { target: "draft-2020-12" }) : z.toJSONSchema(z.object({}), { target: "draft-2020-12" })// After:input_schema: t.parameters ? z.toJSONSchema(t.parameters, { target: "draft-2020-12" }) : (t.mcp?.tool?.inputSchema ?? z.toJSONSchema(z.object({}), { target: "draft-2020-12" }))
Same pattern for OpenAI and Gemini adapters. Alternatively, replace @dmitryrechkin/json-schema-to-zod with a Zod v4-compatible JSON-Schema-to-Zod converter, or skip the conversion entirely and pass inputSchema through as-is for MCP tools.
Environment
@inngest/agent-kit: 0.13.2
inngest: 3.54.0
zod: 4.3.6
Node: v24.12.0
Deployed on Vercel (Next.js 16)
Workaround
We're using a pnpm patch on @inngest/agent-kit@0.13.2 that:
Removes the JSONSchemaToZod.convert() call in listMCPTools (sets parameters: undefined)
Adds t.mcp.tool.inputSchema fallback in all three model adapters
Related issues
#210 — Incompatibility with zod@4 in createTool.parameters (fixed createTool path, but not MCP path)
#156 — Zod v4 support (noted json-schema-to-zod didn't have v4 support)
#77 — ESM Module Error with @dmitryrechkin/json-schema-to-zod
Description:
Bug Report
When using mcpServers in createAgent(), network.run() throws:
TypeError: Cannot read properties of undefined (reading 'def')
The error occurs because listMCPTools converts MCP tool JSON Schemas into Zod schemas using @dmitryrechkin/json-schema-to-zod, which bundles Zod v3 (zod@^3.23.8). These Zod v3 schemas are then stored as parameters on the tool object.
Later, the model adapters (Anthropic, OpenAI, Gemini) call Zod v4's toJSONSchema() on these schemas to build the LLM API request. Zod v4's toJSONSchema() expects v4 schema internals (.def.type) which don't exist on v3 schemas, causing the crash.
Code path
listMCPTools (chunk-BSWKEFTT.js ~L1650): JSONSchemaToZod.convert(t.inputSchema) → produces a Zod v3 schema
Anthropic adapter (L374): z.toJSONSchema(t.parameters, ...) → calls Zod v4 toJSONSchema on the v3 schema → 💥
Same issue in OpenAI adapter (L499) and Gemini adapter (L607)
Reproduction
import { createAgent, createNetwork } from '@inngest/agent-kit';const agent = createAgent({ name: 'test', system: 'You are a test agent.', model: openai({ model: 'gpt-4o' }), mcpServers: [ { name: 'my-server', transport: { type: 'streamable-http', url: 'http://localhost:3000/api/mcp', }, }, ],});const network = createNetwork({ name: 'test-network', agents: [agent],});// This throws: Cannot read properties of undefined (reading 'def')await network.run('hello');
Any MCP server that returns tools with an inputSchema triggers this.
Root cause
@dmitryrechkin/json-schema-to-zod@1.0.1 declares "zod": "^3.23.8" as a hard dependency and imports ZodSchema from Zod — a named export that doesn't exist in Zod v4. So the conversion always produces Zod v3 schemas, even though agent-kit's peer dependency is zod >= 4 < 5.
The round-trip (JSON Schema → Zod v3 schema → Zod v4 toJSONSchema() → JSON Schema) is unnecessary for MCP tools since the original JSON Schema is already available on t.mcp.tool.inputSchema.
Suggested fix
In the model adapters, when t.parameters is falsy (which it always is for MCP tools now that JSONSchemaToZod.convert produces incompatible schemas), fall back to t.mcp.tool.inputSchema directly:
// Anthropic adapter — before:input_schema: t.parameters ? z.toJSONSchema(t.parameters, { target: "draft-2020-12" }) : z.toJSONSchema(z.object({}), { target: "draft-2020-12" })// After:input_schema: t.parameters ? z.toJSONSchema(t.parameters, { target: "draft-2020-12" }) : (t.mcp?.tool?.inputSchema ?? z.toJSONSchema(z.object({}), { target: "draft-2020-12" }))
Same pattern for OpenAI and Gemini adapters. Alternatively, replace @dmitryrechkin/json-schema-to-zod with a Zod v4-compatible JSON-Schema-to-Zod converter, or skip the conversion entirely and pass inputSchema through as-is for MCP tools.
Environment
@inngest/agent-kit: 0.13.2
inngest: 3.54.0
zod: 4.3.6
Node: v24.12.0
Deployed on Vercel (Next.js 16)
Workaround
We're using a pnpm patch on @inngest/agent-kit@0.13.2 that:
Removes the JSONSchemaToZod.convert() call in listMCPTools (sets parameters: undefined)
Adds t.mcp.tool.inputSchema fallback in all three model adapters
Related issues
#210 — Incompatibility with zod@4 in createTool.parameters (fixed createTool path, but not MCP path)
#156 — Zod v4 support (noted json-schema-to-zod didn't have v4 support)
#77 — ESM Module Error with @dmitryrechkin/json-schema-to-zod