Skip to content

fix(cli): keep MCP registration JSON output parseable - #8071

Closed
maxazure wants to merge 6 commits into
morluto:mainfrom
maxazure:fix/mcp-add-json-output
Closed

maxazure wants to merge 6 commits into
morluto:mainfrom
maxazure:fix/mcp-add-json-output

Conversation

@maxazure

@maxazure maxazure commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7610. rea mcp add --agent amp --json now emits one parseable JSON result rather than mixed progress and terminal output. JSON registration calls Incur's public registration producer, preserves success filtering, and waits for Amp configuration verification before reporting success. For example, the result is {"name":"rea","command":"fixture {server} --mcp","agents":["Amp"]}.

Merge current main (71f680d7c) into the existing PR branch, retaining its commits. Resolve the CLI conflict while preserving upstream missing-value validation and Markdown argument-error encoding. Normalize actual equals-bound registration options before dispatch, preserve literal command/sensitive values and selected modes, and follow Incur's registration behavior after --. Explicitly declared sensitive text is redacted from success values and failure messages; registration still receives the original input.

Current PR head: 17f9bdb8fcda4ee92e1a3ca7c6df362cdb94dc11.

Validation

Local macOS arm64, Node 24.22.1, npm 11.16.0:

  • Ten focused CLI files: 61 tests passed, including registration JSON, missing-value validation, discovery, Amp preservation/default registration, package runners, explicit sensitive values, document token controls, argument guidance and Markdown errors. Runtime rebuilt first.
  • npm run check passed: typecheck, lint/module boundaries, formatting, Knip, metadata, architecture guards, production reachability and typed lint. Typed lint reported 0 errors and 4,186 advisory warnings; production reachability reported 33 files with advisory candidates.
  • git diff --check passed; all seven candidate file hashes match the reviewed handoff.

Tests use isolated HOME/XDG directories and recording runners. No real external-client registration or full platform test matrix was run locally. Remote static checks, source tests and package build passed for this head. Eight test shards and the Windows native build remain pending; the full CI gate is not yet complete. No tool catalog, provider or package contract change.

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 with one focused outcome.
  • Related issue, representative output and validation evidence are included.
  • Scope and known verification limitations are documented.
  • Human owner readiness and required checks are complete.

The final item remains unchecked while remote checks are pending.

@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; no new actionable defect was established.

Summary

This PR sends JSON registration requests directly to SyncMcp.register and renders one structured result after Amp verification.

  • JSON MCP registrations now return one result or error document.
  • MCP add routes equals-form options without mistaking their values for flags.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI arguments] --> B[Normalize output and registration options]
  B --> C{Selected mode}
  C -->|Discovery or other mode| D[Existing dispatcher]
  C -->|JSON registration| E{Amp selected or default}
  E -->|Yes| F[Check settings and create backup]
  F --> G[SyncMcp.register]
  E -->|No| G
  G -->|Failure| H[Write one redacted error document]
  G -->|Success| I[Redact and filter result]
  I --> J{Amp verification required}
  J -->|Yes| K[Verify settings and restore prior environment]
  K -->|Passed| L[Write success document]
  K -->|Failed| M[Write validation error]
  J -->|No| L
Loading

Reviews (6) · Last reviewed commit: "fix(cli): reconcile MCP JSON registratio..." · Reviewed by Greptile

@maxazure
maxazure marked this pull request as ready for review October 30, 2026 04:51
Copilot AI balanced review requested due to automatic review settings October 30, 2026 04:51
@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-30T04:51:28.248236Z
We couldn’t complete this review. Comment @codex review to try again.
414f394 Draft marked ready
ℹ️ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change reimplements a complex CLI/MCP registration contract across multiple consumers and was only partly validated via cloud without a full local recheck, leaving verification incomplete.

No open issues 🎉

What changed in this PR

This PR fixes #7610, where rea mcp add --agent amp --json emitted human progress text, a terminal clear-line escape, and success prose ahead of the registration object, making a successful registration's stdout unparseable as JSON. Rather than scrape a JSON suffix out of Incur's mixed human output or patch the pinned dependency, REA's existing registration wrapper now calls Incur's public SyncMcp.register producer directly for the JSON format and renders a single structured result/error document. The change also hardens the shared builtin argument split so Incur's boolean timing-global forms cannot hide registration dispatch, and replaces the old late, token-wide equals-expansion with a scoped normalizeMcpAddArguments pass that only expands actual registration options before mode selection.

Changes:

  • Add normalizeMcpAddArguments, and track per-token source positions (commandIndices) plus timing-global (--timings/--no-timings/--timings=… until --) extraction in splitIncurBuiltinArguments, replacing the superseded inline late expansion.
  • In src/cli.ts, add a serveRegistration path that, for JSON, invokes SyncMcp.register and defers a single success document via flushRegistration (after Amp backup/verification), while failures emit one MCP_ADD_FAILED document with nonzero status; non-JSON/other formats keep their prior presentation.
  • Add tests/boundary/cli/mcpAddJsonOutput.test.ts covering single-document JSON parsing, Amp settings/backup preservation, runner forwarding and failure status, discovery/mode precedence, timing-global forms, equals-shaped literal values, and sensitive-value redaction.
File Description
src/​cliBuiltinArguments.ts Adds commandIndices to the split, aligns timing-global extraction with Incur's parser, and introduces the scoped normalizeMcpAddArguments expansion.
src/​cli.ts Routes JSON mcp add through SyncMcp.register with deferred single-document flushing and single-error failure handling; preserves Amp guard/backup and non-JSON output.
tests/​boundary/​cli/​mcpAddJsonOutput.test.ts New boundary tests validating the one-document JSON contract, side effects, failure status, and argument-handling edge cases.

Review effort: Balanced

Preserve scoped argument normalization and JSON registration output alongside default Amp guards and global timing parsing.

Validation: exact tree 5b31610 matches the reviewed Linux result (25 focused tests, npm run check and test discovery). Local patch checksum, tree, diff and index checks passed.
Comment thread src/cli.ts Resolved
Check registration success and failure through parsed documents, typed
codes, settings bytes, and backup paths.
Incur filters successful registration data before formatting. The direct
JSON document uses that same filter, while failure documents keep their
typed codes.
@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @maxazure, thanks for putting this together, the fix looks useful. What's left: it has merge conflicts with main in src/cli.ts (merging main into the branch is fine). Once that's done I'm happy to merge it.

@maxazure maxazure closed this Nov 11, 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 mixes human messages into --json stdout

4 participants