Skip to content

[Bug]: Server keeps showing "Token expired" after switching it from OAuth to a header token #1172

Closed

Description

@antongulin

What happened?

I moved nine upstreams from OAuth to a plain static token in the Authorization header. In the config, oauth is now null for all of them.

They all work fine. Tool calls succeed every time. But the status still says:

level:   unhealthy
summary: Token expired
action:  login

It has said that for about two weeks, across many restarts. There is no login to do, because these servers do not use OAuth any more.

The reason is an old OAuth token left behind in config.db. Switching the server to header auth does not delete it.

In the oauth_tokens bucket I still see one record per server:

cloudflare_cffd8ffdbe422719
cloudflare-workers_2a776bac1041e57b
cloudflare-dns_a856b1a089eba814
cloudflare-graphql_8789ed3254155ec0
... one for each of the nine

The API then builds an oauth object out of that dead record and returns it, even though the config says null:

"oauth": {
  "auth_url": "",
  "token_url": "",
  "client_id": "",
  "token_expires_at": "2026-08-17T03:43:04Z"
}

That date is in the past, so internal/health/calculator.go takes this branch:

if input.OAuthStatus == "expired" {
    Summary: "Token expired", Action: ActionLogin, Level: LevelUnhealthy
}

So the old saved token wins over the current config.

One more thing. POST /api/v1/servers/<name>/logout does clear the token record, and oauth becomes null in the API. But after a restart the status changes to Refresh token expired instead. So there seems to be a second leftover record (the refresh state) that logout does not clean up.

Expected behavior

A server with "oauth": null and a working Authorization header should show as healthy and connected.

Old OAuth records should be removed when a server stops using OAuth, or at least ignored when the config has no OAuth.

Steps to reproduce

  1. Add an HTTP upstream that uses OAuth and log in, so a token gets saved.
  2. Wait until that token's expiry time has passed.
  3. Change the same server to use a static token instead: set oauth to null and put the token in an Authorization header.
  4. Restart mcpproxy.
  5. Look at the server status. It says Token expired with a login action, but tool calls work.

MCPProxy version

MCPProxy v0.63.0 (personal) linux/amd64

Operating system

Linux

Relevant logs

The status is wrong even when the connection is completely clean. Here is the same server answering a real tool call at the moment its health said Token expired:

$ cloudflare-workers:workers_list
{"workers":[ ... 31 workers ... ],"count":31}

And the older refresh error that first put the record into a failed state, from before the switch to header auth:

Re-authentication required: failed to refresh OAuth token: server not found: cloudflare-workers

Why this matters

The status field becomes useless for these servers. It is permanently red, so a real problem later would not stand out. In my case I had three servers that were genuinely broken (missing API token permissions) sitting in the same list as six that were fine, and every one of them looked identical.

Possible fixes

  1. When a server's config no longer has oauth, delete its stored OAuth token and refresh state.
  2. Or, in the health calculator, do not use a stored token when the current config has no OAuth and the server has an Authorization header.
  3. Make logout also clear the refresh state, not just the token.

Happy to test a fix. I can reproduce this on demand.

Pre-submission checklist

Activity

  1. antongulin commented on Sep 4, 2026

    @antongulin
    ContributorAuthor

    Still reproduces on v0.64.0 (personal, linux/amd64). Re-checked after upgrading from v0.63.0 today.

    This install happens to be a natural A/B for the diagnosis in the issue: 10 upstreams point at the same provider's remote MCP servers, and they differ only in their stored OAuth state.

    Upstream group OAuth record in config.db Header token connected health
    8 servers stale record present yes true, tools served unhealthy / "Token expired" / action: login
    1 server cleared with logout yes true, 23 tools healthy
    1 server never had one no true, 2 tools healthy

    All ten are connected and serving tools; only the eight with a leftover oauth_tokens record report unhealthy. The one that was explicitly logged out sits in the same config shape as the other eight and reports correctly — which is what the issue predicts if internal/health/calculator.go is trusting the stored record over the live "oauth": null config.

    Two things changed between v0.63.0 and v0.64.0 that may be useful:

    1. detail is now empty. On v0.63.0 the same servers carried detail: "Re-authentication required: failed to refresh OAuth token: server not found: <name>". On v0.64.0 summary is still "Token expired" but detail is "", so the only hint about why is gone.
    2. The logged-out server flipped from unhealthy to healthy. On v0.63.0 it reported "Refresh token expired" (the second stale refresh-state record described in the issue). After the upgrade it reports healthy, with no further action taken on it — so something in v0.64.0 appears to have cleared or stopped consulting that second record, while the first-order case is untouched.

    Happy to pull any specific field out of these installs if it helps narrow it down.

  2. added a commit that references this issue on Sep 19, 2026
    527097b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions