@devries-cameron20 / t3code Mirror · read-only / commits / e64a6d4ca8
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, 19:30 UTC

fix(server): abort interrupted ACP MCP fetches (#23955)

Co-authored-by: kiiwee <6160452+kiiwee@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Julius Marminge committed Oct 22, 2026 at 23:44 UTC e64a6d4ca84e8f7adab8066173d432e76ebf1996
2 files changed +52 -3
apps/server/src/mcp/AcpMcpStdioBridge.test.ts
+48 -1
@@ -2,10 +2,11 @@
2 import * as NodeStream from "node:stream";
3
4 import { describe, expect, it } from "@effect/vitest";
5 +import * as Deferred from "effect/Deferred";
6 import * as Effect from "effect/Effect";
7 import * as Fiber from "effect/Fiber";
8
8 -import { runAcpMcpStdioBridge } from "./AcpMcpStdioBridge.ts";
9 +import { mcpToolSession, runAcpMcpStdioBridge } from "./AcpMcpStdioBridge.ts";
10
11 function makeHarness(responder: (request: Request) => Promise<Response> | Response) {
12 const input = new NodeStream.PassThrough();
@@ -29,6 +30,13 @@ function makeHarness(responder: (request: Request) => Promise<Response> | Respon
30 return { input, written, requests, bridge };
31 }
32
33 +function pendingFetch(started: Deferred.Deferred<AbortSignal | undefined>) {
34 + return (_url: string, init?: RequestInit): Promise<Response> => {
35 + Deferred.doneUnsafe(started, Effect.succeed(init?.signal ?? undefined));
36 + return new Promise(() => {});
37 + };
38 +}
39 +
40 describe("AcpMcpStdioBridge", () => {
41 it.effect("forwards requests and replays the session id and protocol version", () =>
42 Effect.gen(function* () {
@@ -282,4 +290,43 @@ describe("AcpMcpStdioBridge", () => {
290 expect(JSON.parse(written[0]!)).toMatchObject({ id: 7, result: {} });
291 }),
292 );
293 +
294 + it.effect("aborts the pending fetch when a tool call is interrupted", () =>
295 + Effect.gen(function* () {
296 + const started = yield* Deferred.make<AbortSignal | undefined>();
297 + const fiber = yield* mcpToolSession({
298 + endpoint: "http://127.0.0.1:1/mcp",
299 + authorization: "Bearer bridge-test",
300 + clientName: "t3-code-acp-cli",
301 + fetchImplementation: pendingFetch(started),
302 + }).pipe(
303 + Effect.flatMap((session) => session.call("orchestrator_capabilities", {})),
304 + Effect.scoped,
305 + Effect.forkChild,
306 + );
307 +
308 + const signal = yield* Deferred.await(started);
309 + yield* Fiber.interrupt(fiber);
310 + expect(signal?.aborted).toBe(true);
311 + }),
312 + );
313 +
314 + it.effect("aborts the pending fetch when the stdio bridge is interrupted", () =>
315 + Effect.gen(function* () {
316 + const started = yield* Deferred.make<AbortSignal | undefined>();
317 + const input = new NodeStream.PassThrough();
318 + const fiber = yield* runAcpMcpStdioBridge({
319 + endpoint: "http://127.0.0.1:1/mcp",
320 + authorization: "Bearer bridge-test",
321 + input,
322 + output: { write: () => undefined },
323 + fetchImplementation: pendingFetch(started),
324 + }).pipe(Effect.forkChild);
325 +
326 + input.write(`${JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })}\n`);
327 + const signal = yield* Deferred.await(started);
328 + yield* Fiber.interrupt(fiber);
329 + expect(signal?.aborted).toBe(true);
330 + }),
331 + );
332 });
apps/server/src/mcp/AcpMcpStdioBridge.ts
+4 -2
@@ -92,11 +92,12 @@ export const mcpToolSession = (
92 message: unknown,
93 ): Effect.fn.Return<ReadonlyArray<unknown>, AcpMcpBridgeError> {
94 const response = yield* Effect.tryPromise({
95 - try: () =>
95 + try: (signal) =>
96 fetchImplementation(options.endpoint, {
97 method: "POST",
98 headers: { "content-type": "application/json", ...headers() },
99 body: JSON.stringify(message),
100 + signal,
101 }),
102 catch: bridgeError,
103 });
@@ -212,7 +213,7 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
213 )(
214 function* (line: string, envelope: JsonRpcEnvelope) {
215 const response = yield* Effect.tryPromise({
215 - try: () =>
216 + try: (signal) =>
217 fetchImplementation(options.endpoint, {
218 method: "POST",
219 headers: {
@@ -223,6 +224,7 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
224 ...(protocolVersion === null ? {} : { "mcp-protocol-version": protocolVersion }),
225 },
226 body: line,
227 + signal,
228 }),
229 catch: bridgeError,
230 });