Repository navigation
fix(cli): reject mcp add valued options without a value - #8003
mirzasnowy wants to merge 3 commits into
Conversation
Reject a trailing --agent, --command, or -c (or one followed by another flag) in REA's entry point before Incur's registration helper runs, so an incomplete request fails with a missing-value diagnostic instead of silently registering with defaults. Refs morluto#7609.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Low impact] The change is limited to incomplete values on the `mcp add` CLI path. The PR should not merge yet because the global-flag bypass remains partly unfixed. Findings
Fix with agent prompt### Issue 1
src/cliBuiltinArguments.ts:undefined-213
`findMcpAddMissingValue` skips `rea --full-output mcp add --agent` because it requires `mcp add` at the start of the raw arguments. Incur removes `--full-output` before finding the command, so this still reaches default registration instead of reporting the missing value.
Use the existing argument normalization and builtin split to find the command. Add coverage for global flags before and between its words.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds an entry-point check that rejects missing values for
Review checks were source-only. Checking whether another PR supersedes this one was blocked by unavailable GitHub authentication. Reviews (2) · Last reviewed commit: "fix(cli): reject mcp add missing values ..." · Reviewed by Greptile |
| export const findMcpAddMissingValue = ( | ||
| arguments_: readonly string[], | ||
| ): string | undefined => { | ||
| if (arguments_[0] !== "mcp" || arguments_[1] !== "add") return undefined; |
There was a problem hiding this comment.
findMcpAddMissingValue skips rea --full-output mcp add --agent because it requires mcp add at the start of the raw arguments. Incur removes --full-output before finding the command, so this still reaches default registration instead of reporting the missing value.
Use the existing argument normalization and builtin split to find the command. Add coverage for global flags before and between its words.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cliBuiltinArguments.ts
Line: 213
Comment:
**Global flags bypass rejection**
`findMcpAddMissingValue` skips `rea --full-output mcp add --agent` because it requires `mcp add` at the start of the raw arguments. Incur removes `--full-output` before finding the command, so this still reaches default registration instead of reporting the missing value.
Use the existing argument normalization and builtin split to find the command. Add coverage for global flags before and between its words.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Closing as superseded by #7996, which has landed on main with the same fix. Rejecting a separate empty |
Summary
Fixes #7609. Before,
node scripts/rea.mjs mcp add --agent(and the same for--commandand-c) exited 0 and silently created a default Amp registration. An equals form with an empty remainder (--agent=,--command=,-c=), an empty string value (--agent ""), and the same missing values behind global output flags (--full-output mcp add --agent,mcp --full-output add --agent,--format json mcp add --agent) behaved the same way. After, all of those invocations exit 1 withMissing value for flag: --agent(or the corresponding option) on stderr, and no runner is invoked and no client settings are written. Valid values, including non-empty equals forms, help requests, and other commands are unchanged. Mode flags ahead of the command (--mcp,--llms,--schema,--update,--incur-update-check) keep their own behavior, since Incur never reaches registration for those invocations.Problem and expected behavior
Smallest triggers are
node scripts/rea.mjs mcp add --agent,node scripts/rea.mjs mcp add --agent=,node scripts/rea.mjs mcp add --agent "", andnode scripts/rea.mjs --full-output mcp add --agent. The violated invariant is that help advertises--agent,--command, and-cas valued options, so a missing value, including an empty equals remainder, an empty string value, or a value hidden behind global output flags, must fail the way REA-owned commands fail it, instead of silently registering with defaults.Change and scope
A helper in
src/cliBuiltinArguments.tsdetects a valuedmcp addoption without a value, including empty equals forms, empty string values, and values hidden behind global output flags, andscripts/rea.mjsrejects it before Incur runs. The command is located through REA's existing argument normalization and builtin split, the same pipeline its doctor dispatch uses, andsrc/cliBuiltinArguments.test.tscovers the check (14 tests). Option-swallowed-as-value (--command --agent amp) needed no new code: the existing flag-following rejection already covers it, proven by repro on the previous commit. Deliberately out of scope: combined short forms like-cfoo(Incur matches exact-c); siblings #7608 and #7610 as separate parser behaviors; the behavior of mode flags themselves, which is preserved exactly. Contribution scope fit: ordinary fix, no scope decision required.Contract and boundary impact
CLI contract change is the nonzero diagnostic for an invalid invocation; no tool catalog, provider, bridge, target, platform, evidence, or generated-metadata impact. No MCP schema change. No provider change. Invocations diverted by mode flags keep their exact prior behavior (serve, docs, or their own error).
Expected effects
No target interaction; the change only validates argv and exits before side effects.
Evidence and regression coverage
New tests (14 total; the 3 tests for global flags and empty strings fail on the previous commit and pass with this one; the swallowed, mode-flag, and valid-with-global-flag tests pass on both, proving those behaviors already held); before/after repro from the issue's script (original 5 incomplete cases stay exit 1 with diagnostic and zero side effects; 3 empty-equals cases stay exit 1; 3 empty-string cases, 6 leading global-flag cases, and 3 between-words cases move from exit 0 with default registration to exit 1 with diagnostic and zero side effects; mode-flag, help, setup control, and valid-value controls unchanged); neighbouring suites 121 passed; oxlint 0 errors on touched files; oxfmt clean; typecheck exit 0; module boundaries checked across 3,349 files. Remaining gaps: full CI matrix and full suite not run locally; knip, docs:check, and test:python not run; Greptile rescore pending at push time. One disclosed limitation: the
addword is located by aligning normalized form with the split command on first match, so adversarial interleavings of output-flag values literally equal tomcporaddwith a mode flag between them and the real command are not separately covered; no realistic invocation does this.Validation performed
npm run build:cached(pass); issue repro script extended with global-flag, empty-string, option-swallowed, and mode-flag cases, before and after (results above); vitest on the updated test file plus the three neighbouring suites (results above); oxlint and oxfmt on touched files (clean); typecheck (pass); module boundaries (pass). Not run: full CI matrix, full repo suite, knip, docs:check, test:python. Greptile rescore checked once after push: not yet appeared.Compatibility, safety, and release
No breaking change is claimed beyond one intentional behavior change: previously accepted invalid invocations (trailing, flag-following, option-swallowed, empty equals, empty string, and values hidden behind global output flags) now fail; no previously valid call changes, and mode-flag, help, and valid-value behavior is unchanged. No migration. No Hopper/Ghidra/browser/OS coverage applicable. Linux plus Node v24.22.1 verified. No package or release metadata impact. No doc change is needed since help already documents the valued contract.
Author readiness
Human owner: @mirzasnowy
Before merge
type(scope): outcome.I have reviewed every line of this diff.