Skip to content

Commit 815fbaa

Browse files
committed
fix: address review comments for MCP resource auto-approval
- Add explicit return false after try-catch block for better code clarity - Extract McpServerUse type into a proper TypeScript interface in types package - Improve type safety and code maintainability
1 parent fafd33f commit 815fbaa

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
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: 5 additions & 9 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
@@ -1151,12 +1151,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
11511151
}
11521152

11531153
try {
1154-
const mcpServerUse = JSON.parse(message.text) as {
1155-
type: string
1156-
serverName: string
1157-
toolName?: string
1158-
uri?: string
1159-
}
1154+
const mcpServerUse = JSON.parse(message.text) as McpServerUse
11601155

11611156
if (mcpServerUse.type === "use_mcp_tool") {
11621157
// For tools, check if the specific tool is always allowed
@@ -1170,6 +1165,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
11701165
console.error("Failed to parse MCP server use message:", error)
11711166
return false
11721167
}
1168+
return false
11731169
}
11741170

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

0 commit comments

Comments
 (0)