From 3e478df7e363b2b9cc9256fe28e737bd6771c59a Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 1 Jul 2025 06:26:10 +0000 Subject: [PATCH] Fix #5300: Implement auto-approval for access_mcp_resource tool - Add auto-approval logic to Task.ask() method - Check autoApprovalEnabled setting and specific tool permissions - Implement shouldAutoApprove() method to handle different ask types - Fix missing auto-approval for use_mcp_server ask type used by both MCP tools - Ensure access_mcp_resource respects alwaysAllowMcp setting like use_mcp_tool --- src/core/task/Task.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 46da7485edf..595a78e3224 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -431,6 +431,16 @@ export class Task extends EventEmitter { throw new Error(`[RooCode#ask] task ${this.taskId}.${this.instanceId} aborted`) } + // Check for auto-approval before proceeding with user interaction + const state = await this.providerRef.deref()?.getState() + if (state?.autoApprovalEnabled) { + const shouldAutoApprove = this.shouldAutoApprove(type, state) + if (shouldAutoApprove) { + // Return immediate approval without user interaction + return { response: "yesButtonClicked" } + } + } + let askTs: number if (partial !== undefined) { @@ -524,6 +534,25 @@ export class Task extends EventEmitter { return result } + /** + * Determines if a request should be auto-approved based on the ask type and current settings + */ + private shouldAutoApprove(type: ClineAsk, state: any): boolean { + switch (type) { + case "use_mcp_server": + return state.alwaysAllowMcp === true + case "command": + return state.alwaysAllowExecute === true + case "browser_action_launch": + return state.alwaysAllowBrowser === true + case "tool": + // For general tool requests, check if read-only operations are always allowed + return state.alwaysAllowReadOnly === true + default: + return false + } + } + async handleWebviewAskResponse(askResponse: ClineAskResponse, text?: string, images?: string[]) { this.askResponse = askResponse this.askResponseText = text