modelcontextprotocol / modelcontextprotocol/typescript-sdk

Auth Failure Retry Handler `_hasCompletedAuthFlow`

Open
#1,317 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth bug enhancement needs confirmation P3
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Auth Retry Handling for Remote MCP Proxies

Current Behavior

We use _hasCompletedAuthFlow to prevent infinite recursion during MCP Server authentication, which works well for standard use cases.

The Challenge

When building custom proxies like mcp-remote or mcp-connector, we need more flexible authentication retry logic.

Remote MCP Servers often use scope-based authentication, where each tool requires specific permissions. This creates a scenario where:

  1. A user adds a new tool to their MCP Server
  2. When they try to execute it, the request returns a 401 Unauthorized error
  3. This happens because the local access token stored in the proxy doesn't include the scope required for the new tool
Required Solution: Two-Tier Retry Strategy

Case 1: Token Refresh
Attempt to obtain a new access token using the existing refresh token (with updated scopes).

Case 2: Full Re-authentication
If token refresh fails, restart the entire authentication flow from scratch.

The Problem

Once _hasCompletedAuthFlow is set to true, any subsequent authentication attempts throw an error. This prevents Case 2 from being implemented, leaving proxies unable to handle full re-authentication scenarios.

Proposed Solution

Expose _hasCompletedAuthFlow through one of the following approaches:

  • Add a public getter method to check the authentication state
  • Make the variable public to allow direct access

This would enable custom proxy implementations to:

  • Check the current authentication state
  • Reset the flag when full re-authentication is needed
  • Implement proper retry handling without functionality breakage

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the _hasCompletedAuthFlow state through the MCP Server authentication and retry paths. Compare the existing token-refresh behavior with the requested full re-authentication flow, then verify that custom proxies can observe or reset the state without causing infinite recursion. Done means both retry tiers can be supported without breaking standard authentication.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, authentication
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.