claude-code - 💡(How to fix) Fix Feature Request: Automatic MCP reconnection on auth token expiry [1 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#51799Fetched 2026-04-22 07:52:31
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

Root Cause

Long-running Claude Code sessions are a common use case, but short-lived auth tokens make them fragile. The current workaround — a local proxy to handle token refresh — is significant overhead for what could be a built-in reconnect-on-auth-failure behavior.

Fix Action

Fix / Workaround

Long-running Claude Code sessions are a common use case, but short-lived auth tokens make them fragile. The current workaround — a local proxy to handle token refresh — is significant overhead for what could be a built-in reconnect-on-auth-failure behavior.

RAW_BUFFERClick to expand / collapse

Problem

HTTP MCP servers commonly use short-lived auth tokens (e.g. 1-hour TTL) via headersHelper. When a token expires mid-session, all MCP tool calls silently fail until the user manually runs /mcp to reconnect — which re-executes headersHelper and obtains a fresh token.

Requested Behavior

When an HTTP MCP server returns a 401/403, Claude Code should automatically reconnect (re-executing headersHelper) and retry the failed request, without requiring manual intervention.

Why This Matters

Long-running Claude Code sessions are a common use case, but short-lived auth tokens make them fragile. The current workaround — a local proxy to handle token refresh — is significant overhead for what could be a built-in reconnect-on-auth-failure behavior.

extent analysis

TL;DR

Implement automatic reconnect logic in Claude Code to re-execute headersHelper and retry failed requests when encountering 401/403 errors from the HTTP MCP server.

Guidance

  • Identify the specific error handling mechanism in Claude Code that catches 401/403 errors from the HTTP MCP server and modify it to trigger a reconnect.
  • Re-executing headersHelper should obtain a fresh auth token, which can then be used to retry the original failed request.
  • Consider implementing a retry limit to prevent infinite loops in case of persistent authentication issues.
  • Verify that the reconnect logic correctly handles different scenarios, such as multiple concurrent requests failing due to token expiration.

Example

// Pseudo-code example of reconnect logic
if (response.status === 401 || response.status === 403) {
  const freshToken = await reExecuteHeadersHelper();
  // Retry the original request with the new token
  return retryRequestWithToken(freshToken);
}

Notes

The exact implementation details may vary depending on the specific architecture and technology stack used by Claude Code. This guidance assumes that headersHelper can be re-executed programmatically to obtain a fresh auth token.

Recommendation

Apply workaround: Implement the reconnect logic as described, as there is no indication of a fixed version that addresses this issue. This approach allows for a more robust handling of short-lived auth tokens without relying on manual user intervention or external workarounds.

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 Feature Request: Automatic MCP reconnection on auth token expiry [1 comments, 2 participants]