From 1638a27ed491b54f46c699b33f61a99067aea280 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Sat, 21 Jun 2025 14:15:29 -0500 Subject: [PATCH] fix: resolve MCP tool eye icon state and hide in chat context (#4993) --- .../src/components/chat/McpExecution.tsx | 2 + webview-ui/src/components/mcp/McpToolRow.tsx | 43 +++++++++-------- .../mcp/__tests__/McpToolRow.spec.tsx | 46 +++++++++++++++++++ 3 files changed, 71 insertions(+), 20 deletions(-) diff --git a/webview-ui/src/components/chat/McpExecution.tsx b/webview-ui/src/components/chat/McpExecution.tsx index 8e0882340b..a96f368a17 100644 --- a/webview-ui/src/components/chat/McpExecution.tsx +++ b/webview-ui/src/components/chat/McpExecution.tsx @@ -242,6 +242,7 @@ export const McpExecution = ({ serverName={useMcpServer.serverName} serverSource={server?.source} alwaysAllowMcp={alwaysAllowMcp} + isInChatContext={true} /> )} @@ -256,6 +257,7 @@ export const McpExecution = ({ serverName={serverName} serverSource={undefined} alwaysAllowMcp={alwaysAllowMcp} + isInChatContext={true} /> )} diff --git a/webview-ui/src/components/mcp/McpToolRow.tsx b/webview-ui/src/components/mcp/McpToolRow.tsx index 76664fea46..892304d1c6 100644 --- a/webview-ui/src/components/mcp/McpToolRow.tsx +++ b/webview-ui/src/components/mcp/McpToolRow.tsx @@ -10,9 +10,10 @@ type McpToolRowProps = { serverName?: string serverSource?: "global" | "project" alwaysAllowMcp?: boolean + isInChatContext?: boolean } -const McpToolRow = ({ tool, serverName, serverSource, alwaysAllowMcp }: McpToolRowProps) => { +const McpToolRow = ({ tool, serverName, serverSource, alwaysAllowMcp, isInChatContext = false }: McpToolRowProps) => { const { t } = useAppTranslation() const handleAlwaysAllowChange = () => { if (!serverName) return @@ -66,25 +67,27 @@ const McpToolRow = ({ tool, serverName, serverSource, alwaysAllowMcp }: McpToolR )} - {/* Enabled eye button */} - + {/* Enabled eye button - only show in settings context */} + {!isInChatContext && ( + + )} )} diff --git a/webview-ui/src/components/mcp/__tests__/McpToolRow.spec.tsx b/webview-ui/src/components/mcp/__tests__/McpToolRow.spec.tsx index 43889c3cc5..a3ccd6a990 100644 --- a/webview-ui/src/components/mcp/__tests__/McpToolRow.spec.tsx +++ b/webview-ui/src/components/mcp/__tests__/McpToolRow.spec.tsx @@ -12,6 +12,7 @@ vi.mock("@src/i18n/TranslationContext", () => ({ "mcp:tool.alwaysAllow": "Always allow", "mcp:tool.parameters": "Parameters", "mcp:tool.noDescription": "No description", + "mcp:tool.togglePromptInclusion": "Toggle prompt inclusion", } return translations[key] || key }, @@ -48,6 +49,7 @@ describe("McpToolRow", () => { name: "test-tool", description: "A test tool", alwaysAllow: false, + enabledForPrompt: true, } beforeEach(() => { @@ -141,4 +143,48 @@ describe("McpToolRow", () => { expect(screen.getByText("First parameter")).toBeInTheDocument() expect(screen.getByText("Second parameter")).toBeInTheDocument() }) + + it("shows eye button when serverName is provided and not in chat context", () => { + render() + + const eyeButton = screen.getByRole("button", { name: "Toggle prompt inclusion" }) + expect(eyeButton).toBeInTheDocument() + }) + + it("hides eye button when isInChatContext is true", () => { + render() + + const eyeButton = screen.queryByRole("button", { name: "Toggle prompt inclusion" }) + expect(eyeButton).not.toBeInTheDocument() + }) + + it("shows correct eye icon based on enabledForPrompt state", () => { + // Test when enabled (should show eye-closed icon) + const { rerender } = render() + + let eyeIcon = screen.getByRole("button", { name: "Toggle prompt inclusion" }).querySelector("span") + expect(eyeIcon).toHaveClass("codicon-eye-closed") + + // Test when disabled (should show eye icon) + const disabledTool = { ...mockTool, enabledForPrompt: false } + rerender() + + eyeIcon = screen.getByRole("button", { name: "Toggle prompt inclusion" }).querySelector("span") + expect(eyeIcon).toHaveClass("codicon-eye") + }) + + it("sends message to toggle enabledForPrompt when eye button is clicked", () => { + render() + + const eyeButton = screen.getByRole("button", { name: "Toggle prompt inclusion" }) + fireEvent.click(eyeButton) + + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: "toggleToolEnabledForPrompt", + serverName: "test-server", + source: "global", + toolName: "test-tool", + isEnabled: false, + }) + }) })