diff --git a/bin/cli.js b/bin/cli.js index 460ce58..ca1958a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -7,7 +7,7 @@ import { fileURLToPath } from "url"; const __dirname = dirname(fileURLToPath(import.meta.url)); function delay(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms, true)); } async function main() { @@ -73,42 +73,40 @@ async function main() { cancelled = true; abort.abort(); }); - - const server = spawnPromise( - "node", - [ - inspectorServerPath, - ...(command ? [`--env`, command] : []), - ...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []), - ], - { - env: { - ...process.env, - PORT: SERVER_PORT, - MCP_ENV_VARS: JSON.stringify(envVars), - }, - signal: abort.signal, - echoOutput: true, - }, - ); - - const client = spawnPromise("node", [inspectorClientPath], { - env: { ...process.env, PORT: CLIENT_PORT }, - signal: abort.signal, - echoOutput: true, - }); - - // Make sure our server/client didn't immediately fail - await Promise.any([server, client, delay(2 * 1000)]); - const portParam = SERVER_PORT === "6277" ? "" : `?proxyPort=${SERVER_PORT}`; - console.log( - `\nš MCP Inspector is up and running at http://127.0.0.1:${CLIENT_PORT}${portParam} š`, - ); - + let server, serverOk; try { - await Promise.any([server, client]); - } catch (e) { - if (!cancelled || process.env.DEBUG) throw e; + server = spawnPromise( + "node", + [ + inspectorServerPath, + ...(command ? [`--env`, command] : []), + ...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []), + ], + { + env: { + ...process.env, + PORT: SERVER_PORT, + MCP_ENV_VARS: JSON.stringify(envVars), + }, + signal: abort.signal, + echoOutput: true, + }, + ); + + // Make sure server started before starting client + serverOk = await Promise.race([server, delay(2 * 1000)]); + } catch (error) {} + + if (serverOk) { + try { + await spawnPromise("node", [inspectorClientPath], { + env: { ...process.env, PORT: CLIENT_PORT }, + signal: abort.signal, + echoOutput: true, + }); + } catch (e) { + if (!cancelled || process.env.DEBUG) throw e; + } } return 0; @@ -119,4 +117,4 @@ main() .catch((e) => { console.error(e); process.exit(1); - }); + }); \ No newline at end of file diff --git a/client/bin/cli.js b/client/bin/cli.js index 81b7bd1..d30cc70 100755 --- a/client/bin/cli.js +++ b/client/bin/cli.js @@ -16,4 +16,18 @@ const server = http.createServer((request, response) => { }); const port = process.env.PORT || 6274; -server.listen(port, () => {}); +server.on("listening", () => { + console.log( + `š MCP Inspector is up and running at http://127.0.0.1:${port} š`, + ); +}); +server.on("error", (err) => { + if (err.message.includes(`EADDRINUSE`)) { + console.error( + `ā MCP Inspector PORT IS IN USE at http://127.0.0.1:${port} ā `, + ); + } else { + throw err; + } +}); +server.listen(port); diff --git a/client/package.json b/client/package.json index 9eff88c..c268c33 100644 --- a/client/package.json +++ b/client/package.json @@ -18,7 +18,7 @@ "dev": "vite", "build": "tsc -b && vite build", "lint": "eslint .", - "preview": "vite preview", + "preview": "vite preview --port 5173", "test": "jest --config jest.config.cjs", "test:watch": "jest --config jest.config.cjs --watch" }, diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index ca6d5fe..33e88a7 100644 --- a/client/src/components/Sidebar.tsx +++ b/client/src/components/Sidebar.tsx @@ -8,6 +8,7 @@ import { Github, Eye, EyeOff, + RotateCcw, Settings, } from "lucide-react"; import { Button } from "@/components/ui/button"; @@ -375,8 +376,17 @@ const Sidebar = ({