Skip to content

fix(cli): keep the stdio target when an option precedes it - #2704

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2631-cli-boolean-flag-target
Oct 12, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2631-cli-boolean-flag-target

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2631

Problem

The CLI split the ad-hoc target off as the leading run of non-dash tokens before Commander parsed anything. So any flag ahead of the target (-q, --strict, --format json, --method …) left the target empty, and the run fell back to the catalog with a misleading error. Unknown flags after the target, such as a server's own --crashable, were silently dropped.

Fix (clients/cli/src/cli.ts)

  • The target is now whatever Commander does not consume as an Inspector option. That is its positionals plus unknown flags, in their original order, taken from program.args. Commander already matches known options anywhere on the line, so flag order no longer matters, and node server.js --crashable --method tools/list passes --crashable to the server.
  • Unknown flags before the target's first token are still ignored, as every unknown flag was before. A command cannot start with a dash, and forwarding one would turn a catalog run into a failed ad-hoc launch.
  • -- keeps the documented CLI form and gains the conventional one.
    • When the line starts with the target (node s.js --config x -- --method tools/list), it still means target-before, options-after. That is documented in three guides and covered by existing tests.
    • When the line starts with an option, or with --, everything after -- is appended to the target verbatim. The old split read that shape as a target starting with a dash, which could never run, so no working invocation changes meaning.
  • --cli is registered as a hidden, ignored option. The test suite and v1-style callers pass a stray --cli. Now that unknown flags are forwarded, it would otherwise reach a stdio server as an argument and make URL targets fail with "Arguments cannot be passed to a URL-based MCP server". Completion already filters out hidden options.

Tests

clients/cli/__tests__/arg-order.test.ts (13 cases) uses the crashable test server as the probe for "did the argument reach the server", since --crashable adds a crash_server tool. It covers:

  • each boolean flag from the issue, plus --format json and --method, placed before the target
  • an unknown flag after the target
  • a known option placed between target tokens
  • both readings of --
  • a leading unknown flag being dropped

Docs

  • docs/mcp-server-configuration.md, docs/v1-to-v2-migration.md and docs/cli-smoke-testing.md described the old target-first rule and the "-- is required for any server flag" rule. They now describe the new behavior and give the version boundary.
  • They also note one inherent caveat: a variadic option such as --tool-arg placed directly before the target swallows the command.

Verification

npm run local:gate is green. I also checked by hand against the built CLI: -q node test-servers/build/test-server-stdio.js --method tools/list now lists tools, and --crashable reaches the server both after the target and after --.

No UI change, so no screenshots.

🤖 Generated with Claude Code

The CLI split the ad-hoc target off as the leading run of non-dash
tokens before Commander ran, so any flag ahead of the target (-q,
--strict, --format json, ...) left the target empty and the run fell
back to the catalog. Unknown flags after the target (--crashable) were
silently dropped, so a server's own flags could not be passed without
a config file.

The target is now whatever Commander does not consume as an Inspector
option: its positionals plus unknown flags, in order. Unknown flags
ahead of the target's first token are still ignored. The documented
`<target> -- <options>` form is kept; a line that starts with an
option reads `--` as conventional end-of-options instead. `--cli` is
registered as a hidden, ignored option so a stray one is not forwarded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 12, 2026
@cliffhall cliffhall linked an issue Oct 12, 2026 that may be closed by this pull request
@cliffhall
cliffhall requested a balanced review from Copilot October 12, 2026 19:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The parser change matches the issue requirements and is thoroughly covered by focused tests and documentation.

0 open findings

What changed in this PR

Fixes #2631 by deriving the CLI’s ad-hoc stdio target from Commander’s unconsumed arguments, allowing Inspector options before the target.

Changes:

  • Preserves targets regardless of Inspector option order and forwards unknown server flags.
  • Adds compatibility handling for --cli and both -- conventions.
  • Adds comprehensive argument-order tests and updates CLI documentation.
File Description
clients/​cli/​src/​cli.ts Implements revised target and separator parsing.
clients/​cli/​__tests__/​arg-order.test.ts Covers option ordering and server-argument forwarding.
docs/​mcp-server-configuration.md Documents the new parsing and separator rules.
docs/​v1-to-v2-migration.md Explains the v2.11 behavior boundary.
docs/​cli-smoke-testing.md Updates stdio smoke-test guidance.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 was clean (approval recommended, 0 open findings, no inline or suppressed comments), so no further round was requested.

@cliffhall
cliffhall merged commit ca0ab33 into v2/main Oct 12, 2026
8 checks passed
@cliffhall
cliffhall deleted the v2/fix/2631-cli-boolean-flag-target branch October 12, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI loses a stdio target when a boolean flag precedes it

2 participants