[GH-ISSUE #5435] [Bug] MCP doctor emits indented JSON when stdout is redirected #3297

Closed
opened 2026-10-31 00:38:53 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @coygeek on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/5435

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

CLI

Observed behavior

Redirecting rea mcp doctor --json produces indented JSON despite the documented compact redirected-output contract. The same happens with --json --full-output.

An independent verifier reproduced this through the built public CLI. The healthy plain report occupied 67 lines and 1,624 bytes; --format jsonl returned the identical parsed object in one line and 1,229 bytes. All captured commands exited 0 with empty stderr.

Reproduction

From the source checkout with its locked dependencies installed and runtime built, using Node 24.18.0 and an isolated HOME, XDG directories and temporary directory, the verifier ran:

node scripts/rea.mjs mcp doctor --json > report.json
node scripts/rea.mjs mcp doctor --format jsonl > report.jsonl
node scripts/rea.mjs mcp doctor --json --full-output > full.json
node scripts/rea.mjs capabilities --json > control.json
wc -l -c report.json report.jsonl

The verifier parsed the captured files and confirmed that report.json and report.jsonl were deeply equal, and that full.json's data equaled the plain report. The capabilities control occupied one compact line. The plain doctor command was also run with stdout attached to a pseudo-terminal; it remained indented and its parsed value equaled the redirected report. These are individual executed checks, not a repeated-run reliability measurement.

Expected behavior

docs/cli.md:427-442, under "Output and exit status," documents the doctor JSON command and states that --json is indented on a terminal and compact when piped or redirected. Both the plain diagnostic report and full-output envelope should follow that destination-dependent formatting while preserving the JSON value and exit status.

Impact and scope

The observed impact is output whitespace, assessed as P3. The plain report carries 395 extra bytes but remains valid JSON with the same diagnostic value and successful status. The full-output report is also indented. No downstream failure, token cost or performance effect was measured. Unhealthy reports and other platforms were not executed for this report.

The verified --format jsonl selector provides a compact representation of the same plain diagnostic object.

REA version

6.7.0, source commit 074768901f3cdc8205b61773fb1faf6f6c7b3ca8.

Runtime and platform

Node.js v24.18.0; macOS arm64. No analysis provider was required.

Target and artifact context

Target-free MCP startup diagnostic with isolated user state and no selected analysis target.

Interface

CLI

Earliest failure stage

Transport or result projection

Relevant output or evidence

The redirected plain report began with:

{
  "healthy": true,

Captured measurements:

  • mcp doctor --json: 67 lines, 1,624 bytes.
  • mcp doctor --format jsonl: one line, 1,229 bytes; identical parsed report.
  • mcp doctor --json --full-output: 74 lines, 1,859 bytes. Compact serialization of that captured value would occupy 1,304 bytes; its embedded data equaled the plain report.
  • capabilities --json: one line, 30,398 bytes; compact serialization had the same byte count.

The independent verifier obtained these results from subprocess stdout captures and parsed-value comparisons. All four commands exited 0 with empty stderr.

Typed outcome or recovery expected

Preserve the existing report, envelope and healthy exit status, with compact JSON on redirected stdout and indentation on terminal stdout.

Analysis or suspected cause

Source-derived reasoning: scripts/rea.mjs:74-81 writes the doctor's returned string unchanged. src/mcpDoctor.ts:287-322 formats both report variants with Formatter.format(outputValue, parsed.format) without destination information. The installed incur formatter's JSON branch uses two-space indentation. The ordinary destination-aware JSON writer is src/cli/jsonOutput.ts.

Additional context

Prepared with AI assistance and independently reproduced by a separate verifier. A fresh upstream fetch found no later changes to the cited documentation, dispatcher, doctor formatter or ordinary JSON writer through 052956af3416fa01d93837e54fdec3ad2739f6d1; this freshness check was source-based, not a new runtime reproduction.

Related reports cover different behavior: #2673 concerned the missing full-output envelope, and PR #2693 concerns output selectors on argument errors. Merged PR #1413 introduced compact redirected output for the ordinary JSON writer.

NOT_ENOUGH_INFO: no last-known-good version was established.

Originally created by @coygeek on GitHub (Oct 20, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/5435 ### Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ### Area CLI ### Observed behavior Redirecting `rea mcp doctor --json` produces indented JSON despite the documented compact redirected-output contract. The same happens with `--json --full-output`. An independent verifier reproduced this through the built public CLI. The healthy plain report occupied 67 lines and 1,624 bytes; `--format jsonl` returned the identical parsed object in one line and 1,229 bytes. All captured commands exited 0 with empty stderr. ### Reproduction From the source checkout with its locked dependencies installed and runtime built, using Node 24.18.0 and an isolated HOME, XDG directories and temporary directory, the verifier ran: ```sh node scripts/rea.mjs mcp doctor --json > report.json node scripts/rea.mjs mcp doctor --format jsonl > report.jsonl node scripts/rea.mjs mcp doctor --json --full-output > full.json node scripts/rea.mjs capabilities --json > control.json wc -l -c report.json report.jsonl ``` The verifier parsed the captured files and confirmed that `report.json` and `report.jsonl` were deeply equal, and that `full.json`'s `data` equaled the plain report. The capabilities control occupied one compact line. The plain doctor command was also run with stdout attached to a pseudo-terminal; it remained indented and its parsed value equaled the redirected report. These are individual executed checks, not a repeated-run reliability measurement. ### Expected behavior `docs/cli.md:427-442`, under "Output and exit status," documents the doctor JSON command and states that `--json` is indented on a terminal and compact when piped or redirected. Both the plain diagnostic report and full-output envelope should follow that destination-dependent formatting while preserving the JSON value and exit status. ### Impact and scope The observed impact is output whitespace, assessed as P3. The plain report carries 395 extra bytes but remains valid JSON with the same diagnostic value and successful status. The full-output report is also indented. No downstream failure, token cost or performance effect was measured. Unhealthy reports and other platforms were not executed for this report. The verified `--format jsonl` selector provides a compact representation of the same plain diagnostic object. ### REA version 6.7.0, source commit `074768901f3cdc8205b61773fb1faf6f6c7b3ca8`. ### Runtime and platform Node.js v24.18.0; macOS arm64. No analysis provider was required. ### Target and artifact context Target-free MCP startup diagnostic with isolated user state and no selected analysis target. ### Interface CLI ### Earliest failure stage Transport or result projection ### Relevant output or evidence The redirected plain report began with: ```json { "healthy": true, ``` Captured measurements: - `mcp doctor --json`: 67 lines, 1,624 bytes. - `mcp doctor --format jsonl`: one line, 1,229 bytes; identical parsed report. - `mcp doctor --json --full-output`: 74 lines, 1,859 bytes. Compact serialization of that captured value would occupy 1,304 bytes; its embedded data equaled the plain report. - `capabilities --json`: one line, 30,398 bytes; compact serialization had the same byte count. The independent verifier obtained these results from subprocess stdout captures and parsed-value comparisons. All four commands exited 0 with empty stderr. ### Typed outcome or recovery expected Preserve the existing report, envelope and healthy exit status, with compact JSON on redirected stdout and indentation on terminal stdout. ### Analysis or suspected cause Source-derived reasoning: `scripts/rea.mjs:74-81` writes the doctor's returned string unchanged. `src/mcpDoctor.ts:287-322` formats both report variants with `Formatter.format(outputValue, parsed.format)` without destination information. The installed `incur` formatter's JSON branch uses two-space indentation. The ordinary destination-aware JSON writer is `src/cli/jsonOutput.ts`. ### Additional context Prepared with AI assistance and independently reproduced by a separate verifier. A fresh upstream fetch found no later changes to the cited documentation, dispatcher, doctor formatter or ordinary JSON writer through `052956af3416fa01d93837e54fdec3ad2739f6d1`; this freshness check was source-based, not a new runtime reproduction. Related reports cover different behavior: #2673 concerned the missing full-output envelope, and PR #2693 concerns output selectors on argument errors. Merged PR #1413 introduced compact redirected output for the ordinary JSON writer. NOT_ENOUGH_INFO: no last-known-good version was established.
Author
Owner

@Sriram-PR commented on GitHub (Oct 20, 2026):

I'll take this one. Reproduced on main (0c440bf) on Linux with Node 24.18.0: redirected mcp doctor --json is 67 lines / 1624 bytes, --format jsonl is 1 line / 1229 bytes with the same parsed value, and --json --full-output is indented too, while capabilities --json is one line. runProductionMcpDoctorCli in src/mcpDoctor.ts renders with Formatter.format, which always indents, and scripts/rea.mjs just writes that string. The other commands go through jsonOutputParts in src/cli/jsonOutput.ts, which only indents when stdout is a TTY. Plan: have the doctor take the stdout TTY state from the dispatcher and render json through jsonOutputParts, for both the plain and --full-output reports, plus boundary tests for the redirected (compact) and terminal (indented) cases. PR shortly.

<!-- gh-comment-id:6290622547 --> @Sriram-PR commented on GitHub (Oct 20, 2026): I'll take this one. Reproduced on main (0c440bf) on Linux with Node 24.18.0: redirected `mcp doctor --json` is 67 lines / 1624 bytes, `--format jsonl` is 1 line / 1229 bytes with the same parsed value, and `--json --full-output` is indented too, while `capabilities --json` is one line. `runProductionMcpDoctorCli` in `src/mcpDoctor.ts` renders with `Formatter.format`, which always indents, and `scripts/rea.mjs` just writes that string. The other commands go through `jsonOutputParts` in `src/cli/jsonOutput.ts`, which only indents when stdout is a TTY. Plan: have the doctor take the stdout TTY state from the dispatcher and render `json` through `jsonOutputParts`, for both the plain and `--full-output` reports, plus boundary tests for the redirected (compact) and terminal (indented) cases. PR shortly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#3297
No description provided.