From c1a56810fb98eace99b553f78c6cb29a16261281 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Tue, 19 Nov 2024 11:42:11 -0800 Subject: [PATCH] pass in args --- bin/cli.js | 14 +++++++++----- client/src/App.tsx | 8 ++++++-- server/src/index.ts | 20 +++++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 0de8616..fe50a25 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -6,20 +6,24 @@ import concurrently from "concurrently"; const __dirname = dirname(fileURLToPath(import.meta.url)); -// Paths to the server and client entry points -const serverPath = join(__dirname, "../server/build/index.js"); -const clientPath = join(__dirname, "../client/bin/cli.js"); +// Get command line arguments +const [, , environment, ...mcpServerArgs] = process.argv; + +const inspectorServerPath = join(__dirname, "../server/build/index.js"); + +// Path to the client entry point +const inspectorClientPath = join(__dirname, "../client/bin/cli.js"); console.log("Starting MCP inspector..."); const { result } = concurrently( [ { - command: `node ${serverPath}`, + command: `node ${inspectorServerPath}${environment ? ` --env ${environment}` : ""}${mcpServerArgs.length ? ` ${mcpServerArgs.join(" ")}` : ""}`, name: "server", }, { - command: `node ${clientPath}`, + command: `node ${inspectorClientPath}`, name: "client", }, ], diff --git a/client/src/App.tsx b/client/src/App.tsx index 8ae2068..73a337a 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -186,9 +186,13 @@ const App = () => { }, [args]); useEffect(() => { - fetch("http://localhost:3000/default-environment") + fetch("http://localhost:3000/config") .then((response) => response.json()) - .then((data) => setEnv(data)) + .then((data) => { + setEnv(data.defaultEnvironment); + setCommand(data.defaultCommand); + setArgs(data.defaultArgs); + }) .catch((error) => console.error("Error fetching default environment:", error), ); diff --git a/server/src/index.ts b/server/src/index.ts index 5030fdc..c8f2c74 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node +import { parseArgs } from "node:util"; import cors from "cors"; import EventSource from "eventsource"; @@ -16,6 +17,14 @@ import mcpProxy from "./mcpProxy.js"; // eslint-disable-next-line @typescript-eslint/no-explicit-any (global as any).EventSource = EventSource; +const { values } = parseArgs({ + args: process.argv.slice(2), + options: { + env: { type: "string", default: "" }, + args: { type: "string", default: "" }, + }, +}); + const app = express(); app.use(cors()); @@ -97,11 +106,16 @@ app.post("/message", async (req, res) => { } }); -app.get("/default-environment", (req, res) => { +app.get("/config", (req, res) => { try { - res.json(getDefaultEnvironment()); + const defaultEnvironment = getDefaultEnvironment(); + res.json({ + defaultEnvironment, + defaultCommand: values.env, + defaultArgs: values.args, + }); } catch (error) { - console.error("Error in /default-environment route:", error); + console.error("Error in /config route:", error); res.status(500).json(error); } });