Skip to content

Commit 7e24600

Browse files
authored
feat: add auto-approve support for MCP access_resource tool (#7606)
1 parent d1baa6e commit 7e24600

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/types/src/mcp.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { z } from "zod"
22

3+
/**
4+
* MCP Server Use Types
5+
*/
6+
export interface McpServerUse {
7+
type: string
8+
serverName: string
9+
toolName?: string
10+
uri?: string
11+
}
12+
313
/**
414
* McpExecutionStatus
515
*/

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useTranslation } from "react-i18next"
1111
import { useDebounceEffect } from "@src/utils/useDebounceEffect"
1212
import { appendImages } from "@src/utils/imageUtils"
1313

14-
import type { ClineAsk, ClineMessage } from "@roo-code/types"
14+
import type { ClineAsk, ClineMessage, McpServerUse } from "@roo-code/types"
1515

1616
import { ClineSayBrowserAction, ClineSayTool, ExtensionMessage } from "@roo/ExtensionMessage"
1717
import { McpServer, McpTool } from "@roo/mcp"
@@ -1062,9 +1062,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
10621062
return true
10631063
}
10641064

1065-
const mcpServerUse = JSON.parse(message.text) as { type: string; serverName: string; toolName: string }
1065+
const mcpServerUse = JSON.parse(message.text) as McpServerUse
10661066

1067-
if (mcpServerUse.type === "use_mcp_tool") {
1067+
if (mcpServerUse.type === "use_mcp_tool" && mcpServerUse.toolName) {
10681068
const server = mcpServers?.find((s: McpServer) => s.name === mcpServerUse.serverName)
10691069
const tool = server?.tools?.find((t: McpTool) => t.name === mcpServerUse.toolName)
10701070
return tool?.alwaysAllow || false
@@ -1145,7 +1145,27 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
11451145
}
11461146

11471147
if (message.ask === "use_mcp_server") {
1148-
return alwaysAllowMcp && isMcpToolAlwaysAllowed(message)
1148+
// Check if it's a tool or resource access
1149+
if (!message.text) {
1150+
return false
1151+
}
1152+
1153+
try {
1154+
const mcpServerUse = JSON.parse(message.text) as McpServerUse
1155+
1156+
if (mcpServerUse.type === "use_mcp_tool") {
1157+
// For tools, check if the specific tool is always allowed
1158+
return alwaysAllowMcp && isMcpToolAlwaysAllowed(message)
1159+
} else if (mcpServerUse.type === "access_mcp_resource") {
1160+
// For resources, auto-approve if MCP is always allowed
1161+
// Resources don't have individual alwaysAllow settings like tools do
1162+
return alwaysAllowMcp
1163+
}
1164+
} catch (error) {
1165+
console.error("Failed to parse MCP server use message:", error)
1166+
return false
1167+
}
1168+
return false
11491169
}
11501170

11511171
if (message.ask === "command") {

0 commit comments

Comments
 (0)