From c7b90a1af9b727d5f6e0b505ced86bd66981d9b4 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Thu, 24 Jul 2025 12:56:43 +0100 Subject: [PATCH] Fix command-line argument passing to pre-fill UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running the inspector with command-line arguments (e.g., `npx @modelcontextprotocol/inspector node build/index.js arg1 arg2`), the command and arguments were not being properly passed through to the UI for pre-filling. Changes: - cli.ts now passes command and args to start.js - start.js uses --command for the command and --args for arguments - Server parses the new --command parameter - /config endpoint returns correct values for UI pre-filling This ensures the UI correctly displays the command and arguments passed on the command line instead of showing old localStorage values. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- cli/src/cli.ts | 15 ++++++++++++++- client/bin/start.js | 6 ++++-- server/src/index.ts | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cli/src/cli.ts b/cli/src/cli.ts index f29743abb..5ff1f1110 100644 --- a/cli/src/cli.ts +++ b/cli/src/cli.ts @@ -66,8 +66,21 @@ async function runWebClient(args: Args): Promise { abort.abort(); }); + // Build arguments to pass to start.js + const startArgs: string[] = []; + + // Pass environment variables + for (const [key, value] of Object.entries(args.envArgs)) { + startArgs.push("-e", `${key}=${value}`); + } + + // Pass command and args (using -- to separate them) + if (args.command) { + startArgs.push("--", args.command, ...args.args); + } + try { - await spawnPromise("node", [inspectorClientPath], { + await spawnPromise("node", [inspectorClientPath, ...startArgs], { signal: abort.signal, echoOutput: true, }); diff --git a/client/bin/start.js b/client/bin/start.js index aef386d04..ae6e9259c 100755 --- a/client/bin/start.js +++ b/client/bin/start.js @@ -91,8 +91,10 @@ async function startProdServer(serverOptions) { "node", [ inspectorServerPath, - ...(command ? [`--env`, command] : []), - ...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []), + ...(command ? [`--command`, command] : []), + ...(mcpServerArgs && mcpServerArgs.length > 0 + ? [`--args`, mcpServerArgs.join(" ")] + : []), ], { env: { diff --git a/server/src/index.ts b/server/src/index.ts index dafd187c1..92badc2c3 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -39,6 +39,7 @@ const { values } = parseArgs({ options: { env: { type: "string", default: "" }, args: { type: "string", default: "" }, + command: { type: "string", default: "" }, }, }); @@ -520,7 +521,7 @@ app.get("/config", originValidationMiddleware, authMiddleware, (req, res) => { try { res.json({ defaultEnvironment, - defaultCommand: values.env, + defaultCommand: values.command, defaultArgs: values.args, }); } catch (error) {