-
Notifications
You must be signed in to change notification settings - Fork 197
Open
Description
A U+2028 LINE SEPARATOR in MCP tool results causes the claude SDK to fail with
Error: CLI output was not valid JSON. This may indicate an error during startup. Output: {"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01F1kfdYcsZrBCXmE8y7bn6k","type":"tool_result","content":[{"type":"text","text":"before
Minimal repro below:
#!/usr/bin/env npx tsx
/**
* U+2028 LINE SEPARATOR in MCP tool results causes JSON parsing failures.
*
* - JSON.stringify does NOT escape U+2028
* - Node's readline treats U+2028 as a line terminator
* - The JSON line gets split, causing JSON.parse to fail
*/
import { query, createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";
const mcpServer = createSdkMcpServer({
name: "test",
version: "1.0.0",
tools: [
tool("get_text", "Get text", { id: z.string() }, async () => ({
content: [{ type: "text", text: "before\u2028after" }],
})),
],
});
(async () => {
const q = query({
prompt: "Call get_text with id 'x'",
options: {
model: "haiku",
mcpServers: { test: mcpServer },
allowedTools: ["mcp__test__get_text"],
tools: [],
},
});
for await (const msg of q) {
if (msg.type === "result") break;
}
})();Metadata
Metadata
Assignees
Labels
No labels