@devries-cameron20 / t3code-1 / commits / 45b0fe4a8e
Fork 0

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

fix(server): ACP terminal MCP calls answer interleaved server requests (#35805)

Julius Marminge committed Nov 12, 2026 at 18:38 UTC 45b0fe4a8e652c8a8889cb61067a31632c6d2f40
2 files changed +50 -3
apps/server/src/mcp/AcpMcpStdioBridge.test.ts
+35
@@ -392,6 +392,41 @@ describe("AcpMcpStdioBridge", () => {
392 }),
393 );
394
395 + it.effect("answers a server ping that arrives before the tool result on its SSE stream", () =>
396 + Effect.gen(function* () {
397 + const sent: Array<{ id?: unknown; method?: string; result?: unknown }> = [];
398 + const result = yield* mcpToolSession({
399 + endpoint: "http://127.0.0.1:1/mcp",
400 + authorization: "Bearer bridge-test",
401 + clientName: "t3-code-acp-cli",
402 + fetchImplementation: async (_url, init) => {
403 + if (init?.method === "DELETE") return new Response(null, { status: 204 });
404 + const message = JSON.parse(String(init?.body)) as (typeof sent)[number];
405 + sent.push(message);
406 + if (message.method === "initialize") {
407 + return Response.json(
408 + { jsonrpc: "2.0", id: message.id, result: { protocolVersion: "2025-06-18" } },
409 + { headers: { "mcp-session-id": "session-42" } },
410 + );
411 + }
412 + if (message.method !== "tools/call") return new Response(null, { status: 202 });
413 + const ping = { jsonrpc: "2.0", id: "server-ping", method: "ping" };
414 + const reply = { jsonrpc: "2.0", id: message.id, result: { content: [] } };
415 + return new Response(
416 + `data: ${JSON.stringify(ping)}\n\ndata: ${JSON.stringify(reply)}\n\n`,
417 + { headers: { "content-type": "text/event-stream" } },
418 + );
419 + },
420 + }).pipe(
421 + Effect.flatMap((session) => session.call("orchestrator_capabilities", {})),
422 + Effect.scoped,
423 + );
424 +
425 + expect(result).toEqual({ content: [] });
426 + expect(sent).toContainEqual({ jsonrpc: "2.0", id: "server-ping", result: {} });
427 + }),
428 + );
429 +
430 it.effect("aborts the pending fetch when the stdio bridge is interrupted", () =>
431 Effect.gen(function* () {
432 const started = yield* Deferred.make<AbortSignal | undefined>();
apps/server/src/mcp/AcpMcpStdioBridge.ts
+15 -3
@@ -58,6 +58,12 @@ function protocolVersionOf(entry: unknown): string | null {
58 return typeof version === "string" && version.length > 0 ? version : null;
59 }
60
61 +function replyToServerRequest(envelope: JsonRpcEnvelope): unknown {
62 + return envelope.method === "ping"
63 + ? { jsonrpc: "2.0", id: envelope.id, result: {} }
64 + : { jsonrpc: "2.0", id: envelope.id, error: { code: -32601, message: "Method not found" } };
65 +}
66 +
67 export interface McpToolSessionOptions {
68 readonly endpoint: string;
69 readonly authorization: string;
@@ -112,10 +118,16 @@ export const mcpToolSession = (
118 message: `T3 Code MCP endpoint responded with HTTP ${response.status}.`,
119 });
120 }
115 - const payloads = yield* Stream.runCollect(responsePayloads(response, bridgeError));
116 - for (const payload of payloads) {
121 + const payloads: Array<unknown> = [];
122 + yield* Stream.runForEach(responsePayloads(response, bridgeError), (payload) => {
123 protocolVersion = protocolVersionOf(payload) ?? protocolVersion;
118 - }
124 + const envelope = asEnvelope(payload);
125 + if (envelope?.id !== undefined && typeof envelope.method === "string") {
126 + return send(replyToServerRequest(envelope)).pipe(Effect.asVoid);
127 + }
128 + payloads.push(payload);
129 + return Effect.void;
130 + });
131 return payloads;
132 });
133