Elffuss BraidHub

kikocis/continue public

feat: better mcp connection status (#7830)

* add tooltips for showing mcp connection status

* add type

* explicit message to clarify no mcps are available in chat mode

* ability to disconnect mcp server

* move buttons inside a kebab menu

* use a listbox instead

* remove server and mcp suffixes
change reconnect to reload

* add anchor
Changeset53ff866ea6e754e7b0d90971b1388d37b9bfb05e0109a105ec20b83721024c9d
AuthorAditya Mitra <61635505+uinstinct@users.noreply.github.com> · 2025-09-24 21:31 +05:30
CommitterGitHub <noreply@github.com> · 2025-09-24 09:01 -07:00
Parentse31fcddb0dec

Browse the files at this changeset

7 files changed

modified core/context/mcp/MCPConnection.ts +1 −0
@@ -85,6 +85,7 @@
8585 }
8686
8787 async disconnect() {
88+ this.status = "not-connected";
8889 this.abortController.abort();
8990 await this.client.close();
9091 await this.transport.close();
modified core/context/mcp/MCPManagerSingleton.ts +26 −3
@@ -13,6 +13,7 @@
1313
1414 public onConnectionsRefreshed?: () => void;
1515 public connections: Map<string, MCPConnection> = new Map();
16+ private disconnectedServers: string[] = [];
1617
1718 private abortController: AbortController = new AbortController();
1819
@@ -25,6 +26,18 @@
2526 return MCPManagerSingleton.instance;
2627 }
2728
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+
2841 createConnection(id: string, options: MCPOptions): MCPConnection {
2942 if (this.connections.has(id)) {
3043 return this.connections.get(id)!;
@@ -163,9 +176,19 @@
163176 }),
164177 (async () => {
165178 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+ }),
169192 );
170193 if (this.onConnectionsRefreshed) {
171194 this.onConnectionsRefreshed();
modified core/core.ts +14 −0
@@ -492,6 +492,20 @@
492492
493493 on("mcp/reloadServer", async (msg) => {
494494 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();
495509 });
496510 on("mcp/getPrompt", async (msg) => {
497511 const { serverName, promptName, args } = msg.data;
modified core/protocol/core.ts +2 −0
@@ -148,6 +148,8 @@
148148 },
149149 void,
150150 ];
151+ "mcp/disconnectServer": [{ id: string }, void];
152+ "mcp/getDisconnectedServers": [undefined, string[]];
151153 "mcp/getPrompt": [
152154 {
153155 serverName: string;
modified core/protocol/passThrough.ts +2 −0
@@ -32,6 +32,8 @@
3232 "mcp/getPrompt",
3333 "mcp/startAuthentication",
3434 "mcp/removeAuthentication",
35+ "mcp/disconnectServer",
36+ "mcp/getDisconnectedServers",
3537 "context/getContextItems",
3638 "context/getSymbolsForFiles",
3739 "context/loadSubmenuItems",
modified gui/src/pages/config/hooks/useToolPolicies.ts +1 −1
@@ -45,7 +45,7 @@
4545 case "chat":
4646 return "All tools disabled in Chat, switch to Plan or Agent mode to use tools";
4747 case "plan":
48- return "Read-only/MCP tools available in Plan mode";
48+ return "Read-only tools available in Plan mode";
4949 default:
5050 return "";
5151 }
modified gui/src/pages/config/sections/ToolsSection.tsx +136 −41
@@ -4,16 +4,27 @@
44 ChevronDownIcon,
55 CircleStackIcon,
66 CommandLineIcon,
7+ EllipsisVerticalIcon,
78 GlobeAltIcon,
9+ PlayCircleIcon,
10+ StopCircleIcon,
811 UserCircleIcon,
912 WrenchScrewdriverIcon,
1013 } 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";
1316 import Alert from "../../../components/gui/Alert";
1417 import { ToolTip } from "../../../components/gui/Tooltip";
1518 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";
1728 import { useAuth } from "../../../context/Auth";
1829 import { IdeMessengerContext } from "../../../context/IdeMessenger";
1930 import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
@@ -27,14 +38,32 @@
2738 serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number];
2839 }
2940
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+
3057 function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) {
3158 const [expandedSections, setExpandedSections] = useState<{
3259 [key: string]: boolean;
3360 }>({});
61+ const [disconnectedMCPServers, setDisconnectedMCPServers] = useState<
62+ string[]
63+ >([]);
3464 const ideMessenger = useContext(IdeMessengerContext);
3565 const config = useAppSelector((store) => store.config.config);
3666 const dispatch = useAppDispatch();
37-
3867 const updateMCPServerStatus = (status: MCPServerStatus["status"]) => {
3968 // optimistic config update
4069 dispatch(
@@ -64,9 +93,35 @@
6493
6594 const onRefresh = async () => {
6695 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", {
68112 id: server.id,
69113 });
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+ }
70125 };
71126
72127 const toggleSection = (section: string) => {
@@ -76,6 +131,8 @@
76131 }));
77132 };
78133
134+ useEffect(() => void fetchDisconectedMCPServers(), []);
135+
79136 const ResourceRow = ({
80137 title,
81138 items,
@@ -83,7 +140,11 @@
83140 sectionKey,
84141 }: {
85142 title: string;
86- items: any[];
143+ items:
144+ | MCPServerStatus["tools"]
145+ | MCPServerStatus["prompts"]
146+ | MCPServerStatus["resources"]
147+ | MCPServerStatus["resourceTemplates"];
87148 icon: React.ReactNode;
88149 sectionKey: string;
89150 }) => {
@@ -146,23 +207,17 @@
146207 <div className="flex-1">
147208 <div className="flex items-center gap-3">
148209 <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>
160215 </div>
161216 </div>
162217 </div>
163218
164219 <div className="-mr-2.5 flex items-center gap-1">
165- {server.isProtectedResource && (
220+ {server.isProtectedResource && server.status !== "connected" && (
166221 <ToolTip
167222 content={
168223 server.status === "error"
@@ -182,7 +237,7 @@
182237 }
183238 variant="ghost"
184239 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"
186241 disabled={server.status === "authenticating"}
187242 >
188243 {server.status === "authenticating" ? (
@@ -193,27 +248,59 @@
193248 </Button>
194249 </ToolTip>
195250 )}
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>
217304 </div>
218305 </div>
219306
@@ -294,6 +381,7 @@
294381
295382 function McpSubsection() {
296383 const currentOrg = useAppSelector(selectCurrentOrg);
384+ const mode = useAppSelector((store) => store.session.mode);
297385 const servers = useAppSelector(
298386 (store) => store.config.config.mcpServerStatuses,
299387 );
@@ -317,7 +405,7 @@
317405 .map((server) => [server.name, server]) ?? [],
318406 );
319407
320- return (servers ?? []).map((doc) => ({
408+ return (servers ?? []).map((doc: MCPServerStatus) => ({
321409 block: doc,
322410 blockFromYaml: yamlServersByName.get(doc.name),
323411 }));
@@ -348,6 +436,13 @@
348436 <Card>
349437 <EmptyState message="MCP servers are disabled in your organization" />
350438 </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>
351446 ) : mergedBlocks.length > 0 ? (
352447 mergedBlocks.map(({ block, blockFromYaml }, index) => (
353448 <div key={block.id}>