fix(mcp): use stored OAuth credentials for auto-detect HTTP servers#3417
Open
amitksingh1490 wants to merge 1 commit into
Open
fix(mcp): use stored OAuth credentials for auto-detect HTTP servers#3417amitksingh1490 wants to merge 1 commit into
amitksingh1490 wants to merge 1 commit into
Conversation
Co-Authored-By: ForgeCode <noreply@forgecode.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix auto-detect HTTP MCP servers failing to connect even after a successful
mcp login, by using stored OAuth credentials directly and no longer masking authentication errors behind the SSE fallback.Context
After running
forge mcp login <name>against an OAuth-protected HTTP MCP server (e.g. Vanta athttps://mcp.vanta.com/mcp), the server still failed to connect and landed in the failed-servers map — despite valid credentials being stored in~/.forge/.mcp-credentials.json.Root cause, traced through the connection flow in
crates/forge_infra/src/mcp_client.rs:oauthsetting) was probed unauthenticated first viacreate_standard_http_connection.401 Unauthorized(with aWWW-Authenticateheader).GET. Many MCP servers (including Vanta) reject that with405 Method Not Allowed.405error masked the original401, so the subsequent error-string check matched none of the auth keywords.Changes
mcp login), authenticate directly with them instead of doing an unauthenticated probe. Addedhas_stored_credentialshelper.create_standard_http_connectionno longer falls back to SSE when the failure is an authentication error — it surfaces the401/auth error so auto-detection can trigger the OAuth path.is_auth_error, which walks the full error source chain looking for rmcp'sAuth required/WWW-Authenticatemarkers as well as401/unauthorized/oauth.is_auth_error.Key Implementation Details
The change is generic across all HTTP MCP servers — there is nothing server-specific in it. It only affects the
McpServerConfig::Httpmatch arm;oauth: false(disabled), explicitly-configuredoauth: {...}, and Stdio servers retain their existing behavior. The stored-credentials-first path is safe because credentials are only ever persisted via an explicitmcp login.rmcp's worker-based transport can surface a
401as a generic transport/connection error rather than a cleanAuthRequired, sois_auth_errorinspects the entire error source chain instead of relying on the top-level message.Use Cases
mcp login.Testing
Manual verification:
Links
crates/forge_infra/src/mcp_client.rs