feat(mcp): OAuth 2.1 and static Bearer header auth for remote MCP servers#1937
Merged
feat(mcp): OAuth 2.1 and static Bearer header auth for remote MCP servers#1937
Conversation
…vers
Adds two authentication modes for HTTP MCP servers:
- Static headers: arbitrary headers (e.g. Authorization: Bearer ${KEY})
with vault reference resolution for embedded ${VAR} patterns
- OAuth 2.1 with PKCE: full authorization code flow with local callback
server, VaultCredentialStore for token persistence across sessions,
InMemoryStateStore for PKCE verifier/CSRF, and proactive token refresh
OAuth flow: pre-binds TcpListener before client registration to resolve
redirect_uri port, validates all discovered metadata endpoints via SSRF
guard, reads buffered HTTP until CRLF to handle TCP fragmentation.
Two-phase MCP startup: non-OAuth servers connect concurrently (phase 1),
OAuth servers connect after (phase 2) to avoid blocking startup.
Auth URL delivery: CLI via eprintln, TUI via status_tx spinner, Telegram
via stderr (follow-up: #TODO for native bot message).
New config fields on McpServerConfig: headers (HashMap<String, String>)
and oauth (McpOAuthConfig with enabled, token_storage, callback_port).
Config validation enforces mutual exclusion of headers + oauth.enabled.
Closes #1930
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
Resolves #1930 — adds authentication support for remote MCP HTTP servers:
Bearer ${TOKEN}patterns127.0.0.1:18766),VaultCredentialStorebacked by age vault for token persistence across sessions, and proactive token refreshKey design decisions
TcpListenerbeforeregister_client()to resolve redirect_uri port (avoids chicken-and-egg)\r\n\r\nto handle packet fragmentationconnect_all(): non-OAuth servers concurrent (phase 1), OAuth deferred (phase 2)headersandoauth.enabledare mutually exclusive per server (validated at config load)mcp.oauth.{server_id}.{access_token,refresh_token,expires_at}New config
Known limitations
StoredCredentialstoken zeroization is an upstream rmcp limitation (accepted risk, vault at-rest encrypted)Test plan
cargo nextest run --workspace --features full --lib --bins)cargo +nightly fmt --checkcleancargo clippy --workspace --features full -- -D warningscleanMcpOAuthConfigdeserialization,OAuthTokenStorageserde,Config::validate()mutual exclusion, vault key collision detection,validate_oauth_metadata_urls()SSRF fan-out