Skip to content

Commit 1efd84a

Browse files
trevhudsaoudrizwan
andauthored
Trevhud/eng 279 (RooCodeInc#2505)
* Move restart/delete server and all toggle all * changeset * move buttons back to the bottom and show icons even when expanded * Only display auto-approve all if auto-approve mcp is enabled * Move auto-approve setting to bottom --------- Co-authored-by: Saoud Rizwan <[email protected]>
1 parent 130922f commit 1efd84a

File tree

6 files changed

+84
-17
lines changed

6 files changed

+84
-17
lines changed

.changeset/mighty-pants-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Move the MCP Restart and Delete buttons and add an auto-approve all toggle

src/core/webview/ClineProvider.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,20 @@ export class ClineProvider implements vscode.WebviewViewProvider {
819819
}
820820
case "toggleToolAutoApprove": {
821821
try {
822-
await this.mcpHub?.toggleToolAutoApprove(message.serverName!, message.toolName!, message.autoApprove!)
822+
await this.mcpHub?.toggleToolAutoApprove(
823+
message.serverName!,
824+
message.toolNames!,
825+
message.autoApprove!,
826+
)
823827
} catch (error) {
824-
console.error(`Failed to toggle auto-approve for tool ${message.toolName}:`, error)
828+
if (message.toolNames?.length === 1) {
829+
console.error(
830+
`Failed to toggle auto-approve for server ${message.serverName} with tool ${message.toolNames[0]}:`,
831+
error,
832+
)
833+
} else {
834+
console.error(`Failed to toggle auto-approve tools for server ${message.serverName}:`, error)
835+
}
825836
}
826837
break
827838
}

src/services/mcp/McpHub.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ export class McpHub {
621621
)
622622
}
623623

624-
async toggleToolAutoApprove(serverName: string, toolName: string, shouldAllow: boolean): Promise<void> {
624+
async toggleToolAutoApprove(serverName: string, toolNames: string[], shouldAllow: boolean): Promise<void> {
625625
try {
626626
const settingsPath = await this.getMcpSettingsFilePath()
627627
const content = await fs.readFile(settingsPath, "utf-8")
@@ -633,14 +633,16 @@ export class McpHub {
633633
}
634634

635635
const autoApprove = config.mcpServers[serverName].autoApprove
636-
const toolIndex = autoApprove.indexOf(toolName)
637-
638-
if (shouldAllow && toolIndex === -1) {
639-
// Add tool to autoApprove list
640-
autoApprove.push(toolName)
641-
} else if (!shouldAllow && toolIndex !== -1) {
642-
// Remove tool from autoApprove list
643-
autoApprove.splice(toolIndex, 1)
636+
for (const toolName of toolNames) {
637+
const toolIndex = autoApprove.indexOf(toolName)
638+
639+
if (shouldAllow && toolIndex === -1) {
640+
// Add tool to autoApprove list
641+
autoApprove.push(toolName)
642+
} else if (!shouldAllow && toolIndex !== -1) {
643+
// Remove tool from autoApprove list
644+
autoApprove.splice(toolIndex, 1)
645+
}
644646
}
645647

646648
await fs.writeFile(settingsPath, JSON.stringify(config, null, 2))

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface WebviewMessage {
8181
timeout?: number
8282
// For toggleToolAutoApprove
8383
serverName?: string
84-
toolName?: string
84+
toolNames?: string[]
8585
autoApprove?: boolean
8686

8787
// For auth

webview-ui/src/components/mcp/McpToolRow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ type McpToolRowProps = {
1111
const McpToolRow = ({ tool, serverName }: McpToolRowProps) => {
1212
const { autoApprovalSettings } = useExtensionState()
1313

14-
const handleAutoApproveChange = () => {
15-
if (!serverName) return
14+
// Accept the event object
15+
const handleAutoApproveChange = (event: any) => {
16+
// Only proceed if the event was triggered by a direct user interaction
17+
if (!serverName || !event.isTrusted) return
1618

1719
vscode.postMessage({
1820
type: "toggleToolAutoApprove",
1921
serverName,
20-
toolName: tool.name,
22+
toolNames: [tool.name],
2123
autoApprove: !tool.autoApprove,
2224
})
2325
}

webview-ui/src/components/mcp/McpView.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
VSCodePanelView,
77
VSCodeDropdown,
88
VSCodeOption,
9+
VSCodeCheckbox,
910
} from "@vscode/webview-ui-toolkit/react"
1011
import { useEffect, useState } from "react"
1112
import styled from "styled-components"
@@ -204,7 +205,7 @@ export const TabButton = ({
204205

205206
// Server Row Component
206207
const ServerRow = ({ server }: { server: McpServer }) => {
207-
const { mcpMarketplaceCatalog } = useExtensionState()
208+
const { mcpMarketplaceCatalog, autoApprovalSettings } = useExtensionState()
208209

209210
const [isExpanded, setIsExpanded] = useState(false)
210211
const [isDeleting, setIsDeleting] = useState(false)
@@ -271,6 +272,17 @@ const ServerRow = ({ server }: { server: McpServer }) => {
271272
})
272273
}
273274

275+
const handleAutoApproveChange = () => {
276+
if (!server.name) return
277+
278+
vscode.postMessage({
279+
type: "toggleToolAutoApprove",
280+
serverName: server.name,
281+
toolNames: server.tools?.map((tool) => tool.name) || [],
282+
autoApprove: !server.tools?.every((tool) => tool.autoApprove),
283+
})
284+
}
285+
274286
return (
275287
<div style={{ marginBottom: "10px" }}>
276288
<div
@@ -299,7 +311,33 @@ const ServerRow = ({ server }: { server: McpServer }) => {
299311
}}>
300312
{getMcpServerDisplayName(server.name, mcpMarketplaceCatalog)}
301313
</span>
302-
<div style={{ display: "flex", alignItems: "center", marginRight: "8px" }} onClick={(e) => e.stopPropagation()}>
314+
{/* Collapsed view controls */}
315+
{!server.error && (
316+
<div style={{ display: "flex", alignItems: "center", gap: "4px", marginLeft: "8px" }}>
317+
<VSCodeButton
318+
appearance="icon"
319+
title="Restart Server"
320+
onClick={(e) => {
321+
e.stopPropagation()
322+
handleRestart()
323+
}}
324+
disabled={server.status === "connecting"}>
325+
<span className="codicon codicon-sync"></span>
326+
</VSCodeButton>
327+
<VSCodeButton
328+
appearance="icon"
329+
title="Delete Server"
330+
onClick={(e) => {
331+
e.stopPropagation()
332+
handleDelete()
333+
}}
334+
disabled={isDeleting}>
335+
<span className="codicon codicon-trash"></span>
336+
</VSCodeButton>
337+
</div>
338+
)}
339+
{/* Toggle Switch */}
340+
<div style={{ display: "flex", alignItems: "center", marginLeft: "8px" }} onClick={(e) => e.stopPropagation()}>
303341
<div
304342
role="switch"
305343
aria-checked={!server.disabled}
@@ -422,6 +460,15 @@ const ServerRow = ({ server }: { server: McpServer }) => {
422460
{server.tools.map((tool) => (
423461
<McpToolRow key={tool.name} tool={tool} serverName={server.name} />
424462
))}
463+
{server.name && autoApprovalSettings.enabled && autoApprovalSettings.actions.useMcp && (
464+
<VSCodeCheckbox
465+
style={{ marginBottom: -10 }}
466+
checked={server.tools.every((tool) => tool.autoApprove)}
467+
onChange={handleAutoApproveChange}
468+
data-tool="all-tools">
469+
Auto-approve all tools
470+
</VSCodeCheckbox>
471+
)}
425472
</div>
426473
) : (
427474
<div

0 commit comments

Comments
 (0)