anthropics / anthropics/claude-agent-sdk-typescript
z.record() tool schema crashes tools/list of SDK MCP servers since 0.3.257 — all tools of the server silently disappear
- Linguagem predominante
- Shell
- Estrelas
- 1.8k
- Forks
- 226
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
**Summary**
Since @anthropic-ai/claude-agent-sdk 0.3.257, defining an in-process MCP tool (via tool() + createSdkMcpServer()) whose input schema contains z.record(...) makes the server's tools/list request fail with:
MCP error -32603: Cannot read properties of undefined (reading 'push')
Because the conversion happens inside the tools/list handler, a single affected tool takes down the listing for the entire server: the session's init message still reports the server as "status": "connected", but none of its
tools appear in tools, and the model gets No such tool available: mcp____ when it tries to call them from memory/prompt hints. There is no error surfaced to the host application, so the tools just silently
vanish.
0.3.252 is the last good version. 0.3.257 (the next published version) is broken, and the latest 0.3.263 is still broken. Zod is 4.5.4, matching the stated peer range (zod: ^4.0.0), deduped to a single copy across the SDK,
@modelcontextprotocol/sdk 1.29.0, and the app.
**Minimal reproduction**
No API key needed — the crash is in schema conversion, reachable through an in-memory MCP client:
```
import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { z } from "zod";
const server = createSdkMcpServer({
name: "repro",
version: "1.0.0",
tools: [
tool("t", "demo", { a: z.record(z.string(), z.string()).optional() },
async () => ({ content: [{ type: "text", text: "ok" }] })),
],
}) as any;
const [ct, st] = InMemoryTransport.createLinkedPair();
await server.instance.connect(st);
const client = new Client({ name: "probe", version: "1.0.0" });
await client.connect(ct);
await client.listTools(); // throws on >=0.3.257, works on 0.3.252
```
- On 0.3.252: resolves, schema converts to {"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}}.
- On 0.3.257–0.3.263: rejects with McpError: MCP error -32603: Cannot read properties of undefined (reading 'push').
Other schema shapes we tested (z.string(), z.boolean().optional(), z.number(), z.enum([...]), z.array(z.object({...})), z.object({...})) all convert fine — only z.record(...) crashes.
**Suspected cause**
sdk.mjs in the affected versions bundles a zod-to-json-schema-style converter (the "Let zodToJsonSchema decide on which parser to use" symbol and its option defaults are visible in the bundle). That library targets zod v3
internals, and its record parser appears to trip over zod v4's record _def shape (the reading 'push' TypeError is consistent with its string-check handling on a key type it can't introspect). Zod v4's native z.toJSONSchema()
handles the same schema fine.
**Expected behavior**
Either convert z.record(...) correctly (as 0.3.252 did), or at minimum fail per-tool with a surfaced error instead of silently dropping every tool on the server while reporting it connected.
**Environment**
- @anthropic-ai/claude-agent-sdk: 0.3.263 (bisected: broken since 0.3.257, last good 0.3.252)
- zod: 4.5.4 (single deduped copy)
- @modelcontextprotocol/sdk: 1.29.0
- Node.js 25.2.1, macOS (darwin arm64)
**Workaround**
Replacing z.record(z.string(), z.string()) with z.object({}).catchall(z.string()) produces an equivalent JSON schema (additionalProperties: {type: "string"}) and converts without error.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Avaliação
Esta issue ainda não foi avaliada.