Skip to main content
Glama
cli.js2.59 kB
#!/usr/bin/env node import { resolve, dirname } from "path"; import { spawnPromise } from "spawn-rx"; import { fileURLToPath } from "url"; const __dirname = dirname(fileURLToPath(import.meta.url)); function delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } async function main() { // Parse command line arguments const args = process.argv.slice(2); const envVars = {}; const mcpServerArgs = []; let command = null; let parsingFlags = true; for (let i = 0; i < args.length; i++) { const arg = args[i]; if (parsingFlags && arg === "--") { parsingFlags = false; continue; } if (parsingFlags && arg === "-e" && i + 1 < args.length) { const [key, value] = args[++i].split("="); if (key && value) { envVars[key] = value; } } else if (!command) { command = arg; } else { mcpServerArgs.push(arg); } } const inspectorServerPath = resolve( __dirname, "..", "server", "build", "index.js", ); // Path to the client entry point const inspectorClientPath = resolve( __dirname, "..", "client", "bin", "cli.js", ); const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173"; const SERVER_PORT = process.env.SERVER_PORT ?? "3000"; console.log("Starting MCP inspector..."); const abort = new AbortController(); let cancelled = false; process.on("SIGINT", () => { 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 === "3000" ? "" : `?proxyPort=${SERVER_PORT}`; console.log( `\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT}${portParam} 🚀`, ); try { await Promise.any([server, client]); } catch (e) { if (!cancelled || process.env.DEBUG) throw e; } return 0; } main() .then((_) => process.exit(0)) .catch((e) => { console.error(e); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samihalawa/advanced-tts-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server