Skip to content

Auth Failure Retry Handler _hasCompletedAuthFlow #1317

@lokendra-ss

Description

@lokendra-ss

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesauthIssues and PRs related to Authentication / OAuthbugSomething isn't workingenhancementRequest for a new feature that's not currently supportedneeds confirmationNeeds confirmation that the PR is actually required or needed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions