Skip to content

Commit 3e478df

Browse files
committed
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
1 parent 3a8ba27 commit 3e478df

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/core/task/Task.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,16 @@ export class Task extends EventEmitter<ClineEvents> {
431431
throw new Error(`[RooCode#ask] task ${this.taskId}.${this.instanceId} aborted`)
432432
}
433433

434+
// Check for auto-approval before proceeding with user interaction
435+
const state = await this.providerRef.deref()?.getState()
436+
if (state?.autoApprovalEnabled) {
437+
const shouldAutoApprove = this.shouldAutoApprove(type, state)
438+
if (shouldAutoApprove) {
439+
// Return immediate approval without user interaction
440+
return { response: "yesButtonClicked" }
441+
}
442+
}
443+
434444
let askTs: number
435445

436446
if (partial !== undefined) {
@@ -524,6 +534,25 @@ export class Task extends EventEmitter<ClineEvents> {
524534
return result
525535
}
526536

537+
/**
538+
* Determines if a request should be auto-approved based on the ask type and current settings
539+
*/
540+
private shouldAutoApprove(type: ClineAsk, state: any): boolean {
541+
switch (type) {
542+
case "use_mcp_server":
543+
return state.alwaysAllowMcp === true
544+
case "command":
545+
return state.alwaysAllowExecute === true
546+
case "browser_action_launch":
547+
return state.alwaysAllowBrowser === true
548+
case "tool":
549+
// For general tool requests, check if read-only operations are always allowed
550+
return state.alwaysAllowReadOnly === true
551+
default:
552+
return false
553+
}
554+
}
555+
527556
async handleWebviewAskResponse(askResponse: ClineAskResponse, text?: string, images?: string[]) {
528557
this.askResponse = askResponse
529558
this.askResponseText = text

0 commit comments

Comments
 (0)