Changesets · Branches · Tags · Compare
| Changeset | 53ff866ea6e754e7b0d90971b1388d37b9bfb05e0109a105ec20b83721024c9d |
|---|---|
| Author | Aditya Mitra <61635505+uinstinct@users.noreply.github.com> · 2025-09-24 21:31 +05:30 |
| Committer | GitHub <noreply@github.com> · 2025-09-24 09:01 -07:00 |
| Parents | e31fcddb0dec |
7 files changed
modified core/context/mcp/MCPConnection.ts +1 −0
| @@ -85,6 +85,7 @@ | ||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | async disconnect() { |
| 88 | + this.status = "not-connected"; | |
| 88 | 89 | this.abortController.abort(); |
| 89 | 90 | await this.client.close(); |
| 90 | 91 | await this.transport.close(); |
modified core/context/mcp/MCPManagerSingleton.ts +26 −3
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | |
| 14 | 14 | public onConnectionsRefreshed?: () => void; |
| 15 | 15 | public connections: Map<string, MCPConnection> = new Map(); |
| 16 | + private disconnectedServers: string[] = []; | |
| 16 | 17 | |
| 17 | 18 | private abortController: AbortController = new AbortController(); |
| 18 | 19 | |
| @@ -25,6 +26,18 @@ | ||
| 25 | 26 | return MCPManagerSingleton.instance; |
| 26 | 27 | } |
| 27 | 28 | |
| 29 | + addDisconnectedServer(serverId: string) { | |
| 30 | + this.disconnectedServers.push(serverId); | |
| 31 | + } | |
| 32 | + removeDisconnectedServer(serverId: string) { | |
| 33 | + this.disconnectedServers = this.disconnectedServers.filter( | |
| 34 | + (server) => server !== serverId, | |
| 35 | + ); | |
| 36 | + } | |
| 37 | + getDisconnectedServers() { | |
| 38 | + return this.disconnectedServers; | |
| 39 | + } | |
| 40 | + | |
| 28 | 41 | createConnection(id: string, options: MCPOptions): MCPConnection { |
| 29 | 42 | if (this.connections.has(id)) { |
| 30 | 43 | return this.connections.get(id)!; |
| @@ -163,9 +176,19 @@ | ||
| 163 | 176 | }), |
| 164 | 177 | (async () => { |
| 165 | 178 | await Promise.all( |
| 166 | - Array.from(this.connections.values()).map(async (connection) => { | |
| 167 | - await connection.connectClient(force, this.abortController.signal); | |
| 168 | - }), | |
| 179 | + Array.from(this.connections.values()) | |
| 180 | + .filter( | |
| 181 | + (connection) => | |
| 182 | + !this.disconnectedServers.some( | |
| 183 | + (s) => s === connection.options.id, | |
| 184 | + ), | |
| 185 | + ) | |
| 186 | + .map(async (connection) => { | |
| 187 | + await connection.connectClient( | |
| 188 | + force, | |
| 189 | + this.abortController.signal, | |
| 190 | + ); | |
| 191 | + }), | |
| 169 | 192 | ); |
| 170 | 193 | if (this.onConnectionsRefreshed) { |
| 171 | 194 | this.onConnectionsRefreshed(); |
modified core/core.ts +14 −0
| @@ -492,6 +492,20 @@ | ||
| 492 | 492 | |
| 493 | 493 | on("mcp/reloadServer", async (msg) => { |
| 494 | 494 | await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id); |
| 495 | + MCPManagerSingleton.getInstance().removeDisconnectedServer(msg.data.id); | |
| 496 | + }); | |
| 497 | + on("mcp/disconnectServer", async (msg) => { | |
| 498 | + const mcpConnection = MCPManagerSingleton.getInstance().getConnection( | |
| 499 | + msg.data.id, | |
| 500 | + ); | |
| 501 | + if (!mcpConnection) | |
| 502 | + throw new Error(`MCP connection with id ${msg.data.id} not found`); | |
| 503 | + MCPManagerSingleton.getInstance().addDisconnectedServer(msg.data.id); | |
| 504 | + await mcpConnection.disconnect(); | |
| 505 | + await this.configHandler.refreshAll("MCP Servers disconnected"); | |
| 506 | + }); | |
| 507 | + on("mcp/getDisconnectedServers", async (_msg) => { | |
| 508 | + return MCPManagerSingleton.getInstance().getDisconnectedServers(); | |
| 495 | 509 | }); |
| 496 | 510 | on("mcp/getPrompt", async (msg) => { |
| 497 | 511 | const { serverName, promptName, args } = msg.data; |
modified core/protocol/core.ts +2 −0
| @@ -148,6 +148,8 @@ | ||
| 148 | 148 | }, |
| 149 | 149 | void, |
| 150 | 150 | ]; |
| 151 | + "mcp/disconnectServer": [{ id: string }, void]; | |
| 152 | + "mcp/getDisconnectedServers": [undefined, string[]]; | |
| 151 | 153 | "mcp/getPrompt": [ |
| 152 | 154 | { |
| 153 | 155 | serverName: string; |
modified core/protocol/passThrough.ts +2 −0
| @@ -32,6 +32,8 @@ | ||
| 32 | 32 | "mcp/getPrompt", |
| 33 | 33 | "mcp/startAuthentication", |
| 34 | 34 | "mcp/removeAuthentication", |
| 35 | + "mcp/disconnectServer", | |
| 36 | + "mcp/getDisconnectedServers", | |
| 35 | 37 | "context/getContextItems", |
| 36 | 38 | "context/getSymbolsForFiles", |
| 37 | 39 | "context/loadSubmenuItems", |
modified gui/src/pages/config/hooks/useToolPolicies.ts +1 −1
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | case "chat": |
| 46 | 46 | return "All tools disabled in Chat, switch to Plan or Agent mode to use tools"; |
| 47 | 47 | case "plan": |
| 48 | - return "Read-only/MCP tools available in Plan mode"; | |
| 48 | + return "Read-only tools available in Plan mode"; | |
| 49 | 49 | default: |
| 50 | 50 | return ""; |
| 51 | 51 | } |
modified gui/src/pages/config/sections/ToolsSection.tsx +136 −41
| @@ -4,16 +4,27 @@ | ||
| 4 | 4 | ChevronDownIcon, |
| 5 | 5 | CircleStackIcon, |
| 6 | 6 | CommandLineIcon, |
| 7 | + EllipsisVerticalIcon, | |
| 7 | 8 | GlobeAltIcon, |
| 9 | + PlayCircleIcon, | |
| 10 | + StopCircleIcon, | |
| 8 | 11 | UserCircleIcon, |
| 9 | 12 | WrenchScrewdriverIcon, |
| 10 | 13 | } from "@heroicons/react/24/outline"; |
| 11 | -import { MCPServerStatus } from "core"; | |
| 12 | -import { useContext, useMemo, useState } from "react"; | |
| 14 | +import { MCPConnectionStatus, MCPServerStatus } from "core"; | |
| 15 | +import { useContext, useEffect, useMemo, useState } from "react"; | |
| 13 | 16 | import Alert from "../../../components/gui/Alert"; |
| 14 | 17 | import { ToolTip } from "../../../components/gui/Tooltip"; |
| 15 | 18 | import EditBlockButton from "../../../components/mainInput/Lump/EditBlockButton"; |
| 16 | -import { Button, Card, EmptyState } from "../../../components/ui"; | |
| 19 | +import { | |
| 20 | + Button, | |
| 21 | + Card, | |
| 22 | + EmptyState, | |
| 23 | + Listbox, | |
| 24 | + ListboxButton, | |
| 25 | + ListboxOption, | |
| 26 | + ListboxOptions, | |
| 27 | +} from "../../../components/ui"; | |
| 17 | 28 | import { useAuth } from "../../../context/Auth"; |
| 18 | 29 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 19 | 30 | import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; |
| @@ -27,14 +38,32 @@ | ||
| 27 | 38 | serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number]; |
| 28 | 39 | } |
| 29 | 40 | |
| 41 | +const ServerStatusTooltip: Record<MCPConnectionStatus, string> = { | |
| 42 | + connected: "Active", | |
| 43 | + connecting: "Connecting", | |
| 44 | + "not-connected": "Inactive", | |
| 45 | + authenticating: "Authenticating", | |
| 46 | + error: "Error", | |
| 47 | +}; | |
| 48 | + | |
| 49 | +const ServerStatusColor: Record<MCPConnectionStatus, string> = { | |
| 50 | + connected: "bg-success", | |
| 51 | + connecting: "bg-warning", | |
| 52 | + "not-connected": "bg-description-muted", | |
| 53 | + authenticating: "bg-warning", | |
| 54 | + error: "bg-error", | |
| 55 | +}; | |
| 56 | + | |
| 30 | 57 | function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { |
| 31 | 58 | const [expandedSections, setExpandedSections] = useState<{ |
| 32 | 59 | [key: string]: boolean; |
| 33 | 60 | }>({}); |
| 61 | + const [disconnectedMCPServers, setDisconnectedMCPServers] = useState< | |
| 62 | + string[] | |
| 63 | + >([]); | |
| 34 | 64 | const ideMessenger = useContext(IdeMessengerContext); |
| 35 | 65 | const config = useAppSelector((store) => store.config.config); |
| 36 | 66 | const dispatch = useAppDispatch(); |
| 37 | - | |
| 38 | 67 | const updateMCPServerStatus = (status: MCPServerStatus["status"]) => { |
| 39 | 68 | // optimistic config update |
| 40 | 69 | dispatch( |
| @@ -64,9 +93,35 @@ | ||
| 64 | 93 | |
| 65 | 94 | const onRefresh = async () => { |
| 66 | 95 | updateMCPServerStatus("connecting"); |
| 67 | - ideMessenger.post("mcp/reloadServer", { | |
| 96 | + await ideMessenger.request("mcp/reloadServer", { | |
| 97 | + id: server.id, | |
| 98 | + }); | |
| 99 | + await fetchDisconectedMCPServers(); | |
| 100 | + }; | |
| 101 | + | |
| 102 | + const onDisconnect = async () => { | |
| 103 | + updateMCPServerStatus("not-connected"); | |
| 104 | + setDisconnectedMCPServers((prev) => [...prev, server.id]); | |
| 105 | + dispatch( | |
| 106 | + updateConfig({ | |
| 107 | + ...config, | |
| 108 | + tools: config.tools.filter((tool) => tool.group !== server.id), | |
| 109 | + }), | |
| 110 | + ); | |
| 111 | + await ideMessenger.request("mcp/disconnectServer", { | |
| 68 | 112 | id: server.id, |
| 69 | 113 | }); |
| 114 | + await fetchDisconectedMCPServers(); | |
| 115 | + }; | |
| 116 | + | |
| 117 | + const fetchDisconectedMCPServers = async () => { | |
| 118 | + const disconnectedServersData = await ideMessenger.request( | |
| 119 | + "mcp/getDisconnectedServers", | |
| 120 | + undefined, | |
| 121 | + ); | |
| 122 | + if (disconnectedServersData.status === "success") { | |
| 123 | + setDisconnectedMCPServers(disconnectedServersData.content); | |
| 124 | + } | |
| 70 | 125 | }; |
| 71 | 126 | |
| 72 | 127 | const toggleSection = (section: string) => { |
| @@ -76,6 +131,8 @@ | ||
| 76 | 131 | })); |
| 77 | 132 | }; |
| 78 | 133 | |
| 134 | + useEffect(() => void fetchDisconectedMCPServers(), []); | |
| 135 | + | |
| 79 | 136 | const ResourceRow = ({ |
| 80 | 137 | title, |
| 81 | 138 | items, |
| @@ -83,7 +140,11 @@ | ||
| 83 | 140 | sectionKey, |
| 84 | 141 | }: { |
| 85 | 142 | title: string; |
| 86 | - items: any[]; | |
| 143 | + items: | |
| 144 | + | MCPServerStatus["tools"] | |
| 145 | + | MCPServerStatus["prompts"] | |
| 146 | + | MCPServerStatus["resources"] | |
| 147 | + | MCPServerStatus["resourceTemplates"]; | |
| 87 | 148 | icon: React.ReactNode; |
| 88 | 149 | sectionKey: string; |
| 89 | 150 | }) => { |
| @@ -146,23 +207,17 @@ | ||
| 146 | 207 | <div className="flex-1"> |
| 147 | 208 | <div className="flex items-center gap-3"> |
| 148 | 209 | <h3 className="my-0 text-sm font-medium">{server.name}</h3> |
| 149 | - <div | |
| 150 | - className={`h-2 w-2 flex-shrink-0 rounded-full ${ | |
| 151 | - server.status === "connected" | |
| 152 | - ? "bg-success" | |
| 153 | - : server.status === "connecting" | |
| 154 | - ? "bg-warning" | |
| 155 | - : server.status === "not-connected" | |
| 156 | - ? "bg-description-muted" | |
| 157 | - : "bg-error" | |
| 158 | - }`} | |
| 159 | - /> | |
| 210 | + <ToolTip content={ServerStatusTooltip[server.status] ?? "Error"}> | |
| 211 | + <div | |
| 212 | + className={`h-2 w-2 flex-shrink-0 rounded-full ${ServerStatusColor[server.status] ?? "bg-error"}`} | |
| 213 | + /> | |
| 214 | + </ToolTip> | |
| 160 | 215 | </div> |
| 161 | 216 | </div> |
| 162 | 217 | </div> |
| 163 | 218 | |
| 164 | 219 | <div className="-mr-2.5 flex items-center gap-1"> |
| 165 | - {server.isProtectedResource && ( | |
| 220 | + {server.isProtectedResource && server.status !== "connected" && ( | |
| 166 | 221 | <ToolTip |
| 167 | 222 | content={ |
| 168 | 223 | server.status === "error" |
| @@ -182,7 +237,7 @@ | ||
| 182 | 237 | } |
| 183 | 238 | variant="ghost" |
| 184 | 239 | size="sm" |
| 185 | - className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 240 | + className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0 pt-0.5" | |
| 186 | 241 | disabled={server.status === "authenticating"} |
| 187 | 242 | > |
| 188 | 243 | {server.status === "authenticating" ? ( |
| @@ -193,27 +248,59 @@ | ||
| 193 | 248 | </Button> |
| 194 | 249 | </ToolTip> |
| 195 | 250 | )} |
| 196 | - | |
| 197 | - <ToolTip content="Edit server configuration"> | |
| 198 | - <div> | |
| 199 | - <EditBlockButton | |
| 200 | - blockType={"mcpServers"} | |
| 201 | - block={serverFromYaml} | |
| 202 | - sourceFile={server.sourceFile} | |
| 203 | - /> | |
| 204 | - </div> | |
| 205 | - </ToolTip> | |
| 206 | - | |
| 207 | - <ToolTip content="Refresh server"> | |
| 208 | - <Button | |
| 209 | - onClick={onRefresh} | |
| 210 | - variant="ghost" | |
| 211 | - size="sm" | |
| 212 | - className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0" | |
| 213 | - > | |
| 214 | - <ArrowPathIcon className="h-4 w-4 flex-shrink-0" /> | |
| 215 | - </Button> | |
| 216 | - </ToolTip> | |
| 251 | + <Listbox> | |
| 252 | + <ListboxButton> | |
| 253 | + <EllipsisVerticalIcon className="h-4 w-4 flex-shrink-0" /> | |
| 254 | + </ListboxButton> | |
| 255 | + <ListboxOptions className="min-w-fit" anchor="bottom end"> | |
| 256 | + {server.isProtectedResource && server.status === "connected" && ( | |
| 257 | + <ListboxOption | |
| 258 | + value="remove auth" | |
| 259 | + onClick={onRemoveAuth} | |
| 260 | + className="justify-start gap-x-1.5" | |
| 261 | + > | |
| 262 | + <UserCircleIcon className="h-4 w-4 flex-shrink-0" /> Logout | |
| 263 | + </ListboxOption> | |
| 264 | + )} | |
| 265 | + | |
| 266 | + <ListboxOption | |
| 267 | + value="edit mcp" | |
| 268 | + className="justify-start gap-x-1.5" | |
| 269 | + > | |
| 270 | + <EditBlockButton | |
| 271 | + blockType={"mcpServers"} | |
| 272 | + block={serverFromYaml} | |
| 273 | + sourceFile={server.sourceFile} | |
| 274 | + className="h-3.5 w-3.5 text-inherit" | |
| 275 | + /> | |
| 276 | + Edit | |
| 277 | + </ListboxOption> | |
| 278 | + | |
| 279 | + {!disconnectedMCPServers.includes(server.name) && ( | |
| 280 | + <ListboxOption | |
| 281 | + value="disconnect" | |
| 282 | + onClick={onDisconnect} | |
| 283 | + className="justify-start gap-x-1.5" | |
| 284 | + > | |
| 285 | + <StopCircleIcon className="h-4 w-4 flex-shrink-0" />{" "} | |
| 286 | + Disconnect | |
| 287 | + </ListboxOption> | |
| 288 | + )} | |
| 289 | + | |
| 290 | + <ListboxOption | |
| 291 | + value="reconnect" | |
| 292 | + onClick={onRefresh} | |
| 293 | + className="justify-start gap-x-1.5" | |
| 294 | + > | |
| 295 | + {disconnectedMCPServers.includes(server.name) ? ( | |
| 296 | + <PlayCircleIcon className="h-4 w-4 flex-shrink-0" /> | |
| 297 | + ) : ( | |
| 298 | + <ArrowPathIcon className="h-4 w-4 flex-shrink-0" /> | |
| 299 | + )} | |
| 300 | + Reload | |
| 301 | + </ListboxOption> | |
| 302 | + </ListboxOptions> | |
| 303 | + </Listbox> | |
| 217 | 304 | </div> |
| 218 | 305 | </div> |
| 219 | 306 | |
| @@ -294,6 +381,7 @@ | ||
| 294 | 381 | |
| 295 | 382 | function McpSubsection() { |
| 296 | 383 | const currentOrg = useAppSelector(selectCurrentOrg); |
| 384 | + const mode = useAppSelector((store) => store.session.mode); | |
| 297 | 385 | const servers = useAppSelector( |
| 298 | 386 | (store) => store.config.config.mcpServerStatuses, |
| 299 | 387 | ); |
| @@ -317,7 +405,7 @@ | ||
| 317 | 405 | .map((server) => [server.name, server]) ?? [], |
| 318 | 406 | ); |
| 319 | 407 | |
| 320 | - return (servers ?? []).map((doc) => ({ | |
| 408 | + return (servers ?? []).map((doc: MCPServerStatus) => ({ | |
| 321 | 409 | block: doc, |
| 322 | 410 | blockFromYaml: yamlServersByName.get(doc.name), |
| 323 | 411 | })); |
| @@ -348,6 +436,13 @@ | ||
| 348 | 436 | <Card> |
| 349 | 437 | <EmptyState message="MCP servers are disabled in your organization" /> |
| 350 | 438 | </Card> |
| 439 | + ) : mode === "chat" ? ( | |
| 440 | + <Alert type="info" size="sm"> | |
| 441 | + <span className="text-2xs italic"> | |
| 442 | + All MCPs are disabled in Chat, switch to Plan or Agent mode to use | |
| 443 | + MCPs | |
| 444 | + </span> | |
| 445 | + </Alert> | |
| 351 | 446 | ) : mergedBlocks.length > 0 ? ( |
| 352 | 447 | mergedBlocks.map(({ block, blockFromYaml }, index) => ( |
| 353 | 448 | <div key={block.id}> |