Skip to content

Commit 14da479

Browse files
committed
extract transport logic
1 parent 02bfd16 commit 14da479

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

client/src/components/ResourcesTab.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ListPane from "./ListPane";
66

77
export type Resource = {
88
uri: string;
9+
name: string;
910
};
1011

1112
const ResourcesTab = ({
@@ -37,7 +38,7 @@ const ResourcesTab = ({
3738
<div className="flex items-center w-full">
3839
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
3940
<span className="flex-1 truncate" title={resource.uri}>
40-
{resource.uri}
41+
{resource.name}
4142
</span>
4243
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
4344
</div>
@@ -48,8 +49,8 @@ const ResourcesTab = ({
4849

4950
<div className="bg-white rounded-lg shadow">
5051
<div className="p-4 border-b border-gray-200 flex justify-between items-center">
51-
<h3 className="font-semibold truncate" title={selectedResource?.uri}>
52-
{selectedResource ? selectedResource.uri : "Select a resource"}
52+
<h3 className="font-semibold truncate" title={selectedResource?.name}>
53+
{selectedResource ? selectedResource.name : "Select a resource"}
5354
</h3>
5455
{selectedResource && (
5556
<Button

server/src/index.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,44 @@ app.use(cors());
1616

1717
let webAppTransports: SSEServerTransport[] = [];
1818

19-
app.get("/sse", async (req, res) => {
20-
console.log("New SSE connection");
21-
const transportType = req.query.transportType as string;
22-
console.log(`Transport type: ${transportType}`);
19+
const createTransport = async (query: express.Request["query"]) => {
20+
console.log("Query parameters:", query);
2321

24-
let backingServerTransport;
25-
console.log("Query parameters:", req.query);
22+
const transportType = query.transportType as string;
2623

2724
if (transportType === "stdio") {
28-
const command = decodeURIComponent(req.query.command as string);
29-
const args = decodeURIComponent(req.query.args as string).split(",");
25+
const command = decodeURIComponent(query.command as string);
26+
const args = decodeURIComponent(query.args as string).split(",");
3027
console.log(`Stdio transport: command=${command}, args=${args}`);
31-
backingServerTransport = new StdioClientTransport();
32-
await backingServerTransport.spawn({ command, args });
28+
const transport = new StdioClientTransport();
29+
await transport.spawn({ command, args });
3330
console.log("Spawned stdio transport");
31+
return transport;
3432
} else if (transportType === "sse") {
35-
const url = decodeURIComponent(req.query.url as string);
33+
const url = decodeURIComponent(query.url as string);
3634
console.log(`SSE transport: url=${url}`);
37-
backingServerTransport = new SSEClientTransport();
38-
await backingServerTransport.connect(new URL(url));
35+
const transport = new SSEClientTransport();
36+
await transport.connect(new URL(url));
3937
console.log("Connected to SSE transport");
38+
return transport;
4039
} else {
4140
console.error(`Invalid transport type: ${transportType}`);
4241
throw new Error("Invalid transport type specified");
4342
}
43+
};
44+
45+
app.get("/sse", async (req, res) => {
46+
console.log("New SSE connection");
47+
const transportType = req.query.transportType as string;
48+
console.log(`Transport type: ${transportType}`);
49+
50+
const backingServerTransport = await createTransport(req.query);
51+
52+
console.log("Connected MCP client to backing server transport");
4453

4554
const webAppTransport = new SSEServerTransport("/message");
55+
console.log("Created web app transport");
56+
4657
webAppTransports.push(webAppTransport);
4758
console.log("Created web app transport");
4859

0 commit comments

Comments
 (0)