[BUG] MCP HTTP client doesn't re-initialize session after "Server not initialized" error
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:
- Detect the session is no longer valid
- Re-initiate the MCP handshake (initialize request + notifications/initialized)
- 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
- Configure an HTTP MCP server in
.mcp.json:
```json
{
"mcpServers": {
"myserver": {
"type": "http",
"url": "https://example.com/mcp"
}
}
}
- Start Claude Code and use an MCP tool - it works initially
- Wait for the server session to expire (or restart the server)
- Try to use an MCP tool again
- 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:
- Client sends initialize request
- Server responds with capabilities
- Client sends notifications/initialized notification
- Session is now ready for tool calls
Claude Code appears to do the initial handshake but doesn't re-handshake when sessions become invalid.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗