Repository navigation
Description
Summary
After logout -> restart -> login, OAuth for an HTTP upstream can enter a reconnect loop and never complete reliably. The loop is triggered by a persisted OAuth record that contains DCR client credentials but no real access token.
I can reproduce this consistently on Linux with mcpproxy v0.17.4.
Environment
- mcpproxy:
v0.17.4 - OS: Linux
- Upstream: HTTP OAuth server (
gcwin my case)
Steps to Reproduce
- Start with a previously authenticated OAuth server.
- Call
POST /api/v1/servers/<id>/logout. - Call
POST /api/v1/servers/<id>/restart. - Call
POST /api/v1/servers/<id>/login. - Wait a few seconds.
Expected Behavior
- One OAuth login flow starts.
- User completes callback.
- Connection retries once and becomes healthy.
Actual Behavior
- Quick OAuth starts and returns auth URL.
- Then the manager repeatedly logs:
Detected persisted OAuth token; triggering reconnect- with
token_expires_at: 0001-01-01T00:00:00.000Z
- Reconnect repeatedly starts new OAuth attempts.
- Callback handling times out (
OAuth authorization timeout).
Log Evidence
Observed sequence around 2026-02-15 08:55 (+03):
OAuth logout initiatedSuccessfully recreated server with fresh secretsStarting quick OAuth flowDCR succeededAuthorization URL obtainedWaiting for OAuth callback in background- then repeated
Detected persisted OAuth token; triggering reconnectwith zero expiry.
Root Cause (code-level)
The reconnect monitor appears to treat a DCR-only placeholder record as a valid persisted token:
- DCR stores client credentials before token exchange, creating/updating a minimal OAuth record:
internal/upstream/core/connection_oauth.go(DCR success path, persists credentials)internal/storage/bbolt.goUpdateOAuthClientCredentials(...)creates minimal record when none exists.
PersistentTokenStore.GetToken()returns a token object from that record even when access token is empty / expiry is zero:
internal/oauth/persistent_token_store.go
scanForNewTokens()reconnects whentok != nil(without validating token usability):
internal/upstream/manager.go(scanForNewTokens, reconnect branch)
This produces false positives and reconnect loops while quick OAuth callback is still pending.
Suggested Fix
In scanForNewTokens() only trigger reconnect when token is actually usable, e.g.:
tok.AccessToken != ""- and optionally not zero expiry (or valid refresh semantics)
- and avoid reconnect while OAuth flow is currently in progress for that server.
Using a "valid persisted token" helper (instead of only tok != nil) would likely prevent this loop.
Related UX issue (possibly separate issue)
In daemon mode, mcpproxy auth login does not surface auth_url from /api/v1/servers/{id}/login because CLI client parses a legacy response shape in internal/cliclient/client.go.
If maintainers prefer, I can open this as a separate issue.
Activity
Fix OAuth reconnect loop caused by DCR-only placeholder token (#305)
tjsingleton commentedon Feb 21, 2026
Love the PR description!