[BUG] MCP servers fail on startup due to race condition — connections dropped before REPL mounts (AlmaLinux 8 / RHEL 8)

Resolved 💬 3 comments Opened Mar 3, 2026 by diehard2 Closed Mar 21, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Note there is an existing issue, but it was closed as a duplicate of an issue that does not describe the problem - https://github.com/anthropics/claude-code/issues/29730

---
Describe the bug

Both MCP servers (github, context7) consistently fail to connect on startup with MCP error -32000: Connection closed. They succeed immediately on manual reconnect via /mcp. The issue is reproducible every startup session.

Version: 2.1.63
OS: AlmaLinux 8 (RHEL 8 family), kernel 5.14.0-611.16.1.el9_7.x86_64

---
What's happening

Looking at the debug log, the MCP servers start and fully establish a session — then Claude Code drops the connection before the REPL finishes mounting:

16:24:11.886Z MCP server "github": Starting connection (timeout 30000ms)
16:24:11.996Z [github stderr] server session connected session_id=""
16:24:12.050Z [github stderr] server session disconnected session_id="" ← dropped here
16:24:12.128Z [REPL:mount] REPL mounted, disabled=false ← REPL not ready yet
16:24:12.184Z MCP server "github": Connection failed after 301ms: MCP error -32000: Connection closed

The MCP session is disconnected ~78ms before the REPL mounts. The stdio pipes appear to be closed during the REPL transition, which causes the MCP server process to receive EOF and exit.

On manual reconnect (after REPL is fully up), both servers connect successfully:

  • context7: 106ms
  • github: 204ms

Why AlmaLinux 8 specifically: The startup sequence takes marginally longer on this system, landing the MCP initialization squarely in the window where the REPL isn't ready. On faster systems the initialization likely completes before the race fires.

Possible fix

The MCP connection lifecycle should be gated on REPL mount completion, or MCP servers that disconnect during the startup window should be automatically retried once the REPL is ready, rather than left in a failed state requiring manual reconnection.

---
Additional context

  • Both MCP servers print normal startup logs to stderr and exit cleanly (they receive EOF, not a crash)
  • This is 100% reproducible across sessions on this host
  • The issue does not occur on faster Linux systems (same config, same Claude Code version)
  • The 429 telemetry errors in the log (1P event logging: N events failed to export) are unrelated

What Should Happen?

MCP servers should connect

Error Messages/Logs

Debug log (annotated key section)

  2026-03-03T16:24:11.886Z [DEBUG] MCP server "github": Starting connection with timeout of 30000ms
  2026-03-03T16:24:11.889Z [DEBUG] MCP server "context7": Starting connection with timeout of 30000ms

  # GitHub MCP server starts successfully in its own process:
  # time=11:24:11.893  starting server
  # time=11:24:11.985  token scopes fetched
  # time=11:24:11.996  server session connected   session_id=""
  # time=11:24:12.050  server session disconnected session_id=""   ← EOF received, exits cleanly
  # time=11:24:12.050  server session ended

  2026-03-03T16:24:12.128Z [DEBUG] [REPL:mount] REPL mounted, disabled=false   ← too late

  2026-03-03T16:24:12.184Z [DEBUG] MCP server "github": Connection failed after 301ms: MCP error -32000: Connection closed
  2026-03-03T16:24:12.185Z [ERROR] MCP server "github" Connection failed: MCP error -32000: Connection closed
  2026-03-03T16:24:12.187Z [DEBUG] MCP server "context7": Connection failed after 299ms: MCP error -32000: Connection closed
  2026-03-03T16:24:12.188Z [ERROR] MCP server "context7" Connection failed: MCP error -32000: Connection closed

  # ~90 seconds later, manual reconnect — both succeed:
  2026-03-03T16:25:56.835Z [DEBUG] MCP server "context7": Successfully connected in 106ms
  2026-03-03T16:26:02.442Z [DEBUG] MCP server "github": Successfully connected in 204ms

Steps to Reproduce

  1. Run claude on an AlmaLinux 8 / RHEL 8 system with two or more MCP servers configured (probably an older system
  2. Observe MCP status at startup — both servers show as failed/disconnected
  3. Run /mcp → reconnect → both connect successfully in <250ms

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.63

Platform

AWS Bedrock

Operating System

Other Linux

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗