diff --git a/src/cliBuiltinArguments.ts b/src/cliBuiltinArguments.ts index 94e2bc11bd..8b6c497fa1 100644 --- a/src/cliBuiltinArguments.ts +++ b/src/cliBuiltinArguments.ts @@ -389,7 +389,7 @@ const readMcpHttpOption = (argument: string, next: string | undefined) => { const readMcpHttpCommand = ( arguments_: readonly string[], ): McpHttpCommand | undefined => { - let mode: "explicit" | "required" | undefined; + let transportFlag: string | undefined; const values = new Map(); const allowedHosts: string[] = []; let problem: McpHttpCommandProblem | undefined; @@ -400,13 +400,13 @@ const readMcpHttpCommand = ( continue; } if (argument === "--http") { - mode = "explicit"; + transportFlag = "--http"; continue; } const next = arguments_[index + 1]; const { flag, inline, value } = readMcpHttpOption(argument, next); if (MCP_HTTP_VALUED_FLAGS.has(flag)) { - mode ??= "required"; + transportFlag ??= flag; if (value === undefined) { problem ??= invalidMcpHttpCommand(`Missing value for ${flag}`); } else { @@ -424,10 +424,10 @@ const readMcpHttpCommand = ( if (!argument.startsWith("-") || argument === "--") break; if (!inline && spacedOutputValue(flag, next) !== undefined) index += 1; } - if (mode === undefined) return undefined; + if (transportFlag === undefined) return undefined; if (problem !== undefined) return problem; - if (mode === "required") - return invalidMcpHttpCommand("--host and --port require --http"); + if (transportFlag !== "--http") + return invalidMcpHttpCommand(`${transportFlag} requires --http`); return { kind: "listen", host: values.get("--host"), diff --git a/tests/boundary/mcp/mcpHttpOptions.test.ts b/tests/boundary/mcp/mcpHttpOptions.test.ts index 24b77d0d15..5320d673d7 100644 --- a/tests/boundary/mcp/mcpHttpOptions.test.ts +++ b/tests/boundary/mcp/mcpHttpOptions.test.ts @@ -168,17 +168,22 @@ processTest( processTest( "reports an HTTP option without its mode through the compiled CLI", async ({ processes }) => { - const result = await processes.run(process.execPath, [ - fileURLToPath(new URL("../../../scripts/rea.mjs", import.meta.url)), - "mcp", - "--port", - "8765", - ]); - expect(result).toMatchObject({ - exitCode: 1, - stdout: "", - stderr: "--host and --port require --http\n", - }); + for (const [flag, value] of [ + ["--allowed-hosts", "localhost"], + ["--port", "8765"], + ] as const) { + const result = await processes.run(process.execPath, [ + fileURLToPath(new URL("../../../scripts/rea.mjs", import.meta.url)), + "mcp", + flag, + value, + ]); + expect(result).toMatchObject({ + exitCode: 1, + stdout: "", + stderr: `${flag} requires --http\n`, + }); + } }, );