extract transport logic
This commit is contained in:
@@ -6,6 +6,7 @@ import ListPane from "./ListPane";
|
|||||||
|
|
||||||
export type Resource = {
|
export type Resource = {
|
||||||
uri: string;
|
uri: string;
|
||||||
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ResourcesTab = ({
|
const ResourcesTab = ({
|
||||||
@@ -37,7 +38,7 @@ const ResourcesTab = ({
|
|||||||
<div className="flex items-center w-full">
|
<div className="flex items-center w-full">
|
||||||
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
<FileText className="w-4 h-4 mr-2 flex-shrink-0 text-gray-500" />
|
||||||
<span className="flex-1 truncate" title={resource.uri}>
|
<span className="flex-1 truncate" title={resource.uri}>
|
||||||
{resource.uri}
|
{resource.name}
|
||||||
</span>
|
</span>
|
||||||
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
<ChevronRight className="w-4 h-4 flex-shrink-0 text-gray-400" />
|
||||||
</div>
|
</div>
|
||||||
@@ -48,8 +49,8 @@ const ResourcesTab = ({
|
|||||||
|
|
||||||
<div className="bg-white rounded-lg shadow">
|
<div className="bg-white rounded-lg shadow">
|
||||||
<div className="p-4 border-b border-gray-200 flex justify-between items-center">
|
<div className="p-4 border-b border-gray-200 flex justify-between items-center">
|
||||||
<h3 className="font-semibold truncate" title={selectedResource?.uri}>
|
<h3 className="font-semibold truncate" title={selectedResource?.name}>
|
||||||
{selectedResource ? selectedResource.uri : "Select a resource"}
|
{selectedResource ? selectedResource.name : "Select a resource"}
|
||||||
</h3>
|
</h3>
|
||||||
{selectedResource && (
|
{selectedResource && (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -16,33 +16,44 @@ app.use(cors());
|
|||||||
|
|
||||||
let webAppTransports: SSEServerTransport[] = [];
|
let webAppTransports: SSEServerTransport[] = [];
|
||||||
|
|
||||||
|
const createTransport = async (query: express.Request["query"]) => {
|
||||||
|
console.log("Query parameters:", query);
|
||||||
|
|
||||||
|
const transportType = query.transportType as string;
|
||||||
|
|
||||||
|
if (transportType === "stdio") {
|
||||||
|
const command = decodeURIComponent(query.command as string);
|
||||||
|
const args = decodeURIComponent(query.args as string).split(",");
|
||||||
|
console.log(`Stdio transport: command=${command}, args=${args}`);
|
||||||
|
const transport = new StdioClientTransport();
|
||||||
|
await transport.spawn({ command, args });
|
||||||
|
console.log("Spawned stdio transport");
|
||||||
|
return transport;
|
||||||
|
} else if (transportType === "sse") {
|
||||||
|
const url = decodeURIComponent(query.url as string);
|
||||||
|
console.log(`SSE transport: url=${url}`);
|
||||||
|
const transport = new SSEClientTransport();
|
||||||
|
await transport.connect(new URL(url));
|
||||||
|
console.log("Connected to SSE transport");
|
||||||
|
return transport;
|
||||||
|
} else {
|
||||||
|
console.error(`Invalid transport type: ${transportType}`);
|
||||||
|
throw new Error("Invalid transport type specified");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
app.get("/sse", async (req, res) => {
|
app.get("/sse", async (req, res) => {
|
||||||
console.log("New SSE connection");
|
console.log("New SSE connection");
|
||||||
const transportType = req.query.transportType as string;
|
const transportType = req.query.transportType as string;
|
||||||
console.log(`Transport type: ${transportType}`);
|
console.log(`Transport type: ${transportType}`);
|
||||||
|
|
||||||
let backingServerTransport;
|
const backingServerTransport = await createTransport(req.query);
|
||||||
console.log("Query parameters:", req.query);
|
|
||||||
|
|
||||||
if (transportType === "stdio") {
|
console.log("Connected MCP client to backing server transport");
|
||||||
const command = decodeURIComponent(req.query.command as string);
|
|
||||||
const args = decodeURIComponent(req.query.args as string).split(",");
|
|
||||||
console.log(`Stdio transport: command=${command}, args=${args}`);
|
|
||||||
backingServerTransport = new StdioClientTransport();
|
|
||||||
await backingServerTransport.spawn({ command, args });
|
|
||||||
console.log("Spawned stdio transport");
|
|
||||||
} else if (transportType === "sse") {
|
|
||||||
const url = decodeURIComponent(req.query.url as string);
|
|
||||||
console.log(`SSE transport: url=${url}`);
|
|
||||||
backingServerTransport = new SSEClientTransport();
|
|
||||||
await backingServerTransport.connect(new URL(url));
|
|
||||||
console.log("Connected to SSE transport");
|
|
||||||
} else {
|
|
||||||
console.error(`Invalid transport type: ${transportType}`);
|
|
||||||
throw new Error("Invalid transport type specified");
|
|
||||||
}
|
|
||||||
|
|
||||||
const webAppTransport = new SSEServerTransport("/message");
|
const webAppTransport = new SSEServerTransport("/message");
|
||||||
|
console.log("Created web app transport");
|
||||||
|
|
||||||
webAppTransports.push(webAppTransport);
|
webAppTransports.push(webAppTransport);
|
||||||
console.log("Created web app transport");
|
console.log("Created web app transport");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user