@devries-cameron20 / t3code Mirror · read-only / commits / 4c361199f4
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, 00:45 UTC

fix(server): Claude threads can allow an MCP app for the session (#33707)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Nov 9, 2026 at 22:47 UTC 4c361199f47f6ea32a2c14835df392640d0f7c63
2 files changed +52 -13
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+37 -10
@@ -9,6 +9,7 @@ import { beforeEach, vi } from "vite-plus/test";
9
10 import type {
11 ElicitationRequest,
12 + ElicitationResult,
13 Query as ClaudeQuery,
14 SDKMessage,
15 SDKResultMessage,
@@ -5703,6 +5704,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5704 options: [
5705 { decision: "cancel", label: "Cancel" },
5706 { decision: "decline", label: "Decline" },
5707 + { decision: "acceptForSession", label: "Always allow this session" },
5708 { decision: "accept", label: "Approve" },
5709 ],
5710 });
@@ -5732,16 +5734,41 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5734 }).pipe(Effect.scoped, Effect.provide(testLayer)),
5735 );
5736
5735 - it.effect.each(["acceptForSession", "acceptAlways"] as const)(
5736 - "declines an unsupported %s decision",
5737 - (decision) =>
5738 - Effect.gen(function* () {
5739 - const { harness, elicit, awaitCard } = yield* startElicitationTurn();
5740 - const answer = yield* elicit(approvalOnly);
5741 - const request = yield* awaitCard(1);
5742 - yield* harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision });
5743 - assert.deepEqual(yield* Fiber.join(answer), { action: "decline" });
5744 - }).pipe(Effect.scoped, Effect.provide(testLayer)),
5737 + it.effect("declines an unsupported acceptAlways decision", () =>
5738 + Effect.gen(function* () {
5739 + const { harness, elicit, awaitCard } = yield* startElicitationTurn();
5740 + const answer = yield* elicit(approvalOnly);
5741 + const request = yield* awaitCard(1);
5742 + yield* harness.runtime.respondToRuntimeRequest({
5743 + requestId: request.id,
5744 + decision: "acceptAlways",
5745 + });
5746 + assert.deepEqual(yield* Fiber.join(answer), { action: "decline" });
5747 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
5748 + );
5749 +
5750 + it.effect("answers a repeated prompt from a session grant without a card", () =>
5751 + Effect.gen(function* () {
5752 + const { harness, elicit, awaitCard, runtimeRequests } = yield* startElicitationTurn();
5753 + const first = yield* elicit(approvalOnly);
5754 + const request = yield* awaitCard(1);
5755 + yield* harness.runtime.respondToRuntimeRequest({
5756 + requestId: request.id,
5757 + decision: "acceptForSession",
5758 + });
5759 + const granted = { action: "accept", content: {} } satisfies ElicitationResult;
5760 + assert.deepEqual(yield* Fiber.join(first), granted);
5761 +
5762 + assert.deepEqual(yield* Fiber.join(yield* elicit(approvalOnly)), granted);
5763 + assert.equal(runtimeRequests().length, 1);
5764 +
5765 + const otherMessage = yield* elicit({ ...approvalOnly, message: "Deploy api?" });
5766 + yield* awaitCard(2);
5767 + const otherServer = yield* elicit({ ...approvalOnly, serverName: "builds" });
5768 + yield* awaitCard(3);
5769 + assert.isUndefined(otherMessage.pollUnsafe());
5770 + assert.isUndefined(otherServer.pollUnsafe());
5771 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
5772 );
5773
5774 it.effect("declines URL and value forms without a card", () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+15 -3
@@ -3825,11 +3825,12 @@ export const awaitClaudeApprovalDecision = Effect.fn("awaitClaudeApprovalDecisio
3825 return yield* Effect.raceFirst(Deferred.await(decision), cancellation);
3826 });
3827
3828 -// Web and mobile offer a session grant when options are omitted, and this
3829 -// path only ever answers once.
3828 +// MCP servers such as Computer Use ask on every call and expect the client to
3829 +// remember a session grant, as Codex does. The CLI drops a reply's `_meta.persist`.
3830 const CLAUDE_MCP_ELICITATION_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
3831 { decision: "cancel", label: "Cancel" },
3832 { decision: "decline", label: "Decline" },
3833 + { decision: "acceptForSession", label: "Always allow this session" },
3834 { decision: "accept", label: "Approve" },
3835 ];
3836
@@ -5212,6 +5213,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
5213 const pendingRuntimeRequests = yield* Ref.make(
5214 new Map<string, PendingClaudeRuntimeRequest>(),
5215 );
5216 + const mcpElicitationSessionGrants = yield* Ref.make(new Set<string>());
5217 // Background local_bash tasks can trigger wake turns on the query stream with no active provider turn.
5218 const lastTurnRouteByNativeThread = yield* Ref.make(
5219 new Map<
@@ -10620,6 +10622,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10622 );
10623 return { action: "decline" } satisfies ElicitationResult;
10624 }
10625 + const grantKey = `${request.serverName}\u0000${request.message}`;
10626 + if ((yield* Ref.get(mcpElicitationSessionGrants)).has(grantKey)) {
10627 + return acceptance;
10628 + }
10629 // The CLI waits on this answer, so a turn held for its prompt echo
10630 // must show its output now, as canUseTool does.
10631 if (context.heldRootFrames.length > 0) {
@@ -10706,8 +10712,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10712 runtimeRequest: { ...artifacts.request, status: "cancelled", resolvedAt: now },
10713 });
10714 }
10715 + if (resolved === "acceptForSession") {
10716 + yield* Ref.update(mcpElicitationSessionGrants, (current) =>
10717 + new Set(current).add(grantKey),
10718 + );
10719 + return acceptance;
10720 + }
10721 // Never null: the SDK reads null as answered out of band and leaves
10710 - // the server waiting. Every accept is one-time; no grant is offered.
10722 + // the server waiting.
10723 return resolved === "accept"
10724 ? acceptance
10725 : ({