mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Bug]: DCR-only OAuth record is reported as authenticated with a valid token

Open neylwalecki opened this issue 1 month ago • 0 comments

Problem

A Dynamic Client Registration (DCR) record without an access token is reported as authenticated: true, oauth_status: authenticated, and oauth.token_valid: true when its expiry is zero. The CLI consequently prints Token: Valid, even though PersistentTokenStore.GetToken() correctly returns transport.ErrNoToken for the same record.

Observed on personal v0.71.1 (macOS arm64). Reproduced with temporary storage and synthetic fixtures on current main, 14cb288f.

Synthetic reproduction

  1. Create an isolated runtime with a temporary data directory and an enabled HTTP server named dcr-fixture, URL https://mcp.example.invalid/mcp. No real provider is needed.
  2. Persist only client registration via BoltDB.UpdateOAuthClientCredentials(oauth.GenerateServerKey(name, url), "synthetic-client", "", 0, ""). This creates a record with empty AccessToken and zero ExpiresAt.
  3. Add the server to the supervisor StateView as disconnected / pending auth, then call Runtime.GetAllServers().
  4. Read the same record through oauth.NewPersistentTokenStore(name, url, db).GetToken(context.Background()).

Actual projection: authenticated=true, oauth_status=authenticated, oauth.token_valid=true. The token store returns no token. This happens with both an explicit OAuth block and OAuth autodiscovery. A fixture with an empty access token but a future expiry and refresh metadata also reproduces it.

Expected: unauthenticated / login required, without a valid-token claim. Preserve the registration for the next login. Real access tokens with zero expiry must remain supported as non-expiring tokens.

Cause and proposed scope

Runtime.GetAllServers in internal/runtime/runtime.go checks only err == nil && token != nil, then treats a zero expiry as an indefinitely valid token. It reads an OAuthTokenRecord, which can contain only DCR client metadata. PersistentTokenStore.GetToken already checks for an empty access token (fixed in #308 / #305), but the runtime projection bypasses that guard.

A small projection-only fix can require AccessToken != "" before reporting authentication/expiry, while retaining the autodiscovery OAuth marker for DCR-only records. No token writes, OAuth flow changes, or schema changes are needed.

Related reports

  • #305 / #308 fixed DCR placeholders in the token store and reconnect loop. That guard is present; this report concerns the runtime status projection.
  • #1722 covers a pending login being retired by instance replacement and the misleading callback UX. That can leave a DCR-only record behind, but the false token status reproduces without any replacement or browser flow. This report does not propose weakening the retirement barrier.
  • #1522 / #1525 concerned the opposite symptom, a login warning despite an actual token.

Regression prepared: five storage scenarios in both explicit/autodiscovery modes. Before the fix, all four empty-access-token scenarios fail and the six real-token controls pass. With the minimal guard, all ten pass. Fixtures are synthetic; no production configuration, provider credentials, or user data are included.

neylwalecki avatar Oct 21 '26 16:10 neylwalecki