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, 09:30 UTC
perf(acp): MCP calls over ACP no longer wait behind a long call (#23834)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 31, 2026 at 03:42 UTC
f1e2e5d65d4d7eddc52187da97846b1ac5d3ef11
2 files changed
+72
-8
packages/provider-acp/src/server/mcpOverAcpBridge.test.ts
+64
-7
@@ -7,6 +7,9 @@ import { makeAcpMcpOverAcpBridge } from "./mcpOverAcpBridge.ts";
7
describe("AcpMcpOverAcpBridge", () => {
8
it.effect("forwards authenticated MCP requests and closes the negotiated session", () =>
9
Effect.gen(function* () {
10
+ const initializeStarted = Promise.withResolvers<void>();
11
+ const initializeResponse = Promise.withResolvers<void>();
12
+ const listQueued = Promise.withResolvers<void>();
13
const requests: Array<{
14
readonly method: string;
15
readonly headers: Headers;
@@ -24,6 +27,10 @@ describe("AcpMcpOverAcpBridge", () => {
27
if (method === "DELETE") return new Response(null, { status: 204 });
28
if (body === null || typeof body !== "object") return new Response(null, { status: 202 });
29
const request = body as { readonly id?: unknown; readonly method?: unknown };
30
+ if (request.method === "initialize") {
31
+ initializeStarted.resolve();
32
+ await initializeResponse.promise;
33
+ }
34
if (request.method === "notifications/initialized") {
35
return new Response(null, { status: 202 });
36
}
@@ -45,12 +52,21 @@ describe("AcpMcpOverAcpBridge", () => {
52
53
const connected = yield* bridge.connect({ serverId: "t3-code" });
54
expect(connected).toEqual({ connectionId: "connection-1" });
48
- expect(
49
- yield* bridge.message({ connectionId: connected.connectionId, method: "initialize" }),
50
- ).toMatchObject({ protocolVersion: "2025-06-18" });
51
- expect(
52
- yield* bridge.message({ connectionId: connected.connectionId, method: "tools/list" }),
53
- ).toEqual({ tools: [] });
55
+ const initialize = yield* bridge
56
+ .message({ connectionId: connected.connectionId, method: "initialize" })
57
+ .pipe(Effect.forkChild);
58
+ yield* Effect.promise(() => initializeStarted.promise);
59
+ const list = yield* Effect.gen(function* () {
60
+ listQueued.resolve();
61
+ return yield* bridge.message({
62
+ connectionId: connected.connectionId,
63
+ method: "tools/list",
64
+ });
65
+ }).pipe(Effect.forkChild);
66
+ yield* Effect.promise(() => listQueued.promise);
67
+ initializeResponse.resolve();
68
+ expect(yield* Fiber.join(initialize)).toMatchObject({ protocolVersion: "2025-06-18" });
69
+ expect(yield* Fiber.join(list)).toEqual({ tools: [] });
70
yield* bridge.notification({
71
connectionId: connected.connectionId,
72
method: "notifications/initialized",
@@ -62,7 +78,7 @@ describe("AcpMcpOverAcpBridge", () => {
78
expect(requests[1]?.headers.get("mcp-protocol-version")).toBe("2025-06-18");
79
expect(requests.at(-1)?.method).toBe("DELETE");
80
expect(requests.at(-1)?.headers.get("mcp-session-id")).toBe("session-42");
65
- }),
81
+ }).pipe(Effect.scoped),
82
);
83
84
it.effect("aborts an in-flight HTTP request when the ACP call is interrupted", () =>
@@ -88,6 +104,47 @@ describe("AcpMcpOverAcpBridge", () => {
104
}).pipe(Effect.scoped),
105
);
106
107
+ it.effect("answers a call while a long call on the same connection is pending", () =>
108
+ Effect.gen(function* () {
109
+ const waitStarted = Promise.withResolvers<void>();
110
+ const waitResponse = Promise.withResolvers<Response>();
111
+ const reply = (id: unknown, result: unknown) =>
112
+ new Response(JSON.stringify({ jsonrpc: "2.0", id, result }), {
113
+ headers: { "content-type": "application/json", "mcp-session-id": "session-42" },
114
+ });
115
+ const bridge = yield* makeAcpMcpOverAcpBridge({
116
+ endpoint: "http://127.0.0.1:1/mcp",
117
+ authorization: "Bearer bridge-test",
118
+ allocateConnectionId: Effect.succeed("connection-1"),
119
+ fetchImplementation: (_url, init) => {
120
+ const request = JSON.parse(String(init?.body)) as {
121
+ readonly id?: unknown;
122
+ readonly method?: unknown;
123
+ };
124
+ if (request.method === "initialize") {
125
+ return Promise.resolve(reply(request.id, { protocolVersion: "2025-06-18" }));
126
+ }
127
+ if (request.method === "tools/call") {
128
+ waitStarted.resolve();
129
+ return waitResponse.promise;
130
+ }
131
+ return Promise.resolve(reply(request.id, { tools: [] }));
132
+ },
133
+ });
134
+ const { connectionId } = yield* bridge.connect({ serverId: "t3-code" });
135
+ yield* bridge.message({ connectionId, method: "initialize" });
136
+
137
+ const wait = yield* bridge
138
+ .message({ connectionId, method: "tools/call", params: { name: "t3_thread_wait" } })
139
+ .pipe(Effect.forkChild);
140
+ yield* Effect.promise(() => waitStarted.promise);
141
+ expect(yield* bridge.message({ connectionId, method: "tools/list" })).toEqual({ tools: [] });
142
+
143
+ waitResponse.resolve(reply(2, { content: [] }));
144
+ expect(yield* Fiber.join(wait)).toEqual({ content: [] });
145
+ }).pipe(Effect.scoped),
146
+ );
147
+
148
it.effect("rejects unknown servers, connections, and oversized messages", () =>
149
Effect.gen(function* () {
150
const bridge = yield* makeAcpMcpOverAcpBridge({
packages/provider-acp/src/server/mcpOverAcpBridge.ts
+8
-1
@@ -92,11 +92,18 @@ export const makeAcpMcpOverAcpBridge = Effect.fn("AcpMcpOverAcpBridge.make")(fun
92
: Effect.succeed(connection);
93
});
94
95
+ // Only initialization needs ordering; negotiated calls may wait independently.
96
+ const untilNegotiated = <A, E>(connection: Connection, effect: Effect.Effect<A, E>) =>
97
+ Effect.suspend(() =>
98
+ connection.protocolVersion === null ? connection.mutex.withPermits(1)(effect) : effect,
99
+ );
100
+
101
const send = (
102
connection: Connection,
103
message: unknown,
104
): Effect.Effect<ReadonlyArray<unknown>, AcpMcpOverAcpError> =>
99
- connection.mutex.withPermits(1)(
105
+ untilNegotiated(
106
+ connection,
107
Effect.gen(function* () {
108
const body = JSON.stringify(message);
109
if (Buffer.byteLength(body) > MAX_MESSAGE_BYTES) {