Skip to content

fix(cli): reject mcp add valued options without a value - #8003

Closed
mirzasnowy wants to merge 3 commits into
morluto:mainfrom
mirzasnowy:fix/7609-mcp-missing-values
Closed

mirzasnowy wants to merge 3 commits into
morluto:mainfrom
mirzasnowy:fix/7609-mcp-missing-values

Conversation

@mirzasnowy

@mirzasnowy mirzasnowy commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

Fixes #7609. Before, node scripts/rea.mjs mcp add --agent (and the same for --command and -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 with Missing 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 "", and node scripts/rea.mjs --full-output mcp add --agent. The violated invariant is that help advertises --agent, --command, and -c as 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.ts detects a valued mcp add option without a value, including empty equals forms, empty string values, and values hidden behind global output flags, and scripts/rea.mjs rejects it before Incur runs. The command is located through REA's existing argument normalization and builtin split, the same pipeline its doctor dispatch uses, and src/cliBuiltinArguments.test.ts covers 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 add word is located by aligning normalized form with the split command on first match, so adversarial interleavings of output-flag values literally equal to mcp or add with 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

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. Note: the body argues this is an ordinary fix, so no scope decision is required.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked.
  • Tests cover the behavior.
  • Docs updated where needed.
  • Representative output included.
  • Diff checked for secrets, cleanup, and unsupported claims.

I have reviewed every line of this diff.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T06:01:03.692383Z
We couldn’t complete this review. Comment @codex review to try again.
4934d55 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Global flags bypass rejection ▶
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.

Summary

Adds an entry-point check that rejects missing values for mcp add before registration runs.

  • REA rejects incomplete mcp add options before registration.

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

Comment thread src/cliBuiltinArguments.ts Outdated
export const findMcpAddMissingValue = (
arguments_: readonly string[],
): string | undefined => {
if (arguments_[0] !== "mcp" || arguments_[1] !== "add") return undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

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.

Comment thread src/cliBuiltinArguments.ts Resolved
@morluto

morluto commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by #7996, which has landed on main with the same fix. Rejecting a separate empty --agent "" argument isn't on main yet. A small follow-up for that case would be welcome. Thanks for the contribution!

@morluto morluto closed this Nov 4, 2026
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MCP registration ignores missing values for --agent and --command

2 participants