Skip to main content

Module mcp_health

Module mcp_health 

Source
Expand description

Agent MCP self-heal: notice when an agent’s agentmux MCP server did not connect, tell the operator and the agent, and repair it in bounded steps (docs/specs/SPEC_AGENT_MCP_SELF_HEAL_2026_10_10.md).

Claude Code lists each MCP server’s status in its system/init frame and answers mcp_status and mcp_reconnect control requests. This module reads those frames and decides each pane’s next step; the persistent controller carries the steps out (persistent/lifecycle.rs). The steps: reconnect, reconnect again after a pause, repair the agentmux entry of .mcp.json (mcp_rewrite: the canonical entry, then the absolute path of agentmux-mcp) and reconnect after each, restart the CLI in the safe profile (no shell prefix, bash_prefix::apply_for_spawn), and otherwise give up and say so. The safe-profile restart happens once per pane unless the agent asks again (agentmux-mcp doctor --heal): a failure it didn’t fix, it won’t fix the second time.

Structs§

Beat
What the MCP process says about itself in a heartbeat.
Decision
Notice
The pane row’s content. One row per episode, updated in place.
Snapshot
What agentmux-mcp doctor is told.

Enums§

Action
What the controller does next.
Phase
Where a pane is in the ladder.
Shape
What a rewrite of the agentmux entry in .mcp.json makes it (rungs 3 and 4 of the ladder).
Status
A server’s status, as the CLI names it.
Wedge
Why a server that the CLI calls connected is not working.

Constants§

NOTICE_SUBTYPE
The pane row’s frame (frontend/app/view/agent/cli-notice.ts).
SERVER
The MCP server AgentMux puts in every agent’s config.

Functions§

auto_enabled
Whether the automatic repair is on (agent:mcpselfheal, default on). Noticing and telling stay on either way.
forget_beats
Forget a pane’s heartbeat (its CLI process ended).
give_up_note
The [AgentMux] note an agent gets when AgentMux gives up. The error is the CLI’s text about a process, so it is quoted (sanitize::quote_in_system_note): it can’t open a line or a marker.
heal_now
agentmux-mcp doctor --heal: start the ladder over now, allowing one more safe-profile restart. Err says why nothing started: connected, already_healing, or no_status_yet (the CLI hasn’t reported the server).
install
Give the module the settings (srv startup). Until then, and in tests, the automatic repair is on.
is_safe_profile
Whether the pane runs in the safe profile: its MCP server failed and reconnecting didn’t help, so its CLI starts without the shell prefix.
notice_frame
The pane row for notice.
on_beat
A heartbeat from the MCP process of CLI process process; Some when it says the server is wedged, and the step that follows.
on_reconnect
The answer to our mcp_reconnect, and the step that follows.
on_rewrite
The rewrite of the agentmux entry is done (mcp_rewrite::run), and the step that follows.
on_selftest
The launch self-test of the pane’s agentmux server ended (mcp_selftest).
on_status
The server’s status from a frame of process (a system/init, or the answer to our mcp_status, which also says why it failed), and the step that follows. auto: the automatic repair is on (auto_enabled).
on_wedged
The server of process is wedged: the step that follows.
reconnect_request_line
Ask the CLI to start the agentmux server again.
reconnect_result
The answer to our mcp_reconnect: the CLI’s reason when it says it failed. Ok only means it didn’t: the server can still be down, so the outcome is checked with mcp_status ([VERIFY_DELAY]).
silent
Panes whose MCP process has gone quiet: (block, process, why). Each is reported once; the caller then asks on_wedged what to do.
snapshot
What srv knows about the pane’s agentmux server, for doctor.
spawn_watch
Look for quiet MCP processes every [WATCH_EVERY], and hand each to repair(block, process, why). A watcher that finds the machine was asleep (its own tick came late) skips the round and gives every pane a fresh start: the MCP’s beats are late for the same reason.
status_from_control_response
The server’s status in the answer to our mcp_status, with the error the CLI keeps for a server that failed (MCP error -32000: Connection closed).
status_from_init
The agentmux server’s status in a system/init frame; None for any other frame, or one that doesn’t list the server.
status_request_line
Ask the CLI for its servers’ status.