Skip to content

Commit 2f85430

Browse files
authored
Merge pull request modelcontextprotocol#216 from Skn0tt/cleanup-old-transports
fix: clean up previous transport processes
2 parents 6b63bac + fb29ca0 commit 2f85430

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

client/src/components/Sidebar.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Github,
99
Eye,
1010
EyeOff,
11+
RotateCcw,
1112
Settings,
1213
} from "lucide-react";
1314
import { Button } from "@/components/ui/button";
@@ -375,8 +376,17 @@ const Sidebar = ({
375376

376377
<div className="space-y-2">
377378
<Button className="w-full" onClick={onConnect}>
378-
<Play className="w-4 h-4 mr-2" />
379-
Connect
379+
{connectionStatus === "connected" ? (
380+
<>
381+
<RotateCcw className="w-4 h-4 mr-2" />
382+
{transportType === "stdio" ? "Restart" : "Reconnect"}
383+
</>
384+
) : (
385+
<>
386+
<Play className="w-4 h-4 mr-2" />
387+
Connect
388+
</>
389+
)}
380390
</Button>
381391

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

server/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
StdioClientTransport,
1313
getDefaultEnvironment,
1414
} from "@modelcontextprotocol/sdk/client/stdio.js";
15+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
1516
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
1617
import express from "express";
1718
import { findActualExecutable } from "spawn-rx";
@@ -98,12 +99,14 @@ const createTransport = async (req: express.Request) => {
9899
}
99100
};
100101

102+
let backingServerTransport: Transport | undefined;
103+
101104
app.get("/sse", async (req, res) => {
102105
try {
103106
console.log("New SSE connection");
104107

105-
let backingServerTransport;
106108
try {
109+
await backingServerTransport?.close();
107110
backingServerTransport = await createTransport(req);
108111
} catch (error) {
109112
if (error instanceof SseError && error.code === 401) {

0 commit comments

Comments
 (0)