Add `claude mcp reconnect <name>` to programmatically re-attach disconnected stdio MCP servers
Summary
There is no way to programmatically reconnect a disconnected stdio MCP server in a running Claude Code session. The only options today are (a) the interactive /mcp slash command UI or (b) restarting Claude Code entirely. This blocks scripted MCP lifecycle management — recovery scripts, slash commands, CI pipelines, multi-session orchestration — and forces a manual UI hop on every recoverable disconnect.
Requesting: claude mcp reconnect <name> (and --all) as a first-class CLI subcommand.
Problem
When an stdio MCP server's subprocess exits or is terminated (SIGTERM, crash, broken pipe, server-side timeout, etc.), Claude Code marks the connection as dead and unloads the server's tools. Subsequent tool calls return "deferred tool" / "server disconnected" errors. There is no documented mechanism to re-establish the connection from outside the interactive UI.
Confirmed by surveying claude --help and claude mcp --help in 2.1.133 — the full management surface is add, add-from-claude-desktop, add-json, get, list, remove, reset-project-choices, serve. None re-attach a previously-disconnected server.
Current behavior (reproduction)
# 1. Find an stdio MCP child process
$ pgrep -f "bandwidth-mcp/dist/index.js"
12618
# 2. Kill it (simulating a crash or external termination)
$ kill 12618
# 3. Claude Code marks the server disconnected; tools become unavailable
# (system reminder: "52 deferred tools are no longer available (MCP server disconnected)")
# 4. There is no CLI command to bring it back. The user must:
# - Run /mcp interactively and click Reconnect, or
# - Restart Claude Code
claude mcp get <name> reports Status: ✓ Connected after the kill, but that's misleading — get spawns its own throwaway subprocess for a one-shot health check, which doesn't reflect the active session's state.
Proposed feature
claude mcp reconnect <name> # re-attempt connection for one server
claude mcp reconnect --all # reconnect every disconnected server
claude mcp reconnect --all --force # also restart currently-connected ones
- Idempotent: if already connected, exits 0 with
<name>: already connected. - Works in non-interactive (
--print) mode. - Returns non-zero on actual connection failure, with the underlying error.
- Targets the current session's MCP state (not a fresh subprocess like
claude mcp getdoes today).
Use cases
- Recovery slash commands. I built a
/mcp-server-restartuser-scope slash command that targets one MCP per session via PPID disambiguation. It canSIGTERMcleanly, but cannot complete the restart half — every invocation has to end with "now run/mcpand click Reconnect," which defeats the point of a one-line command. - Multi-session machines. Operators routinely have 3–5 concurrent Claude Code sessions; a wedged MCP in one session shouldn't require restarting the whole IDE.
- CI /
claude --printautomation. The interactive/mcpUI is unavailable in--printmode, so any pipeline that exercises MCP tools has no recovery path if a server flakes. - Server-side fixes. After deploying a new MCP server build, operators want to re-attach without quitting their session.
claude mcp reconnectaftergit pull && npm run buildwould close the loop. - Long-lived sessions. Sessions that run for hours occasionally see MCP servers become wedged due to upstream API issues; reconnect is a softer recovery than full session restart.
Alternatives considered
- File-watching on
~/.claude.json. Could trigger reconnects on config edits, but it's implicit, racy, and harder to script intent-fully than an explicit subcommand. remove+addcycle. Mutates persisted config to force re-evaluation. Risky (interruption between calls leaves config broken), undocumented behavior, and not what users want — they want to reconnect, not re-register.- Sending
SIGHUPto theclaudeprocess. Undocumented signal handling; could have unintended side effects across the rest of the session state.
None are acceptable substitutes for a real subcommand.
Additional context
- Claude Code version:
2.1.133 - Platform: macOS (Darwin 25.4.0)
- Found while building a user-scope slash command at
~/.claude/commands/mcp-server-restart.mdthat can kill but not respawn. - Related existing surface: the
/mcpinteractive slash command already implements the reconnect logic internally — exposing it via CLI would mostly be wiring, not new behavior.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗