Skip to content

Commit affd207

Browse files
authored
Merge pull request modelcontextprotocol#238 from max-stytch/feat/disconnect
feat: Add lightweight Disconnect button
2 parents d127ee8 + 4afe2d6 commit affd207

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

client/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const App = () => {
145145
handleCompletion,
146146
completionsSupported,
147147
connect: connectMcpServer,
148+
disconnect: disconnectMcpServer,
148149
} = useConnection({
149150
transportType,
150151
command,
@@ -458,6 +459,7 @@ const App = () => {
458459
bearerToken={bearerToken}
459460
setBearerToken={setBearerToken}
460461
onConnect={connectMcpServer}
462+
onDisconnect={disconnectMcpServer}
461463
stdErrNotifications={stdErrNotifications}
462464
logLevel={logLevel}
463465
sendLogLevelRequest={sendLogLevelRequest}

client/src/components/Sidebar.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EyeOff,
1111
RotateCcw,
1212
Settings,
13+
RefreshCwOff,
1314
} from "lucide-react";
1415
import { Button } from "@/components/ui/button";
1516
import { Input } from "@/components/ui/input";
@@ -45,6 +46,7 @@ interface SidebarProps {
4546
bearerToken: string;
4647
setBearerToken: (token: string) => void;
4748
onConnect: () => void;
49+
onDisconnect: () => void;
4850
stdErrNotifications: StdErrNotification[];
4951
logLevel: LoggingLevel;
5052
sendLogLevelRequest: (level: LoggingLevel) => void;
@@ -68,6 +70,7 @@ const Sidebar = ({
6870
bearerToken,
6971
setBearerToken,
7072
onConnect,
73+
onDisconnect,
7174
stdErrNotifications,
7275
logLevel,
7376
sendLogLevelRequest,
@@ -375,19 +378,24 @@ const Sidebar = ({
375378
</div>
376379

377380
<div className="space-y-2">
378-
<Button className="w-full" onClick={onConnect}>
379-
{connectionStatus === "connected" ? (
380-
<>
381+
{connectionStatus === "connected" && (
382+
<div className="grid grid-cols-2 gap-4">
383+
<Button onClick={onConnect}>
381384
<RotateCcw className="w-4 h-4 mr-2" />
382385
{transportType === "stdio" ? "Restart" : "Reconnect"}
383-
</>
384-
) : (
385-
<>
386-
<Play className="w-4 h-4 mr-2" />
387-
Connect
388-
</>
389-
)}
390-
</Button>
386+
</Button>
387+
<Button onClick={onDisconnect}>
388+
<RefreshCwOff className="w-4 h-4 mr-2" />
389+
Disconnect
390+
</Button>
391+
</div>
392+
)}
393+
{connectionStatus !== "connected" && (
394+
<Button className="w-full" onClick={onConnect}>
395+
<Play className="w-4 h-4 mr-2" />
396+
Connect
397+
</Button>
398+
)}
391399

392400
<div className="flex items-center justify-center space-x-2 mb-4">
393401
<div

client/src/components/__tests__/Sidebar.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("Sidebar Environment Variables", () => {
2626
bearerToken: "",
2727
setBearerToken: jest.fn(),
2828
onConnect: jest.fn(),
29+
onDisconnect: jest.fn(),
2930
stdErrNotifications: [],
3031
logLevel: "info" as const,
3132
sendLogLevelRequest: jest.fn(),

client/src/lib/hooks/useConnection.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ export function useConnection({
321321
}
322322
};
323323

324+
const disconnect = async () => {
325+
await mcpClient?.close();
326+
setMcpClient(null);
327+
setConnectionStatus("disconnected");
328+
setCompletionsSupported(false);
329+
setServerCapabilities(null);
330+
};
331+
324332
return {
325333
connectionStatus,
326334
serverCapabilities,
@@ -331,5 +339,6 @@ export function useConnection({
331339
handleCompletion,
332340
completionsSupported,
333341
connect,
342+
disconnect,
334343
};
335344
}

0 commit comments

Comments
 (0)