发布

  • fix(mcp): auto-register headroom MCP server in wrap claude/codex and init -g

    frostbyte_neo 发布于 2026-05-09 00:18:32 +00:00

    The proxy compresses tool_result payloads and emits [Retrieve more: hash=…]
    markers, but Claude Code / Codex had no headroom_retrieve tool to call on
    those markers unless the user separately ran 'headroom mcp install'. The
    markers were dead pointers — silent quality loss.

    Adds a per-agent MCP registrar abstraction (mcp_registry/) and wires it
    into wrap and init so MCP install happens automatically alongside rtk:

    • mcp_registry/base.py — MCPRegistrar ABC, ServerSpec, RegisterResult,
      RegisterStatus enum.
    • mcp_registry/claude.py — Claude Code registrar (claude mcp add CLI
      with .claude.json / mcp.json file fallback).
    • mcp_registry/codex.py — OpenAI Codex registrar (marker-delimited TOML
      block edits to ~/.codex/config.toml; preserves user's other config).
    • mcp_registry/install.py — install_everywhere() orchestrator with
      detect-then-register semantics.
    • mcp_registry/display.py — shared format_result()/format_results() for
      consistent CLI output across wrap, init, and 'headroom mcp install'.

    Adding a new agent (Cursor, Continue, Cline, Windsurf, Goose) is now a
    single new file plus one entry in get_all_registrars(); call sites and
    display logic don't change.

    Test seam is constructor injection (home_dir, claude_cli) — zero patches
    in 66 new tests across the registry. Removed 13 brittle CLI integration
    tests in test_mcp.py that were patching module-level globals; equivalent
    coverage now lives at the registrar/orchestrator layer.

    wrap codex: snapshot ~/.codex/config.toml at the top of the command so
    the existing wrap→unwrap round-trip captures the true pre-wrap state
    even though MCP install now writes to the same file mid-flow.

    220 tests pass (66 new + 154 existing CLI + integration). ruff and mypy
    clean on touched files.

    下载附件