Skip to content

fix(ai): mcp command tools return the failing output and never write to the protocol stream #839

Closed

Description

@dan-petty

Context & Rationale

_run_mcp_cmd (ai/mcp/server.py:50-63) sends every uv run devops argv to the in-process dispatcher, which runs it with Typer's CliRunner (ai/mcp/dispatcher.py:228-249).

Child output corrupts the protocol stream.

  • A command whose child process inherits stdout writes to the server's real fd 1. Under --transport stdio (.mcp.json), fd 1 is the JSON-RPC channel.
  • Examples: devops ci test|lint|format|typecheck (_run uses capture_output=False, commands/ci.py:172-185), and the kustomize, uv, release, telemetry, config and k8s commands.
  • A probe with a failing child returned Command exited with status 1:\nℹ Quality gate root: <root>. The diagnostic went to fd 1 instead of the reply.

Failures can read as success. The dispatcher returns Success for empty output whatever the exit code (dispatcher.py:248, :268).

ci_run misleads agents (server.py:593-598):

  • it offers only 5 of the gate's checks;
  • its docstring says the gate is 'pytest, ruff check, ruff format, mypy';
  • it times out at 180 s (config/defaults.py:246), while the test step alone takes 102-435 s;
  • its lint and format paths apply fixes, so asking whether the gate passes silently edits the working tree.

Planning record.

Scope & Deliverables

  • Deliverable:
    • In-process dispatch never lets a child process write to fd 1.
    • The dispatcher returns Success only on exit 0, and no output captured otherwise.
    • A non-zero exit raises fastmcp ToolError, carrying the masked, bounded output, so clients see isError.
    • ci_run:
      • runs with --check;
      • accepts any check name the gate defines;
      • takes its timeout from CONST_CI_TEST_BUDGET_SECONDS plus a margin constant;
      • says in its docstring what the gate runs.
    • Mark the defect part of ROADMAP.md:950 and the ToolError part of :968 delivered.
  • Acceptance criteria:
    • A capfd test asserts that nothing reaches the real stdout while a tool dispatches a command whose child prints.
    • A check that exits 1 after printing a diagnostic yields an isError result containing the exit status and the diagnostic.
    • Exit 0 with empty output returns Success.
    • The argv ci_run builds contains --check, and its timeout is at least CONST_CI_TEST_BUDGET_SECONDS.
    • The new tests take at most 1 s in total.
  • Key questions:
  • Constraint:
    • Tests stay offline.
    • No new dependency.
    • The structured mypy/ruff diagnostics from ROADMAP.md:950 stay out of scope.
    • One PR.

Strategic Alignment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/mcptype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions