From e8ebc8b7b36feffc93b4046c7fa7456f558b80b3 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 07:01:09 +0000 Subject: [PATCH 1/4] fix(server): Claude MCP app calls no longer prompt or fail on rules for other tools Any `mcp__` ask or deny rule in Claude's settings made every MCP app tool look covered: read-only tools lost their read-only hint, so each card call opened a confirmation, and with a deny rule the call was then refused anyway. In Full Access, on a CLI that advertises `mcp_call_check_permissions_v1`, card calls now go through Claude's own permission check, which matches rules exactly. A read-only tool keeps its hint unless an ask rule names it. When Claude asks about a call, T3's prompt is the answer: a call the user confirmed is allowed, and one nobody was asked about is refused and prompted from then on. Older CLIs and other modes keep the broad guard. Co-authored-by: Sidreyas Co-Authored-By: Claude Fable 5.2 --- .../Adapters/ClaudeAdapterV2.test.ts | 129 +++++++++--- .../Adapters/ClaudeAdapterV2.ts | 184 +++++++++++++++--- 2 files changed, 257 insertions(+), 56 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index e1665b1bafb3e..d033f9feeeb2d 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -6736,11 +6736,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { overrides?: Partial< Pick< ClaudeAdapterV2.ClaudeAgentSdkQuerySession, - "mcpServerStatus" | "readMcpResource" | "listPermissionRules" + "mcpServerStatus" | "readMcpResource" | "callMcpTool" | "listPermissionRules" > >, toolName = "mcp__probe_server__show_weather", toolUseResult: unknown = { content: '{"tempC":21}', structuredContent: { tempC: 21 } }, + runtimePolicy = CLAUDE_TEST_RUNTIME_POLICY, ) { const mcpRequests: Array = []; const harness = yield* makeWakeHarnessWithOptions({ @@ -6778,6 +6779,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { attemptId: RunAttemptId.make("mcp-app"), text: "Show the weather", attachments: [], + runtimePolicy, }), ); const id = "weather-app-call"; @@ -7094,28 +7096,102 @@ describe("ClaudeAdapterV2 background wake turns", () => { called: false, readOnly: false, }, + { + case: "Claude's own check and rules for other tools", + rules: [ + { behavior: "ask", rule: "mcp__atlassian__createJiraIssue" }, + { behavior: "deny", rule: "mcp__buildkite__create_build" }, + { behavior: "deny", rule: "mcp__probe_server__delete_*" }, + ], + checks: "full-access", + called: true, + readOnly: true, + }, + { + case: "Claude's own check and an ask rule naming the tool", + rules: [{ behavior: "ask", rule: "mcp__probe_server__refresh_*" }], + checks: "full-access", + claudeAsks: true, + called: true, + readOnly: false, + }, + { + case: "Claude's own check and an ask rule for a server alias T3 can't list", + rules: [{ behavior: "ask", rule: "mcp__probe_alias" }], + checks: "full-access", + claudeAsks: true, + called: false, + readOnly: true, + }, + { + case: "Claude's own check and permission rules that cannot be read", + rules: "unreadable", + checks: "full-access", + called: true, + readOnly: true, + }, + { + case: "Claude's own check outside Full Access", + rules: [{ behavior: "deny", rule: "mcp__buildkite__create_build" }], + checks: "approval-required", + called: false, + readOnly: false, + }, ] as const)("applies Claude's permission rules to MCP app calls with $case", (testCase) => Effect.gen(function* () { const server = "server" in testCase ? testCase.server : PROBE_SERVER_STATUS.name; const tool = "tool" in testCase ? testCase.tool : "refresh_weather"; - const { harness, mcpRequests } = yield* runClaudeMcpAppToolTurn(MCP_APP_CAPABILITIES, { - mcpServerStatus: Effect.succeed([ - { - ...PROBE_SERVER_STATUS, - name: server, - tools: [{ ...PROBE_SERVER_STATUS.tools[1], name: tool }], - }, - ]), - listPermissionRules: - testCase.rules === "unreadable" - ? Effect.fail( - new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({ - method: "listPermissionRules", - cause: new Error("Unsupported control request subtype"), + const calls: Array<{ readonly checkPermissions?: boolean }> = []; + const opened: { canUseTool?: ClaudeSdk.CanUseTool | undefined } = {}; + const { harness } = yield* runClaudeMcpAppToolTurn( + "checks" in testCase + ? [...MCP_APP_CAPABILITIES, "mcp_call_check_permissions_v1"] + : MCP_APP_CAPABILITIES, + { + mcpServerStatus: Effect.succeed([ + { + ...PROBE_SERVER_STATUS, + name: server, + tools: [{ ...PROBE_SERVER_STATUS.tools[1], name: tool }], + }, + ]), + listPermissionRules: + testCase.rules === "unreadable" + ? Effect.fail( + new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({ + method: "listPermissionRules", + cause: new Error("Unsupported control request subtype"), + }), + ) + : Effect.succeed(testCase.rules), + // Shape recorded from Claude Code 2.1.330: a checked call's ask goes to canUseTool, and a refusal fails the call. + callMcpTool: Effect.fnUntraced(function* (call) { + if ("claudeAsks" in testCase && call.checkPermissions === true) { + const answer = yield* Effect.promise(() => + opened.canUseTool!(call.tool, call.arguments, { + signal: new AbortController().signal, + toolUseID: "toolu_mcp_call_a53e26e8c8a9483c8466271c506fcdcb", + requestId: "request-mcp-call", }), - ) - : Effect.succeed(testCase.rules), - }); + ); + if (answer?.behavior !== "allow") { + return yield* new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({ + method: "callMcpTool", + cause: new Error("The tool did not run"), + }); + } + } + calls.push(call); + return { content: [{ type: "text", text: "refreshed" }] }; + }), + }, + undefined, + undefined, + "checks" in testCase + ? { ...CLAUDE_TEST_RUNTIME_POLICY, runtimeMode: testCase.checks } + : CLAUDE_TEST_RUNTIME_POLICY, + ); + opened.canUseTool = harness.getOpenedOptions()?.canUseTool; const mcpApps = harness.runtime.mcpApps!; const target = { providerThread: harness.providerThread, server }; const [listed] = yield* mcpApps.listTools(target); @@ -7127,12 +7203,17 @@ describe("ClaudeAdapterV2 background wake turns", () => { ); const exit = yield* Effect.exit(mcpApps.callTool({ ...target, tool, arguments: {} })); assert.equal(Exit.isSuccess(exit), testCase.called); - assert.equal( - mcpRequests.some( - (request) => typeof request === "object" && request !== null && "arguments" in request, - ), - testCase.called, - ); + assert.deepEqual( + calls.map((call) => call.checkPermissions === true), + testCase.called ? ["checks" in testCase && testCase.checks === "full-access"] : [], + ); + if ("claudeAsks" in testCase && !testCase.called) { + // Claude asked about a call nobody was prompted for, so the next one is prompted and runs. + const [relisted] = yield* mcpApps.listTools(target); + assert.deepEqual(relisted?.annotations, { destructiveHint: false }); + yield* mcpApps.callTool({ ...target, tool, arguments: {} }); + assert.lengthOf(calls, 1); + } }).pipe( Effect.scoped, Effect.provide( diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index b120f9feb5e5a..4cb16d72935e9 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -747,6 +747,8 @@ export interface ClaudeAgentSdkQuerySession { readonly callMcpTool: (input: { readonly tool: string; readonly arguments: Record; + /** Has Claude decide the call as the model's own; an ask reaches `canUseTool`. */ + readonly checkPermissions?: boolean; }) => Effect.Effect; readonly listPermissionRules: Effect.Effect< ReadonlyArray, @@ -1074,21 +1076,78 @@ function claudeRulesMayCoverMcpTools( }); } +// Recorded from Claude Code 2.1.330: the tool-use id of the ask a checked `mcp_call` sends to `canUseTool`. +const CLAUDE_MCP_CALL_TOOL_USE_ID_PREFIX = "toolu_mcp_call_"; + +/** + * Whether Claude itself decides a card's calls. Only in Full Access, where it asks for nothing but + * its ask rules and safety checks: plan and dontAsk refuse every ask, and other modes ask about calls + * T3 runs today. An older CLI ignores the flag and runs the tool unchecked. + */ +function claudeChecksMcpAppCalls( + liveQuery: Pick, +): boolean { + return ( + liveQuery.capabilities.has("mcp_call_check_permissions_v1") && + liveQuery.permissionMode === "bypassPermissions" + ); +} + +/** + * Whether an ask rule names this tool as T3 spells it: the tool, its server, or a wildcard over the + * whole name. Claude also matches spellings T3 can't list; such an ask is refused once, then prompted. + */ +function claudeAskRuleNamesMcpTool( + rules: ReadonlyArray, + server: string, + toolName: string, +): boolean { + const serverName = claudeMcpToolPrefix(server).slice(0, -"__".length); + return rules.some((entry) => { + if (entry.behavior !== "ask" || entry.notInEffect === true) return false; + const name = entry.rule.split("(", 1)[0] ?? entry.rule; + if (name === toolName || name === serverName) return true; + if (!name.includes("*")) return false; + const pattern = name + .split("*") + .map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) + .join(".*"); + return new RegExp(`^${pattern}$`).test(toolName); + }); +} + /** - * Claude reports `annotations` as `readOnly`/`destructive`/`openWorld`; apps expect MCP's `*Hint` names. - * Card calls skip Claude's permission check, so `readOnlyHint`, which skips T3's prompt, needs readable - * rules (null when not) with no ask or deny rule that may cover the tool. + * Whether a card runs this read-only tool without T3's prompt. A checked call is refused or asked + * about by Claude, so only a tool it asks about (`asked`, or an ask rule naming it) needs the prompt, + * which then answers the ask. An unchecked call skips Claude's check, so it needs readable rules + * (null when not) with no ask or deny rule that may cover the tool. */ +function claudeReadOnlyMcpToolSkipsPrompt(input: { + readonly checked: boolean; + readonly rules: ReadonlyArray | null; + readonly asked: ReadonlySet; + readonly server: string; + readonly tool: string; +}): boolean { + if (!input.checked) { + return input.rules !== null && !claudeRulesMayCoverMcpTools(input.rules, ["ask", "deny"]); + } + const toolName = claudeMcpToolName(input.server, input.tool); + return ( + !input.asked.has(toolName) && + (input.rules === null || !claudeAskRuleNamesMcpTool(input.rules, input.server, toolName)) + ); +} + +/** Claude reports `annotations` as `readOnly`/`destructive`/`openWorld`; apps expect MCP's `*Hint` names. */ function claudeMcpToolForApps( tool: NonNullable[number], - rules: ReadonlyArray | null, + readOnlySkipsPrompt: boolean, ) { const annotations = tool.annotations ?? {}; + // `readOnlyHint` is what skips T3's prompt. const readOnlyHint = - annotations.readOnly !== true || - (rules !== null && !claudeRulesMayCoverMcpTools(rules, ["ask", "deny"])) - ? annotations.readOnly - : undefined; + annotations.readOnly !== true || readOnlySkipsPrompt ? annotations.readOnly : undefined; return { name: tool.name, ...(tool.description === undefined ? {} : { description: tool.description }), @@ -1987,6 +2046,7 @@ export const layerQueryRunner: Layer.Layer< tool: call.tool, arguments: call.arguments, result_not_for_model: true, + ...(call.checkPermissions === true ? { check_permissions: true } : {}), }), catch: (cause) => queryRunnerError(cause, "callMcpTool"), }), @@ -6095,6 +6155,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( const pdfBudgets = new Map>(); // MCP app notes already in each native session's history, by key. Cleared when it compacts. const deliveredAppContext = new Map>(); + // In-flight card calls, by Claude tool name, that T3 asked the user about first. + const promptedMcpAppCalls = new Map(); + // Claude tool names whose unprompted card call Claude asked about; T3 prompts for them from then on. + const mcpAppToolsClaudeAskedAbout = new Set(); const latestPlanByKind = yield* Ref.make(new Map()); // Claude 5 task tools edit one list per native session, across turns. const taskListsByNativeThread = yield* Ref.make( @@ -12551,6 +12615,22 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( callbackOptions: Parameters[2], options?: { readonly startToolCall?: boolean }, ) { + // A card's call belongs to no turn; T3's own prompt, shown before the call, is the user's answer. + if (callbackOptions.toolUseID.startsWith(CLAUDE_MCP_CALL_TOOL_USE_ID_PREFIX)) { + if (promptedMcpAppCalls.has(toolName)) { + return { + behavior: "allow", + updatedInput: toolInput, + toolUseID: callbackOptions.toolUseID, + } satisfies PermissionResult; + } + mcpAppToolsClaudeAskedAbout.add(toolName); + return { + behavior: "deny", + message: "The user was not asked about this app call.", + toolUseID: callbackOptions.toolUseID, + } satisfies PermissionResult; + } const context = yield* Ref.get(activeTurn); if (context === null) { return { @@ -14554,7 +14634,19 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( const rules = yield* liveQuery.query.listPermissionRules.pipe( Effect.orElseSucceed(() => null), ); - return (status?.tools ?? []).map((tool) => claudeMcpToolForApps(tool, rules)); + const checked = claudeChecksMcpAppCalls(liveQuery); + return (status?.tools ?? []).map((tool) => + claudeMcpToolForApps( + tool, + claudeReadOnlyMcpToolSkipsPrompt({ + checked, + rules, + asked: mcpAppToolsClaudeAskedAbout, + server, + tool: tool.name, + }), + ), + ); }), callTool: Effect.fn("ClaudeAdapterV2.callMcpTool")(function* (call) { const { liveQuery, statuses } = yield* mcpAppServerStatuses( @@ -14572,39 +14664,67 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( detail: "Another tool on this MCP server has the same Claude tool name.", }); } - // mcp_call skips Claude's permission check, so its deny rules are applied here. + const checked = claudeChecksMcpAppCalls(liveQuery); const rules = yield* liveQuery.query.listPermissionRules.pipe( - Effect.mapError( - (cause) => - new ProviderAdapter.ProviderAdapterProtocolError({ - driver: CLAUDE_PROVIDER, - detail: `Claude's permission rules could not be read, so ${tool} was not called.`, - cause, - }), + Effect.catch((cause) => + checked + ? Effect.succeed(null) + : Effect.fail( + new ProviderAdapter.ProviderAdapterProtocolError({ + driver: CLAUDE_PROVIDER, + detail: `Claude's permission rules could not be read, so ${tool} was not called.`, + cause, + }), + ), ), ); - if (claudeRulesMayCoverMcpTools(rules, ["deny"])) { + // An unchecked mcp_call skips Claude's permission check, so its deny rules are applied here. + if (!checked && rules !== null && claudeRulesMayCoverMcpTools(rules, ["deny"])) { return yield* new ProviderAdapter.ProviderAdapterProtocolError({ driver: CLAUDE_PROVIDER, detail: `A Claude deny rule may cover ${tool}, so it was not called.`, }); } - return claudeMcpCallToolResult( - yield* liveQuery.query - .callMcpTool({ - tool, - arguments: call.arguments, + // The client asked first unless it was told the tool is read-only, as listTools decides. + const prompted = + checked && + !( + sameName[0]?.annotations?.readOnly === true && + claudeReadOnlyMcpToolSkipsPrompt({ + checked, + rules, + asked: mcpAppToolsClaudeAskedAbout, + server: call.server, + tool: call.tool, }) - .pipe( - Effect.mapError( - (cause) => - new ProviderAdapter.ProviderAdapterProtocolError({ - driver: CLAUDE_PROVIDER, - detail: "Claude MCP tool call failed.", - cause, - }), - ), + ); + const countPrompted = (change: 1 | -1) => + Effect.sync(() => { + if (!prompted) return; + const count = (promptedMcpAppCalls.get(tool) ?? 0) + change; + if (count > 0) promptedMcpAppCalls.set(tool, count); + else promptedMcpAppCalls.delete(tool); + }); + return claudeMcpCallToolResult( + yield* Effect.acquireUseRelease( + countPrompted(1), + () => + liveQuery.query.callMcpTool({ + tool, + arguments: call.arguments, + ...(checked ? { checkPermissions: true } : {}), + }), + () => countPrompted(-1), + ).pipe( + Effect.mapError( + (cause) => + new ProviderAdapter.ProviderAdapterProtocolError({ + driver: CLAUDE_PROVIDER, + detail: "Claude MCP tool call failed.", + cause, + }), ), + ), ); }), readResource: Effect.fn("ClaudeAdapterV2.readMcpResource")(function* (read) { From 40d34551c4e4f412d86ff03420019c9aa7065d94 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 07:15:30 +0000 Subject: [PATCH 2/4] fix(server): match Claude ask-rule wildcards without a backtracking regex Each `*` became `.*`, so a rule with several wildcards that nearly matched a long tool name backtracked exponentially and blocked the server while a card listed its tools. Match segments left to right instead, which is linear in the name. Co-Authored-By: Claude Fable 5.2 --- .../Adapters/ClaudeAdapterV2.test.ts | 8 +++++++ .../Adapters/ClaudeAdapterV2.ts | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index d033f9feeeb2d..c62ba5e4979d4 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -7115,6 +7115,14 @@ describe("ClaudeAdapterV2 background wake turns", () => { called: true, readOnly: false, }, + { + case: "Claude's own check and an ask wildcard that repeats a segment and misses its last one", + rules: [{ behavior: "ask", rule: "mcp__probe_server__*a*a*a*a*a*a*a*ab" }], + tool: "a".repeat(256), + checks: "full-access", + called: true, + readOnly: true, + }, { case: "Claude's own check and an ask rule for a server alias T3 can't list", rules: [{ behavior: "ask", rule: "mcp__probe_alias" }], diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 4cb16d72935e9..478e17b954e3c 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -1107,15 +1107,25 @@ function claudeAskRuleNamesMcpTool( if (entry.behavior !== "ask" || entry.notInEffect === true) return false; const name = entry.rule.split("(", 1)[0] ?? entry.rule; if (name === toolName || name === serverName) return true; - if (!name.includes("*")) return false; - const pattern = name - .split("*") - .map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) - .join(".*"); - return new RegExp(`^${pattern}$`).test(toolName); + return name.includes("*") && claudeWildcardMatches(name, toolName); }); } +// Leftmost search per segment, not a regex: a `.*` per `*` backtracks exponentially on a near miss. +function claudeWildcardMatches(pattern: string, value: string): boolean { + const [first = "", ...rest] = pattern.split("*"); + const last = rest.pop(); + if (last === undefined) return pattern === value; + if (!value.startsWith(first)) return false; + let from = first.length; + for (const part of rest) { + const at = value.indexOf(part, from); + if (at === -1) return false; + from = at + part.length; + } + return value.length - last.length >= from && value.endsWith(last); +} + /** * Whether a card runs this read-only tool without T3's prompt. A checked call is refused or asked * about by Claude, so only a tool it asks about (`asked`, or an ask rule naming it) needs the prompt, From 37b043e023e891d2e90aed24e539b5ba1020084e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 07:34:59 +0000 Subject: [PATCH 3/4] fix(server): a refused MCP app ask no longer lets a later unprompted call pass A tool whose unprompted card call Claude asked about was remembered so the next call would be prompted. A second call already past its `toolInfo` read was then counted as prompted and passed Claude's ask though the user was never asked. Drop the memory: whether a call was prompted now depends only on the tool and the rules, and an ask T3 did not predict is refused every time. Co-Authored-By: Claude Fable 5.2 --- .../Adapters/ClaudeAdapterV2.test.ts | 8 ++--- .../Adapters/ClaudeAdapterV2.ts | 30 ++++++++----------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index c62ba5e4979d4..9687ebcedf5a3 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -7216,11 +7216,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { testCase.called ? ["checks" in testCase && testCase.checks === "full-access"] : [], ); if ("claudeAsks" in testCase && !testCase.called) { - // Claude asked about a call nobody was prompted for, so the next one is prompted and runs. - const [relisted] = yield* mcpApps.listTools(target); - assert.deepEqual(relisted?.annotations, { destructiveHint: false }); - yield* mcpApps.callTool({ ...target, tool, arguments: {} }); - assert.lengthOf(calls, 1); + // Nobody was prompted for the refused call, so it cannot make a later unprompted one pass. + const retry = yield* Effect.exit(mcpApps.callTool({ ...target, tool, arguments: {} })); + assert.isTrue(Exit.isFailure(retry)); } }).pipe( Effect.scoped, diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 478e17b954e3c..07052d0349573 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -1095,7 +1095,7 @@ function claudeChecksMcpAppCalls( /** * Whether an ask rule names this tool as T3 spells it: the tool, its server, or a wildcard over the - * whole name. Claude also matches spellings T3 can't list; such an ask is refused once, then prompted. + * whole name. Claude also matches spellings T3 can't list; it refuses those asks, as nobody was asked. */ function claudeAskRuleNamesMcpTool( rules: ReadonlyArray, @@ -1128,25 +1128,24 @@ function claudeWildcardMatches(pattern: string, value: string): boolean { /** * Whether a card runs this read-only tool without T3's prompt. A checked call is refused or asked - * about by Claude, so only a tool it asks about (`asked`, or an ask rule naming it) needs the prompt, - * which then answers the ask. An unchecked call skips Claude's check, so it needs readable rules - * (null when not) with no ask or deny rule that may cover the tool. + * about by Claude, so only an ask rule naming the tool needs the prompt, which then answers the ask. + * An unchecked call skips Claude's check, so it needs readable rules (null when not) with no ask or + * deny rule that may cover the tool. */ function claudeReadOnlyMcpToolSkipsPrompt(input: { readonly checked: boolean; readonly rules: ReadonlyArray | null; - readonly asked: ReadonlySet; readonly server: string; readonly tool: string; }): boolean { - if (!input.checked) { - return input.rules !== null && !claudeRulesMayCoverMcpTools(input.rules, ["ask", "deny"]); - } - const toolName = claudeMcpToolName(input.server, input.tool); - return ( - !input.asked.has(toolName) && - (input.rules === null || !claudeAskRuleNamesMcpTool(input.rules, input.server, toolName)) - ); + if (input.rules === null) return input.checked; + return input.checked + ? !claudeAskRuleNamesMcpTool( + input.rules, + input.server, + claudeMcpToolName(input.server, input.tool), + ) + : !claudeRulesMayCoverMcpTools(input.rules, ["ask", "deny"]); } /** Claude reports `annotations` as `readOnly`/`destructive`/`openWorld`; apps expect MCP's `*Hint` names. */ @@ -6167,8 +6166,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( const deliveredAppContext = new Map>(); // In-flight card calls, by Claude tool name, that T3 asked the user about first. const promptedMcpAppCalls = new Map(); - // Claude tool names whose unprompted card call Claude asked about; T3 prompts for them from then on. - const mcpAppToolsClaudeAskedAbout = new Set(); const latestPlanByKind = yield* Ref.make(new Map()); // Claude 5 task tools edit one list per native session, across turns. const taskListsByNativeThread = yield* Ref.make( @@ -12634,7 +12631,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( toolUseID: callbackOptions.toolUseID, } satisfies PermissionResult; } - mcpAppToolsClaudeAskedAbout.add(toolName); return { behavior: "deny", message: "The user was not asked about this app call.", @@ -14651,7 +14647,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( claudeReadOnlyMcpToolSkipsPrompt({ checked, rules, - asked: mcpAppToolsClaudeAskedAbout, server, tool: tool.name, }), @@ -14703,7 +14698,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( claudeReadOnlyMcpToolSkipsPrompt({ checked, rules, - asked: mcpAppToolsClaudeAskedAbout, server: call.server, tool: call.tool, }) From ee49ce7ed6da38dbcdedb5ef0f89f80bc1de0701 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 07:59:57 +0000 Subject: [PATCH 4/4] fix(server): MCP app calls prompt for ask rules T3 cannot place Claude matches permission rules against per-server keys T3 cannot list. An ask rule under such a key kept the tool's read-only hint, so no prompt was shown, Claude asked anyway and the call was refused every time. Keep the prompt-free path only for an ask rule that is plainly about something else: one under this server's name that spells another tool, or one under the name of another server Claude reports. Any other MCP ask rule prompts first, and the confirmed call then passes Claude's ask. Co-Authored-By: Claude Fable 5.2 --- .../Adapters/ClaudeAdapterV2.test.ts | 10 ++++ .../Adapters/ClaudeAdapterV2.ts | 57 ++++++++++++------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 9687ebcedf5a3..42578a4e3e828 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -7100,6 +7100,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { case: "Claude's own check and rules for other tools", rules: [ { behavior: "ask", rule: "mcp__atlassian__createJiraIssue" }, + { behavior: "ask", rule: "mcp__probe_server__delete_*" }, { behavior: "deny", rule: "mcp__buildkite__create_build" }, { behavior: "deny", rule: "mcp__probe_server__delete_*" }, ], @@ -7128,6 +7129,14 @@ describe("ClaudeAdapterV2 background wake turns", () => { rules: [{ behavior: "ask", rule: "mcp__probe_alias" }], checks: "full-access", claudeAsks: true, + called: true, + readOnly: false, + }, + { + case: "Claude's own check and an ask T3 did not prompt for", + rules: [{ behavior: "ask", rule: "mcp__atlassian" }], + checks: "full-access", + claudeAsks: true, called: false, readOnly: true, }, @@ -7162,6 +7171,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { name: server, tools: [{ ...PROBE_SERVER_STATUS.tools[1], name: tool }], }, + { name: "atlassian", status: "connected", tools: [] }, ]), listPermissionRules: testCase.rules === "unreadable" diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 07052d0349573..afb4d2a66d27b 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -1094,20 +1094,35 @@ function claudeChecksMcpAppCalls( } /** - * Whether an ask rule names this tool as T3 spells it: the tool, its server, or a wildcard over the - * whole name. Claude also matches spellings T3 can't list; it refuses those asks, as nobody was asked. + * Whether an ask rule may cover this tool. Claude also matches rules against per-server keys T3 can't + * list, so only two kinds of rule are ruled out: one under this server's name that spells another + * tool, and one under the name of another server Claude reports. A false match only asks first. */ -function claudeAskRuleNamesMcpTool( - rules: ReadonlyArray, - server: string, - toolName: string, -): boolean { - const serverName = claudeMcpToolPrefix(server).slice(0, -"__".length); - return rules.some((entry) => { +function claudeAskRuleMayCoverMcpTool(input: { + readonly rules: ReadonlyArray; + readonly statuses: ReadonlyArray; + readonly server: string; + readonly toolName: string; +}): boolean { + // Claude reads a rule's server as the text up to the first `__`. + const serverPart = (name: string) => name.slice("mcp__".length).split("__", 1)[0] ?? ""; + const own = serverPart(claudeMcpToolPrefix(input.server)); + const others = new Set( + input.statuses.map((status) => serverPart(claudeMcpToolPrefix(status.name))), + ); + return input.rules.some((entry) => { if (entry.behavior !== "ask" || entry.notInEffect === true) return false; const name = entry.rule.split("(", 1)[0] ?? entry.rule; - if (name === toolName || name === serverName) return true; - return name.includes("*") && claudeWildcardMatches(name, toolName); + if (!name.startsWith("mcp__")) return name.includes("*"); + const part = serverPart(name); + if (part === own) { + return ( + input.toolName === name || + input.toolName.startsWith(`${name}__`) || + claudeWildcardMatches(name, input.toolName) + ); + } + return part.includes("*") || !others.has(part); }); } @@ -1128,23 +1143,25 @@ function claudeWildcardMatches(pattern: string, value: string): boolean { /** * Whether a card runs this read-only tool without T3's prompt. A checked call is refused or asked - * about by Claude, so only an ask rule naming the tool needs the prompt, which then answers the ask. - * An unchecked call skips Claude's check, so it needs readable rules (null when not) with no ask or - * deny rule that may cover the tool. + * about by Claude, so only an ask rule that may cover the tool needs the prompt, which then answers + * the ask. An unchecked call skips Claude's check, so it needs readable rules (null when not) with no + * ask or deny rule that may cover any MCP tool. */ function claudeReadOnlyMcpToolSkipsPrompt(input: { readonly checked: boolean; readonly rules: ReadonlyArray | null; + readonly statuses: ReadonlyArray; readonly server: string; readonly tool: string; }): boolean { if (input.rules === null) return input.checked; return input.checked - ? !claudeAskRuleNamesMcpTool( - input.rules, - input.server, - claudeMcpToolName(input.server, input.tool), - ) + ? !claudeAskRuleMayCoverMcpTool({ + rules: input.rules, + statuses: input.statuses, + server: input.server, + toolName: claudeMcpToolName(input.server, input.tool), + }) : !claudeRulesMayCoverMcpTools(input.rules, ["ask", "deny"]); } @@ -14647,6 +14664,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( claudeReadOnlyMcpToolSkipsPrompt({ checked, rules, + statuses, server, tool: tool.name, }), @@ -14698,6 +14716,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( claudeReadOnlyMcpToolSkipsPrompt({ checked, rules, + statuses, server: call.server, tool: call.tool, })