@devries-cameron20 / t3code Mirror · read-only / commits / eee9ba1d3d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

fix(server): ACP MCP bridge no longer splits messages on U+2028/U+2029 (#30719)

Co-authored-by: Geezy <igor.licko@gloryck.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

TheGuyWithHAT committed Nov 6, 2026 at 05:35 UTC eee9ba1d3d673d0bfd5df8a8185057c499b78f4f
2 files changed +41 -7
apps/server/src/mcp/AcpMcpStdioBridge.test.ts
+34 -2
@@ -9,8 +9,10 @@ import { vi } from "vite-plus/test";
9
10 import { mcpToolSession, runAcpMcpCliFastPath, runAcpMcpStdioBridge } from "./AcpMcpStdioBridge.ts";
11
12 -function makeHarness(responder: (request: Request) => Promise<Response> | Response) {
13 - const input = new NodeStream.PassThrough();
12 +function makeHarness(
13 + responder: (request: Request) => Promise<Response> | Response,
14 + input = new NodeStream.PassThrough(),
15 +) {
16 const written: Array<string> = [];
17 const requests: Array<{ readonly headers: Headers; readonly body: string }> = [];
18 const bridge = runAcpMcpStdioBridge({
@@ -163,6 +165,36 @@ describe("AcpMcpStdioBridge", () => {
165 }),
166 );
167
168 + it.effect("keeps U+2028 and U+2029 inside a message instead of splitting it", () =>
169 + Effect.gen(function* () {
170 + const { input, written, requests, bridge } = makeHarness(
171 + () => Response.json({ jsonrpc: "2.0", id: 4, result: { ok: true } }),
172 + // Object mode keeps the two writes as separate chunks instead of one buffered read.
173 + new NodeStream.PassThrough({ objectMode: true }),
174 + );
175 + const fiber = yield* Effect.forkChild(bridge);
176 + // JSON.stringify leaves both separators unescaped, as MCP stdio clients send them.
177 + const message = JSON.stringify({
178 + jsonrpc: "2.0",
179 + id: 4,
180 + method: "tools/call",
181 + params: { name: "echo", arguments: { text: "a\u2028b\u2029c\u{1f30d}" } },
182 + });
183 +
184 + // Split inside the emoji's UTF-8 bytes and leave the last line unterminated, as stdin may.
185 + const bytes = Buffer.from(message);
186 + const split = bytes.indexOf(Buffer.from("\u{1f30d}")) + 2;
187 + input.write(bytes.subarray(0, split));
188 + input.end(bytes.subarray(split));
189 + yield* Fiber.join(fiber);
190 +
191 + expect(requests.map((request) => request.body)).toEqual([message]);
192 + expect(written.map((chunk) => JSON.parse(chunk))).toEqual([
193 + { jsonrpc: "2.0", id: 4, result: { ok: true } },
194 + ]);
195 + }),
196 + );
197 +
198 it.effect("forwards SSE messages before the HTTP response closes", () =>
199 Effect.gen(function* () {
200 let resolveResponseController!: (
apps/server/src/mcp/AcpMcpStdioBridge.ts
+7 -5
@@ -1,7 +1,5 @@
1 // Relay JSON-RPC verbatim; schema decoding would reject foreign payloads.
2 -// @effect-diagnostics nodeBuiltinImport:off globalJsonInEffect:off
3 -import * as NodeReadline from "node:readline";
4 -
2 +// @effect-diagnostics globalJsonInEffect:off
3 import * as Cause from "effect/Cause";
4 import * as Effect from "effect/Effect";
5 import * as Option from "effect/Option";
@@ -320,8 +318,12 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
318 return yield* launch(task);
319 });
320
323 - const reader = NodeReadline.createInterface({ input: options.input });
324 - yield* Stream.runForEach(Stream.fromAsyncIterable(reader, bridgeError), dispatch).pipe(
321 + // node:readline also splits on U+2028/U+2029, which JSON.stringify leaves raw inside strings.
322 + yield* Stream.fromAsyncIterable(options.input, bridgeError).pipe(
323 + Stream.map((chunk) => (typeof chunk === "string" ? Buffer.from(chunk) : chunk)),
324 + Stream.decodeText(),
325 + Stream.splitLines,
326 + Stream.runForEach(dispatch),
327 Effect.ignoreCause,
328 );
329 yield* Fiber.awaitAll(running);