Skip to content

fix(cli): reject unknown MCP registration options - #8069

Closed
maxazure wants to merge 2 commits into
morluto:mainfrom
maxazure:fix/mcp-add-unknown-options
Closed

maxazure wants to merge 2 commits into
morluto:mainfrom
maxazure:fix/mcp-add-unknown-options

Conversation

@maxazure

@maxazure maxazure commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7608. rea mcp add --bogus and misspelled selectors such as --agents claude-code currently report success and can invoke registration with default clients. Reject unknown options with PARSE_ERROR and exit 1 before reading/backing up Amp settings or invoking registration.

Problem and expected behavior

The built-in registration path manually consumes known options and silently ignores others. Invalid options must identify the unsupported flag and stop before client configuration changes. Representative piped JSON output:

{"code":"PARSE_ERROR","message":"Unknown flag: --bogus"}

Change and scope

Validate the command tail in REA's existing mcp add wrapper after shared global argument splitting and discovery handling. Preserve Incur's consumption of nonempty option values, including flag-shaped data. CSV/TSV requests receive a JSON error document so row selection cannot hide the diagnostic.

This is a routine input-validation fix within existing contribution scope; a separate maintainer scope decision is not applicable. It does not implement the missing-value work in #7996/#8003 or surplus-positionals work in #7453. Existing binding issues, including --command "--no-global" and non-Amp equals-form registration, remain outside this change; no claim that all registration parsing is fixed.

Contract and boundary impact

  • Semantic owner / earliest changed stage: CLI registration admission, using the existing normalized builtin split; validation precedes Amp filesystem access and Incur registration.
  • CLI contract: unknown registration options now fail instead of being silently ignored. No MCP tool-catalog/schema, provider, bridge, target-format, Evidence, artifact, or generated/package metadata changes.
  • Effects: rejected calls perform no registration runner invocation or Amp configuration write/backup. Accepted registration retains its existing effects. No target execution or new authority is introduced.

Evidence and regression coverage

Current review follow-up addresses the marked-sensitive-value finding. The early unknown-option return bypassed the normal redaction wrapper. The diagnostic now applies the existing declaredSensitiveValues(command) and redactExplicitText owners before formatting the whole message; error codes remain unchanged and undeclared values are preserved. Regression cases cover all eight output modes, both declaration spellings and equals/spaced forms, overlapping literals, global splitting and declaration-shaped output values, with no runner/configuration side effects.

The fix was developed and verified in the cloud before local publication. The cloud handoff reports 36 neighboring tests, 12 regression tests and 18 tests stacked with #8071 passed, plus check:fast; these counts are reported cloud evidence, not Mac reruns. The exact incremental patch matched SHA-256 c5b7103f21d47addc98884f950102572907a784c82d6c5cce69f3d6ce31be93e. On the Mac, npm run test:focused -- tests/boundary/cli/mcpAddUnknownOptions.test.ts rebuilt the runtime and passed all 12 current regression tests; npm run check:fast and git diff --check also passed. Full check was not rerun for this follow-up; the baseline Knip limitation below remains disclosed.

Initial implementation evidence (before this review follow-up):

Executed on macOS arm64 with Node 24.22.1 and npm 11.16.0 against main 317bf3fe235e655b2d752d3be261cc0da7d00f2b:

  • Before the fix, the new public CLI suite had 2 failures and 1 passing control: mcp add --bogus returned 0; malformed Amp settings were read and reported instead of rejecting the unknown flag first.
  • After the fix, all 3 regression tests pass. Cases cover unknown long/short/equals flags, misspelled agent selection, global output flags, error formats, unchanged existing settings/no backup, help/schema precedence, flag-shaped command values and valid Amp equals forms.
  • All tests use disposable HOME directories and recording package-runner fixtures; no real package registration or client configuration was performed. These fixtures establish argument forwarding, not actual external client integration.
  • Applicable boundary regressions: unknown values, raw token/value identity and public CLI error delivery. No resource lifecycle change.

Validation performed

The current follow-up checks are listed above; the following records the initial revision.

  • npm run build:cached — baseline build passed; fixed runtime rebuilt by focused tests.
  • npm run test:focused -- tests/boundary/cli/mcpAddUnknownOptions.test.ts tests/boundary/cli/mcpAddDiscovery.test.ts tests/boundary/cli/ampRegistrationPreservation.test.ts tests/boundary/cli/packageRunnerRegistration.test.ts tests/acceptance/cliBuiltinDocumentTokens.test.ts — 7 neighboring tests passed; the new suite initially exposed a test expectation that did not account for Markdown colon escaping. After correcting that expectation, node node_modules/vitest/vitest.mjs run tests/boundary/cli/mcpAddUnknownOptions.test.ts passed all 3 tests.
  • npm run check:fast — passed (typecheck, lint and module boundaries).
  • npm run verify:test-discovery — all 2,866 test files discovered exactly once.
  • npm run check — did not pass: Knip reported 4 unused exports, 3 unused exported types and 2 duplicate exports in untouched domain files. Re-running Knip with both changed production files restored to the base revision produced the identical findings. Full check stopped before later chained architecture/production/typed-lint checks. Format and metadata checks passed.
  • git diff --check — passed.

Compatibility, safety, and release

Previously accepted invalid options intentionally become errors; no migration for valid invocations. Real Hopper/Ghidra/browser coverage is not relevant to this input-only fix. Windows/Linux, the full repository test suite and full CI matrix were not run locally. No dependency or release metadata changes. No real client settings were changed during verification.

Author readiness

Human owner: @maxazure

  • 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; this routine fix needs no separate scope decision.
  • The PR has one focused outcome and a Conventional Commit title.
  • Related issue and regression evidence are included.
  • User-visible output and validation limitations are documented.
  • Human owner readiness and required checks are complete.

Resolution

Superseded by merged #9057, which fixes #7375 and #7608 together at the shared registration argument owner. Unknown options and surplus tokens fail before settings reads/backups or package-runner startup; missing-value priority, explicit redaction and discovery controls remain covered. Thirty-three focused tests, independent compiled-CLI before/after checks and all eight CI shards pass on the merged implementation.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

Rejects unknown mcp add options before registration or Amp settings access. The latest change fixes the earlier sensitive-value leak by reusing the shared redaction helpers.

  • The CLI rejects unknown MCP registration flags before registration starts.

Reviews (2) · Last reviewed commit: "fix(cli): redact marked values in regist..." · Reviewed by Greptile

Comment thread src/cli.ts Resolved
@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 add ignores undeclared flags and applies registration [Bug] mcp add writes client configuration despite an unexpected positional argument

3 participants