Skip to content

Spike: structured CLI output (io.Writer / MCP stdio mode) #279

@leggetter

Description

@leggetter

Problem statement

User-visible output is scattered across fmt.Print*, Cobra, the interactive login path, and MCP. Stdio MCP requires a strict contract: stdout = JSON-RPC only; everything else should go to stderr or an injected writer. Violations regress MCP hosts (e.g. "not valid JSON" in the client). Phase 1 fixes the known gateway mcp + Execute() paths; a broader design reduces repeat risk.

Direction to explore

  • A small presentation / output boundary, e.g. UserOutput with Out, Err io.Writer on config or cmd, defaulting to os.Stdout / os.Stderr.
  • Modes: TTY vs MCPStdio (or NonInteractive) chosen once per invocation (command leaf, env, or context).
  • Execute() and other high-touch paths use Err (or mode-aware writers) instead of hardcoded stdout for messages when in MCP stdio mode.
  • Longer term: inventory and migrate direct fmt.Print where protocol safety matters.

Questions for the spike

  • How much of the codebase writes non-protocol text to stdout? (grep / inventory)
  • Should MCP mode be env-only, command-derived, or both?
  • logrus / verbose logging: ensure debug does not hit stdout in MCP.
  • Tests: subprocess gateway mcp + fake stdin; assert no non-JSON lines on stdout until JSON-RPC (may overlap Phase 1d acceptance tests).

Exit criteria

Close with a short design note + follow-up epic, or won't do with rationale (cost vs. rare footguns).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions