Repository navigation
fix(cli): keep the stdio target when an option precedes it - #2704
Merged
Merged
Conversation
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]>
There was a problem hiding this comment.
🟢 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
--cliand 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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)program.args. Commander already matches known options anywhere on the line, so flag order no longer matters, andnode server.js --crashable --method tools/listpasses--crashableto the server.--keeps the documented CLI form and gains the conventional one.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.--, 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.--cliis 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--crashableadds acrash_servertool. It covers:--format jsonand--method, placed before the target--Docs
docs/mcp-server-configuration.md,docs/v1-to-v2-migration.mdanddocs/cli-smoke-testing.mddescribed 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.--tool-argplaced directly before the target swallows the command.Verification
npm run local:gateis green. I also checked by hand against the built CLI:-q node test-servers/build/test-server-stdio.js --method tools/listnow lists tools, and--crashablereaches the server both after the target and after--.No UI change, so no screenshots.
🤖 Generated with Claude Code