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 21, 12:15 UTC
fix(mcp): explain cross-thread permission rejections (#36934)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Rishabh Bothra committed
Nov 15, 2026 at 10:13 UTC
2e9418af79a8803c558e2fbef9c23bbc4fe37d30
3 files changed
+33
-7
apps/server/src/mcp/OrchestratorMcpService.ts
+3
-5
@@ -132,7 +132,7 @@ import {
132
runtimeModeRank,
133
taskPrompt,
134
} from "./delegatedTaskModes.ts";
135
-import { isLiveCallerShell, threadNotFound } from "./threadAccess.ts";
135
+import { assertTargetWithinLimits, isLiveCallerShell, threadNotFound } from "./threadAccess.ts";
136
import * as SecretRequests from "../secrets/SecretRequests.ts";
137
import * as PeerForwarding from "../peer/PeerForwarding.ts";
138
import * as RemoteDelegation from "../peer/RemoteDelegation.ts";
@@ -3362,8 +3362,7 @@ const make = Effect.gen(function* () {
3362
sendToThread: Effect.fn("OrchestratorMcpService.sendToThread")(function* (scope, input) {
3363
const { parent, limits, target } = yield* loadScopedThread(scope, input.threadId, ["runs"]);
3364
yield* assertLiveCallerForOtherThread(scope, parent, target);
3365
- yield* resolveRuntimeMode(limits.runtimeMode, target.thread.runtimeMode);
3366
- yield* resolveInteractionMode(limits.interactionMode, target.thread.interactionMode);
3365
+ yield* assertTargetWithinLimits(limits, target.thread);
3366
3367
const mode = input.mode ?? "auto";
3368
const key = yield* requestKey(input.clientRequestId);
@@ -3467,8 +3466,7 @@ const make = Effect.gen(function* () {
3466
interruptThread: Effect.fn("OrchestratorMcpService.interruptThread")(function* (scope, input) {
3467
const { parent, limits, target } = yield* loadScopedThread(scope, input.threadId, ["runs"]);
3468
yield* assertLiveCallerForOtherThread(scope, parent, target);
3470
- yield* resolveRuntimeMode(limits.runtimeMode, target.thread.runtimeMode);
3471
- yield* resolveInteractionMode(limits.interactionMode, target.thread.interactionMode);
3469
+ yield* assertTargetWithinLimits(limits, target.thread);
3470
const key = yield* requestKey(input.clientRequestId);
3471
// A peer from before `stop` drops it when decoding, so it interrupts
3472
// the run instead, as this call did then.
apps/server/src/mcp/threadAccess.test.ts
+22
-1
@@ -11,7 +11,7 @@ import * as Layer from "effect/Layer";
11
import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
12
import * as McpInvocationContext from "./McpInvocationContext.ts";
13
import { liveThreadShell } from "./McpToolAccess.testkit.ts";
14
-import { readThread } from "./threadAccess.ts";
14
+import { assertTargetWithinLimits, readThread } from "./threadAccess.ts";
15
16
const bareId = ThreadId.make("5d0b4a3e-8c1f-4a52-9d37-2f6c7e1b9a04");
17
const claudeCode: McpInvocationContext.McpClientCaller = {
@@ -117,3 +117,24 @@ it.effect("points an unencoded delegated-task id at the encoded thread it belong
117
expect(error.message).toContain(`\`${encoded}\``);
118
}),
119
);
120
+
121
+it.effect("identifies the target and effective caller ceiling when a thread write is refused", () =>
122
+ Effect.gen(function* () {
123
+ for (const [runtimeMode, interactionMode, code] of [
124
+ ["approval-required", "default", "runtime_mode_escalation_denied"],
125
+ ["full-access", "plan", "interaction_mode_escalation_denied"],
126
+ ["approval-required", "plan", "runtime_mode_escalation_denied"],
127
+ ] as const) {
128
+ const target = liveThreadShell(bareId, { runtimeMode: "full-access" });
129
+ const error = yield* assertTargetWithinLimits({ runtimeMode, interactionMode }, target).pipe(
130
+ Effect.flip,
131
+ );
132
+
133
+ expect(error.code).toBe(code);
134
+ expect(error.message).toContain(bareId);
135
+ expect(error.message).toContain("full-access/default");
136
+ expect(error.message).toContain(`${runtimeMode}/${interactionMode}`);
137
+ expect(error.message).not.toMatch(/child|parent mode/i);
138
+ }
139
+ }),
140
+);
apps/server/src/mcp/threadAccess.ts
+8
-1
@@ -144,11 +144,18 @@ export const loadCaller = Effect.fn("mcp.loadCaller")(function* () {
144
145
export const assertTargetWithinLimits = (
146
limits: CallerLimits,
147
- target: { readonly runtimeMode: RuntimeMode; readonly interactionMode: ProviderInteractionMode },
147
+ target: Pick<OrchestrationV2ThreadShell, "id" | "runtimeMode" | "interactionMode">,
148
) =>
149
resolveRuntimeMode(limits.runtimeMode, target.runtimeMode).pipe(
150
Effect.andThen(resolveInteractionMode(limits.interactionMode, target.interactionMode)),
151
Effect.asVoid,
152
+ Effect.mapError(
153
+ (error) =>
154
+ new OrchestratorMcpFailure({
155
+ code: error.code,
156
+ message: `Thread "${target.id}" runs in ${target.runtimeMode}/${target.interactionMode}, above this caller's ${limits.runtimeMode}/${limits.interactionMode} limit. For linked calls, this limit is also capped by the link's approved access. This call does not create an approval request. Have the user act directly in the target thread through an authorized client.`,
157
+ }),
158
+ ),
159
);
160
161
/** Background subagents retain credentials until provider exit; archived threads and other instances cannot act. */