Repository navigation
feat(cli): bash/zsh/fish shell completion via --completion - #2579
Conversation
…2434) `mcp-inspector --cli --completion <bash|zsh|fish>` prints a completion script and exits without connecting. The flag list, which flags take a value, and which take a path are read from the CLI's own commander program, so the scripts cannot drift from --help. --method completes the same ONE_SHOT_METHODS list parseArgs validates, plus servers/list and servers/show; --transport, --log-level, --format and --protocol-era complete their accepted values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Bash and zsh completion do not handle accepted --option=value arguments correctly.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds shell completion to the CLI without opening a server connection.
Changes:
- Introduces
--completion <bash|zsh|fish>. - Derives completion flags from Commander options.
- Adds installation guidance and structural/shell tests.
| File | Description |
|---|---|
clients/cli/src/completion.ts |
Generates scripts for all three shells. |
clients/cli/src/cli.ts |
Registers completion and exits after generation. |
clients/cli/README.md |
Documents completion setup and usage. |
clients/cli/__tests__/completion.test.ts |
Tests generation, metadata, and shell behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Bash splits `--method=tools/` on '=' (COMP_WORDBREAKS), so the value completes against the option two words back; zsh keeps it as one word, so the option prefix moves into IPREFIX via compset. Fish already handles the form natively; all three are covered by shell tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
Copilot round 1 (2 findings), both fixed in 9a6edc3 and answered inline:
Requesting round 2. |
|
Copilot review loop closed. Round 2 was clean: no findings, and both round-1 findings were resolved. Per the pr-flow skill, one clean round ends the loop. On the round-2 note that the shell execution tests can skip when an interpreter is missing: this is by design, so the suite still passes on machines without zsh or fish. For this PR, all three suites ran rather than skipped. bash, zsh and fish were installed on the machine that ran the gate, and the |
|
Gate status (all runs with the sandbox proxy env unset):
|

Closes #2434
What
mcp-inspector --cli --completion <bash|zsh|fish>prints a shell completion script on stdout and exits without connecting to anything.--cli,--web,--tui). Once that word is--cli, it completes every CLI flag (with descriptions in zsh and fish).--methodcompletesONE_SHOT_METHODS(the same listparseArgsvalidates against), plusservers/listandservers/show.--transport,--log-level,--format,--protocol-eraand--completioncomplete their accepted values. Flags taking a<path>fall back to file completion, as does the stdio target command.--climode is completed. Web and TUI flags are out of scope.How: derived from the program definition
The flag list is read from the live commander
programwhen the script is generated, so it can't drift from--help. The same goes for which flags take a value and which take a path, both read from each option'sflagsstring. Flags that sibling PRs add toparseArgs, such as--quietand--output, get picked up automatically with no edit to the completion module. The one hand-stated piece isVALUE_CHOICES, the finite value sets that the CLI validates in custom parsers rather than with commanderchoices. A test guards it by running every listed value through the real option parser.Why a flag rather than a
completionsubcommandThe CLI treats leading bare words as the stdio target command (
mcp-inspector --cli node server.js …). Acompletion bashsubcommand would collide with a server command namedcompletion. A flag also fits the other no-connect short-circuits (--list-stored-auth,--print-handoff) and is listed in--help.Files
clients/cli/src/completion.ts: new module holding the whole feature (option registration, flag collection, the three renderers).clients/cli/src/cli.ts: three lines aroundprogram.parse, kept minimal so sibling CLI branches merge cleanly.clients/cli/__tests__/completion.test.ts: structural tests, plus tests that execute the generated scripts in real bash, zsh and fish when installed (each shell is skipped if absent).completion.tscoverage is 100% on all four dimensions.clients/cli/README.md: new "Shell completion" section and an options-table row.Gate
npm run format, thennpm run local:gate, with the sandbox proxy env unset.local:validatepassed.coverage:webhad one failure, which is environmental and unrelated to this diff:secret-store-selection.test.ts > isOnMountPoint > is false when the path itself can't be resolved. It fails in this sandbox on any branch because the worktrees sit on a mounted volume, and it is web auth code this PR doesn't touch.coverage:cli,coverage:tui,coverage:launcher,verify:build-gate,verify:bundle-externals: all passed.smoke,smoke:web:firefox,local:storybook: queued behind the machine-wide gate lease. I'll post the result as a comment.🤖 Generated with Claude Code