Skip to content

fix(mcp): --json=false and --exit-code=false are parsed as truthy, enabling the flag instead of disabling it #8689

Description

@JSONbored

⚠️ Definition of Done: this issue must be completed in full, in a single PR. Do not split this
work across multiple PRs, and do not defer any Deliverable below to a follow-up issue. A PR that
satisfies only some of the Deliverables, stubs a required test, or leaves a checkbox
partially-done does NOT resolve this issue and will be closed.

Context

packages/loopover-mcp/bin/loopover-mcp.ts:5462-5499's parseOptions has a generic --key=value
inline-equals handler (added for --format=table, per its own comment referencing #2231) that
applies uniformly to every flag, storing the raw string value. Every consumer of options.json (23
call sites, e.g. lines 4214, 4278, 4407, 4599, 4877, 5024, 6220, emitList at 5512, and
cli-error.ts's argsWantJson) checks plain truthiness (if (options.json) /
arg?.startsWith("--json=")). So --json=false sets options.json = "false" — a non-empty string,
which is truthy — meaning JSON output turns ON, the opposite of what the flag says.

The identical bug affects --exit-code in doctor: bin/loopover-mcp.ts:5940:
options.exitCode && payload.status === "needs_attention" ? 1 : 0--exit-code=false is also
truthy.

This is a real inconsistency with the codebase's own established convention, not a theoretical edge
case: the same file already hardened every other boolean flag against exactly this ambiguity —
--refresh (line 4033, whose comment explicitly explains why === true is required) and --help
(10 sites, all === true), plus --all/--activate. Every options.json and options.exitCode
check was simply missed when that hardening was applied elsewhere.

Requirements

  • Change every options.json truthiness check to the same === true (or equivalent explicit
    boolean-parsing) pattern already used for --refresh/--help/--all/--activate.
  • Apply the identical fix to options.exitCode in doctor.
  • Ensure --json (no explicit value, defaulting to true) and --json=true both still work as
    before — only --json=false/--exit-code=false should change behavior (to correctly disable).

Deliverables

  • All options.json consumers use the same explicit boolean-comparison pattern as
    --refresh/--help, so --json=false correctly disables JSON output.
  • doctor's options.exitCode check has the same fix, so --exit-code=false correctly keeps
    the exit code at 0.
  • A new test using the existing in-process runCli/parseOptions harness (pattern already used
    in test/unit/mcp-cli-basics.test.ts) calls ["whoami", "--json=false"] and asserts plain-text
    output, not JSON.
  • A new test calls ["doctor", "--exit-code=false"] against a failing check and asserts the
    exit code stays 0.
  • Regression tests confirm bare --json and --json=true still enable JSON output as before.

All Deliverables above are required in the same PR.

Test Coverage Requirements

packages/loopover-mcp/** is measured by codecov/patch (99%+ target, branch-counted). The new
tests must exercise both the =false and default/=true branches for both flags.

Expected Outcome

--json=false and --exit-code=false behave as their names claim (disabling, not enabling),
matching the boolean-parsing convention already established for every other boolean flag in this
CLI.

Links & Resources

  • packages/loopover-mcp/bin/loopover-mcp.ts:5462-5499 (parseOptions), :4033 (--refresh's
    already-correct pattern), :5940 (doctor's --exit-code check)
  • packages/loopover-mcp/lib/cli-error.ts (argsWantJson)
  • test/unit/mcp-cli-basics.test.ts (existing in-process test harness to use)

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions