# Files changed · PR \#23834 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/23834/diffs)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

[perf\(acp\): MCP calls over ACP no longer wait behind a long call](https://git.cafe/pingdotgg/t3code/pull/23834.md)

Version: 2

Head commit: 1a42091e68cca5b763228d83448cdcbf1b75e49b

Base commit: d7f3b72548a205de52c851a540471607f56ec889

Comparison base: 05696c636ec2a101a763505d820b83891e529ccd

Showing up to 20 entries from this revision. If the pull request changes, reopen the first page before continuing.

## packages/provider-acp/src/server/mcpOverAcpBridge.test.ts

Status: modified; +41; −0

```diff
@@ -88,6 +88,47 @@
     }).pipe(Effect.scoped),
   );
 
+  it.effect("answers a call while a long call on the same connection is pending", () =>
+    Effect.gen(function* () {
+      const waitStarted = Promise.withResolvers<void>();
+      const waitResponse = Promise.withResolvers<Response>();
+      const reply = (id: unknown, result: unknown) =>
+        new Response(JSON.stringify({ jsonrpc: "2.0", id, result }), {
+          headers: { "content-type": "application/json", "mcp-session-id": "session-42" },
+        });
+      const bridge = yield* makeAcpMcpOverAcpBridge({
+        endpoint: "http://127.0.0.1:1/mcp",
+        authorization: "Bearer bridge-test",
+        allocateConnectionId: Effect.succeed("connection-1"),
+        fetchImplementation: (_url, init) => {
+          const request = JSON.parse(String(init?.body)) as {
+            readonly id?: unknown;
+            readonly method?: unknown;
+          };
+          if (request.method === "initialize") {
+            return Promise.resolve(reply(request.id, { protocolVersion: "2025-06-18" }));
+          }
+          if (request.method === "tools/call") {
+            waitStarted.resolve();
+            return waitResponse.promise;
+          }
+          return Promise.resolve(reply(request.id, { tools: [] }));
+        },
+      });
+      const { connectionId } = yield* bridge.connect({ serverId: "t3-code" });
+      yield* bridge.message({ connectionId, method: "initialize" });
+
+      const wait = yield* bridge
+        .message({ connectionId, method: "tools/call", params: { name: "t3_thread_wait" } })
+        .pipe(Effect.forkChild);
+      yield* Effect.promise(() => waitStarted.promise);
+      expect(yield* bridge.message({ connectionId, method: "tools/list" })).toEqual({ tools: [] });
+
+      waitResponse.resolve(reply(2, { content: [] }));
+      expect(yield* Fiber.join(wait)).toEqual({ content: [] });
+    }).pipe(Effect.scoped),
+  );
+
   it.effect("rejects unknown servers, connections, and oversized messages", () =>
     Effect.gen(function* () {
       const bridge = yield* makeAcpMcpOverAcpBridge({
```

## packages/provider-acp/src/server/mcpOverAcpBridge.ts

Status: modified; +10; −1

```diff
@@ -92,11 +92,20 @@
         : Effect.succeed(connection);
     });
 
+  // Messages wait for the initialize handshake, then run concurrently so a short
+  // call does not queue behind a long one such as t3_thread_wait.
+  const untilNegotiated =
+    (connection: Connection) =>
+    <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> =>
+      Effect.suspend(() =>
+        connection.protocolVersion === null ? connection.mutex.withPermits(1)(effect) : effect,
+      );
+
   const send = (
     connection: Connection,
     message: unknown,
   ): Effect.Effect<ReadonlyArray<unknown>, AcpMcpOverAcpError> =>
-    connection.mutex.withPermits(1)(
+    untilNegotiated(connection)(
       Effect.gen(function* () {
         const body = JSON.stringify(message);
         if (Buffer.byteLength(body) > MAX_MESSAGE_BYTES) {
```
