diff --git a/bin/cli.js b/bin/cli.js index ced2099..55caefd 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -6,6 +6,10 @@ import { fileURLToPath } from "url"; const __dirname = dirname(fileURLToPath(import.meta.url)); +function delay(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + async function main() { // Get command line arguments const [, , command, ...mcpServerArgs] = process.argv; @@ -64,7 +68,7 @@ async function main() { try { await Promise.any([server, client]); } catch (e) { - if (!cancelled) throw e; + if (!cancelled || process.env.DEBUG) throw e; } return 0; diff --git a/server/src/index.ts b/server/src/index.ts index 9a200eb..6489fb0 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -39,6 +39,7 @@ const createTransport = async (query: express.Request["query"]) => { const command = query.command as string; const args = (query.args as string).split(/\s+/); const env = query.env ? JSON.parse(query.env as string) : undefined; + console.log( `Stdio transport: command=${command}, args=${args}, env=${JSON.stringify(env)}`, ); @@ -48,14 +49,18 @@ const createTransport = async (query: express.Request["query"]) => { env, stderr: "pipe", }); + await transport.start(); + console.log("Spawned stdio transport"); return transport; } else if (transportType === "sse") { const url = query.url as string; console.log(`SSE transport: url=${url}`); + const transport = new SSEClientTransport(new URL(url)); await transport.start(); + console.log("Connected to SSE transport"); return transport; } else { @@ -99,6 +104,7 @@ app.get("/sse", async (req, res) => { console.error(error); }, }); + console.log("Set up MCP proxy"); } catch (error) { console.error("Error in /sse route:", error); @@ -126,6 +132,7 @@ app.post("/message", async (req, res) => { app.get("/config", (req, res) => { try { const defaultEnvironment = getDefaultEnvironment(); + res.json({ defaultEnvironment, defaultCommand: values.env, @@ -138,4 +145,4 @@ app.get("/config", (req, res) => { }); const PORT = process.env.PORT || 3000; -app.listen(PORT, () => { }); +app.listen(PORT, () => {});