From 73c64d9ab5a788feccd750ce2cf46acf78e3fc0b Mon Sep 17 00:00:00 2001 From: Evan <58194240+celestial-vault@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:22:20 -0700 Subject: [PATCH] Add Toggle MCP Servers Modal (#2723) * make ServerRow not optionally not expandable * changeset * factor out servers toggle list * changeset * add servers modal * changest * Reduce padding in modal * separate fetch useEffect for more efficient rendering --------- Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> --- .changeset/mean-pears-eat.md | 5 ++ .changeset/polite-lions-deliver.md | 5 ++ .../src/components/chat/ChatTextArea.tsx | 11 ++- .../components/chat/ServersToggleModal.tsx | 86 +++++++++++++++++++ .../tabs/installed/InstalledServersView.tsx | 2 +- .../tabs/installed/ServersToggleList.tsx | 24 +++++- .../tabs/installed/server-row/ServerRow.tsx | 32 ++++--- 7 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 .changeset/mean-pears-eat.md create mode 100644 .changeset/polite-lions-deliver.md create mode 100644 webview-ui/src/components/chat/ServersToggleModal.tsx diff --git a/.changeset/mean-pears-eat.md b/.changeset/mean-pears-eat.md new file mode 100644 index 00000000..ad58fb3c --- /dev/null +++ b/.changeset/mean-pears-eat.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +Add modal for toggling MCP servers to the chat area diff --git a/.changeset/polite-lions-deliver.md b/.changeset/polite-lions-deliver.md new file mode 100644 index 00000000..f531e36c --- /dev/null +++ b/.changeset/polite-lions-deliver.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +factor out servers list diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index 22c16109..de67b0be 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -25,6 +25,7 @@ import ApiOptions, { normalizeApiConfiguration } from "@/components/settings/Api import { MAX_IMAGES_PER_MESSAGE } from "@/components/chat/ChatView" import ContextMenu from "@/components/chat/ContextMenu" import { ChatSettings } from "@shared/ChatSettings" +import ServersToggleModal from "./ServersToggleModal" interface ChatTextAreaProps { inputValue: string @@ -1190,7 +1191,9 @@ const ChatTextArea = forwardRef( onClick={handleContextButtonClick} style={{ padding: "0px 0px", height: "20px" }}> - @ + + @ + {/* {showButtonText && Context} */} @@ -1207,10 +1210,14 @@ const ChatTextArea = forwardRef( }} style={{ padding: "0px 0px", height: "20px" }}> - + {/* {showButtonText && Images} */} + diff --git a/webview-ui/src/components/chat/ServersToggleModal.tsx b/webview-ui/src/components/chat/ServersToggleModal.tsx new file mode 100644 index 00000000..731bce00 --- /dev/null +++ b/webview-ui/src/components/chat/ServersToggleModal.tsx @@ -0,0 +1,86 @@ +import React, { useRef, useState, useEffect } from "react" +import { useClickAway, useWindowSize } from "react-use" +import { useExtensionState } from "@/context/ExtensionStateContext" +import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" +import ServersToggleList from "@/components/mcp/configuration/tabs/installed/ServersToggleList" +import { vscode } from "@/utils/vscode" +import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" + +const ServersToggleModal: React.FC = () => { + const { mcpServers } = useExtensionState() + const [isVisible, setIsVisible] = useState(false) + const buttonRef = useRef(null) + const modalRef = useRef(null) + const { width: viewportWidth, height: viewportHeight } = useWindowSize() + const [arrowPosition, setArrowPosition] = useState(0) + const [menuPosition, setMenuPosition] = useState(0) + + // Close modal when clicking outside + useClickAway(modalRef, () => { + setIsVisible(false) + }) + + // Calculate positions for modal and arrow + useEffect(() => { + if (isVisible && buttonRef.current) { + const buttonRect = buttonRef.current.getBoundingClientRect() + const buttonCenter = buttonRect.left + buttonRect.width / 2 + const rightPosition = document.documentElement.clientWidth - buttonCenter - 5 + + setArrowPosition(rightPosition) + setMenuPosition(buttonRect.top + 1) + } + }, [isVisible, viewportWidth, viewportHeight]) + + useEffect(() => { + if (isVisible) { + vscode.postMessage({ type: "fetchLatestMcpServersFromHub" }) + } + }, [isVisible]) + + return ( +
+
+ setIsVisible(!isVisible)} + style={{ padding: "0px 0px", height: "20px" }}> +
+ +
+
+
+ + {isVisible && ( +
+
+ +
MCP Servers
+
+ +
+
+ )} +
+ ) +} + +export default ServersToggleModal diff --git a/webview-ui/src/components/mcp/configuration/tabs/installed/InstalledServersView.tsx b/webview-ui/src/components/mcp/configuration/tabs/installed/InstalledServersView.tsx index 097ee5b6..94807e99 100644 --- a/webview-ui/src/components/mcp/configuration/tabs/installed/InstalledServersView.tsx +++ b/webview-ui/src/components/mcp/configuration/tabs/installed/InstalledServersView.tsx @@ -29,7 +29,7 @@ const InstalledServersView = () => {
- + {/* Settings Section */}
diff --git a/webview-ui/src/components/mcp/configuration/tabs/installed/ServersToggleList.tsx b/webview-ui/src/components/mcp/configuration/tabs/installed/ServersToggleList.tsx index 9b7caa91..27fb6353 100644 --- a/webview-ui/src/components/mcp/configuration/tabs/installed/ServersToggleList.tsx +++ b/webview-ui/src/components/mcp/configuration/tabs/installed/ServersToggleList.tsx @@ -1,11 +1,29 @@ import { McpServer } from "@shared/mcp" import ServerRow from "./server-row/ServerRow" -const ServersToggleList = ({ servers }: { servers: McpServer[] }) => { +const ServersToggleList = ({ + servers, + isExpandable, + hasTrashIcon, + listGap = "medium", +}: { + servers: McpServer[] + isExpandable: boolean + hasTrashIcon: boolean + listGap?: "small" | "medium" | "large" +}) => { + const gapClasses = { + small: "gap-0", + medium: "gap-2.5", + large: "gap-5", + } + + const gapClass = gapClasses[listGap] + return servers.length > 0 ? ( -
+
{servers.map((server) => ( - + ))}
) : ( diff --git a/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx b/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx index faae580d..33c43deb 100644 --- a/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx +++ b/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx @@ -17,7 +17,15 @@ import McpToolRow from "./McpToolRow" import McpResourceRow from "./McpResourceRow" import { useExtensionState } from "@/context/ExtensionStateContext" -const ServerRow = ({ server, isExpandable = true }: { server: McpServer; isExpandable?: boolean }) => { +const ServerRow = ({ + server, + isExpandable = true, + hasTrashIcon = true, +}: { + server: McpServer + isExpandable?: boolean + hasTrashIcon?: boolean +}) => { const { mcpMarketplaceCatalog, autoApprovalSettings } = useExtensionState() const [isExpanded, setIsExpanded] = useState(false) @@ -138,16 +146,18 @@ const ServerRow = ({ server, isExpandable = true }: { server: McpServer; isExpan disabled={server.status === "connecting"}> - { - e.stopPropagation() - handleDelete() - }} - disabled={isDeleting}> - - + {hasTrashIcon && ( + { + e.stopPropagation() + handleDelete() + }} + disabled={isDeleting}> + + + )}
)} {/* Toggle Switch */}