claude-code - 💡(How to fix) Fix Add `claude mcp reconnect <name>` to programmatically re-attach disconnected stdio MCP servers

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Error Message

  • Returns non-zero on actual connection failure, with the underlying error.

Root Cause

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.

Code Example

# 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 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
RAW_BUFFERClick to expand / collapse

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 get does today).

Use cases

  1. Recovery slash commands. I built a /mcp-server-restart user-scope slash command that targets one MCP per session via PPID disambiguation. It can SIGTERM cleanly, but cannot complete the restart half — every invocation has to end with "now run /mcp and click Reconnect," which defeats the point of a one-line command.
  2. 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.
  3. CI / claude --print automation. The interactive /mcp UI is unavailable in --print mode, so any pipeline that exercises MCP tools has no recovery path if a server flakes.
  4. Server-side fixes. After deploying a new MCP server build, operators want to re-attach without quitting their session. claude mcp reconnect after git pull && npm run build would close the loop.
  5. 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 + add cycle. 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 SIGHUP to the claude process. 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.md that can kill but not respawn.
  • Related existing surface: the /mcp interactive slash command already implements the reconnect logic internally — exposing it via CLI would mostly be wiring, not new behavior.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Add `claude mcp reconnect <name>` to programmatically re-attach disconnected stdio MCP servers