Repository navigation
fix(cli): validate MCP registration before side effects - #9057
gensokyo-dev merged 4 commits into
Conversation
`rea mcp add extra --agent amp --command 'node --version'` exited 0, reported a successful registration, and wrote $HOME/.config/amp/settings.json even though `extra` was silently dropped. The command takes options only, and Incur skips any other token, so the caller had no way to see that part of the invocation had no effect. The neighbouring guards already reject a valued option with no value, a value position occupied by another flag, and an empty `--flag=` form; an unexpected positional was the one shape left. Classify the expanded tokens, since a non-empty equals form is valid syntax, and report the stray word through the same VALIDATION_ERROR document the other guards use. Refs morluto#7375 Co-Authored-By: Claude Sonnet 5 <[email protected]>
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. |
[Medium impact] The PR appears safe to merge; no new actionable issue was found. SummaryThe PR checks
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["mcp add arguments"] --> B{"Discovery request?"}
B -->|Yes| C["Existing discovery route"]
B -->|No| D["readMcpAddArguments"]
D --> E{"Arguments valid?"}
E -->|No| F["Redact error and exit 1"]
E -->|Yes| G{"Amp selected?"}
G -->|Yes| H["Check settings and create backup"]
H --> I["Run registration and verify result"]
G -->|No| J["Run selected client registration"]
Reviews (3) · Last reviewed commit: "fix(cli): validate MCP registration befo..." · Reviewed by Greptile |
`rea mcp add extra --command --json` reported "Missing value for flag: --command" but set `fieldErrors[0].path` to `agent`, because the field was chosen from the stray argument while the message came from the missing value. Scripts read that path to find which option to fix, so they were pointed at the wrong one. Derive the field from the same error the message describes, and cover the combined shape — a stray word plus a missing value — for both `--agent` and `--command`/`-c`. Refs morluto#9057
|
Fixed in The field and the message were chosen from different errors: the message came from The field now derives from the same error the message describes — Pinned by
|
Expanding --command=--help yields --command followed by --help, and the stray-argument pass skipped a value that starts with a dash, so it reported the value as an unexpected argument. The registration was rejected even though the caller asked for it. Only an absent value belongs to the missing-value guard.
Fixes morluto#7375. Fixes morluto#7608. Share argument consumption and agent facts between admission and scope checks; reject invalid registrations before settings, backups or runner startup. Preserve missing-value priority, explicit redaction, discovery and valid registration controls. Validated 33 focused tests (one platform skip), current-main RED and independent compiled-CLI before/after workflows; check:fast passes. Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Summary
Fixes #7375. Fixes #7608.
mcp add extra --agent ampand misspelled options such as--agents claude-codereported success, wrote Amp settings and, for the latter, started registration without the requested selector. Invalid registrations now exit 1 before client-settings inspection, backups or runner startup, with the offending argument identified. Missing/empty values keep their correction field and priority.One shared argument reader owns token consumption, agent selection and tagged validation results. It replaces the separate missing-value scans, agent scanner and proposed unexpected-token scanner. Both the launcher scope guard and dispatch use those facts. Declared sensitive literals are redacted from diagnostics; ordinary evidence text remains intact. The declared
-calias now accepts equals form consistently with--command.Evidence
a93eb3969: original regression fails (1 failed, 2 passed). Seven independent compiled-CLI calls confirm malformed arguments write settings/backups; a misspelled selector also starts a recording runner.check:fastanddocs:checkpass (including nine documentation consistency tests).Linux local verification exercises the real CLI and Amp file writer; package-runner behavior is simulated, and Windows/live-client behavior is unverified. Existing expanded discovery behavior is preserved, including
--command=--help. Completion generation is unchanged; the issue's secondary surplus-completion observation is outside this registration fix. This change adds no provider or target authority.Technical CI passes on the final head, including all eight test shards and required aggregates. Greptile reviews this head at 5/5 with no unresolved threads. No completed Codex review of this head is available; the bot reports exhausted quota. The original author readiness declarations are preserved verbatim; no new human-review attestation is added.
Author readiness
Human owner: @2SinceJuly
Before merge
type(scope): outcome.