Skip to content

Commit c7b90a1

Browse files
Fix command-line argument passing to pre-fill UI
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 <[email protected]>
1 parent 1ea8e9a commit c7b90a1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

cli/src/cli.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@ async function runWebClient(args: Args): Promise<void> {
6666
abort.abort();
6767
});
6868

69+
// Build arguments to pass to start.js
70+
const startArgs: string[] = [];
71+
72+
// Pass environment variables
73+
for (const [key, value] of Object.entries(args.envArgs)) {
74+
startArgs.push("-e", `${key}=${value}`);
75+
}
76+
77+
// Pass command and args (using -- to separate them)
78+
if (args.command) {
79+
startArgs.push("--", args.command, ...args.args);
80+
}
81+
6982
try {
70-
await spawnPromise("node", [inspectorClientPath], {
83+
await spawnPromise("node", [inspectorClientPath, ...startArgs], {
7184
signal: abort.signal,
7285
echoOutput: true,
7386
});

client/bin/start.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ async function startProdServer(serverOptions) {
9191
"node",
9292
[
9393
inspectorServerPath,
94-
...(command ? [`--env`, command] : []),
95-
...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []),
94+
...(command ? [`--command`, command] : []),
95+
...(mcpServerArgs && mcpServerArgs.length > 0
96+
? [`--args`, mcpServerArgs.join(" ")]
97+
: []),
9698
],
9799
{
98100
env: {

server/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const { values } = parseArgs({
3939
options: {
4040
env: { type: "string", default: "" },
4141
args: { type: "string", default: "" },
42+
command: { type: "string", default: "" },
4243
},
4344
});
4445

@@ -520,7 +521,7 @@ app.get("/config", originValidationMiddleware, authMiddleware, (req, res) => {
520521
try {
521522
res.json({
522523
defaultEnvironment,
523-
defaultCommand: values.env,
524+
defaultCommand: values.command,
524525
defaultArgs: values.args,
525526
});
526527
} catch (error) {

0 commit comments

Comments
 (0)