[BUG] MCP HTTP client doesn't re-initialize session after "Server not initialized" error

Resolved 💬 6 comments Opened Jan 11, 2026 by mdon Closed Mar 20, 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?

When using HTTP MCP servers, Claude Code's MCP client fails to recover from expired/invalid sessions. After the initial session expires or becomes invalid, subsequent tool calls fail with "Server not initialized" errors because the client keeps reusing the stale session ID instead of re-initializing.

The client sends tools/call requests with an old session ID, receives "Server not initialized" error, but doesn't attempt to re-handshake (send initialize + notifications/initialized).

What Should Happen?

When Claude Code receives a "Server not initialized" error (or similar session-invalid response), it should:

  1. Detect the session is no longer valid
  2. Re-initiate the MCP handshake (initialize request + notifications/initialized)
  3. Retry the original tool call with the new session

Error Messages/Logs

Server logs show:
  [warning] MCP server event: request_error
  [warning] MCP event details: %{error: #MCP.Error<invalid_request: Invalid Request %{message: "Server not initialized"}>, reason: "not_initialized"}

  Client receives:
  MCP error -32001: AbortError: This operation was aborted

Steps to Reproduce

  1. Configure an HTTP MCP server in .mcp.json:

```json
{
"mcpServers": {
"myserver": {
"type": "http",
"url": "https://example.com/mcp"
}
}
}

  1. Start Claude Code and use an MCP tool - it works initially
  2. Wait for the server session to expire (or restart the server)
  3. Try to use an MCP tool again
  4. Tool call fails with "Server not initialized" - client never re-initializes

Manual curl test proves the server works when handshake is done correctly:
# This works:
curl -X POST $URL -d '{"jsonrpc":"2.0","id":1,"method":"initialize",...}'
curl -X POST $URL -H "mcp-session-id: $SID" -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'
curl -X POST $URL -H "mcp-session-id: $SID" -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.4 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Related to previously closed issue #1604 which claimed this was fixed. The fix may have regressed or may not handle session expiry/recovery.

The MCP spec requires:

  1. Client sends initialize request
  2. Server responds with capabilities
  3. Client sends notifications/initialized notification
  4. Session is now ready for tool calls

Claude Code appears to do the initial handshake but doesn't re-handshake when sessions become invalid.

View original on GitHub ↗

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