Skip to content

Commit 4d5af60

Browse files
geezoria1337claude
andcommitted
fix(server): ACP MCP bridge no longer splits messages on U+2028/U+2029
node:readline treats U+2028 and U+2029 as line breaks, but JSON.stringify leaves both characters raw inside strings. A tools/call whose arguments contained either one was cut into invalid fragments, answered with parse errors, and never forwarded, so the agent's tool call hung. Frame stdin on line feeds with Stream.splitLines instead, matching the LF-only framing Pi's RPC already uses for the same reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8b44f42 commit 4d5af60

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎apps/server/src/mcp/AcpMcpStdioBridge.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ describe("AcpMcpStdioBridge", () => {
163163
}),
164164
);
165165

166+
it.effect("keeps U+2028 and U+2029 inside a message instead of splitting it", () =>
167+
Effect.gen(function* () {
168+
const { input, written, requests, bridge } = makeHarness(() =>
169+
Response.json({ jsonrpc: "2.0", id: 4, result: { ok: true } }),
170+
);
171+
const fiber = yield* Effect.forkChild(bridge);
172+
// JSON.stringify leaves both separators unescaped, as MCP stdio clients send them.
173+
const message = JSON.stringify({
174+
jsonrpc: "2.0",
175+
id: 4,
176+
method: "tools/call",
177+
params: { name: "echo", arguments: { text: "a\u2028b\u2029c" } },
178+
});
179+
180+
input.end(`${message}\n`);
181+
yield* Fiber.join(fiber);
182+
183+
expect(requests.map((request) => request.body)).toEqual([message]);
184+
expect(written.map((chunk) => JSON.parse(chunk))).toEqual([
185+
{ jsonrpc: "2.0", id: 4, result: { ok: true } },
186+
]);
187+
}),
188+
);
189+
166190
it.effect("forwards SSE messages before the HTTP response closes", () =>
167191
Effect.gen(function* () {
168192
let resolveResponseController!: (

‎apps/server/src/mcp/AcpMcpStdioBridge.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Relay JSON-RPC verbatim; schema decoding would reject foreign payloads.
2-
// @effect-diagnostics nodeBuiltinImport:off preferSchemaOverJson:off
3-
import * as NodeReadline from "node:readline";
4-
2+
// @effect-diagnostics preferSchemaOverJson:off
53
import * as Cause from "effect/Cause";
64
import * as Effect from "effect/Effect";
75
import * as Result from "effect/Result";
@@ -311,8 +309,12 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
311309
return yield* launch(task);
312310
});
313311

314-
const reader = NodeReadline.createInterface({ input: options.input });
315-
yield* Stream.runForEach(Stream.fromAsyncIterable(reader, bridgeError), dispatch).pipe(
312+
// node:readline also splits on U+2028/U+2029, which JSON.stringify leaves raw inside strings.
313+
yield* Stream.fromAsyncIterable(options.input, bridgeError).pipe(
314+
Stream.map((chunk) => (typeof chunk === "string" ? Buffer.from(chunk) : chunk)),
315+
Stream.decodeText(),
316+
Stream.splitLines,
317+
Stream.runForEach(dispatch),
316318
Effect.ignoreCause,
317319
);
318320
yield* Fiber.awaitAll(running);

0 commit comments

Comments
 (0)