Skip to content

Remote MCP (OAuth): connection is closed at access-token expiry because list-change subscription recovery gives up before the token refresh completes #5636

Backlog

Description

@jesse-connop

Describe the bug

With an OAuth-protected HTTP MCP server that issues short-lived access tokens (30 minutes) and long-lived refresh tokens, agent sessions lose the server's tools every time the access token expires. The model then tells the user the MCP server "is down" and either waits and retries or abandons the task. The server stays healthy throughout and the refresh token is valid. A refresh grant is made and succeeds, but only after the client has already closed the connection.

What happens at each expiry, from the process log and the authorization server's log:

  1. The access token is not refreshed ahead of expiry. The first sign of expiry is an HTTP 401 on the next request.
  2. The long-lived list-change subscription ends (Cancelled). The client tries to restore it three times in under one second, and all three attempts get a 401 because no refresh has completed yet.
  3. The client logs MCP notification delivery could not be restored; closing connection (list-change subscription recovery exhausted).
  4. About 1–2 seconds later the authorization server completes the refresh_token grant, but the connection is already closed, so the server's tools disappear mid-turn.
  5. With several concurrent sessions using the same server, each session keeps sending its own copy of the old token and hits its own 401 later. We saw expired-token 401s from other sessions 2–20 minutes after a successful refresh, so the dropout repeats per session.
  6. Sometimes recovery escalates to interactive sign-in (MCP authorization was cancelled, host-delegated MCP OAuth request yielded no response; falling back to the local flow, Browser-based OAuth required) even though the stored refresh token is valid. In those cases the agent usually gives up on the server.

Over about 13 days of process logs on one machine: 186 worker quit with fatal ... OAuthChallenge events and 58 list-change subscription recovery exhausted; closing connection events.

Affected version

copilot-cli 1.0.103-unstable.r41379698026.g3219c66 (Copilot agent sessions inside VS Code 1.145.0)

Steps to reproduce the behavior

  1. Configure a streamable HTTP MCP server protected by OAuth: RFC 9728 protected resource metadata pointing to an external authorization server (Keycloak here) that issues 30-minute access tokens and long-lived refresh tokens. A shorter lifetime (2–5 minutes) reproduces it faster.
  2. Sign in, then start two or more agent sessions that use the server's tools.
  3. Keep the sessions open past the access-token expiry and keep making tool calls from each session.
  4. At expiry the server's tools drop out of the sessions and the agent reports the server as unavailable, while the server is healthy and a refresh grant succeeds moments later.

Log excerpt from one expiry (host names redacted; the refresh grant for this client succeeded on the authorization server at 04:51:03):

04:51:01.141Z [WARNING] [rust:mcp::client] MCP list-change subscription ended {"end":"Some(Cancelled)"}
04:51:01.364Z [WARNING] [rust:mcp::client] Failed to restore MCP list-change subscription {"attempt":0,"error":"MCP OAuth challenge required (HTTP 401)"}
04:51:01.665Z [WARNING] [rust:mcp::client] Failed to restore MCP list-change subscription {"attempt":1,"error":"MCP OAuth challenge required (HTTP 401)"}
04:51:02.198Z [WARNING] [rust:mcp::client] Failed to restore MCP list-change subscription {"attempt":2,"error":"MCP OAuth challenge required (HTTP 401)"}
04:51:02.198Z [ERROR] [rust:mcp::client] MCP notification delivery could not be restored; closing connection {"error":"MCP request failed: MCP list-change subscription recovery exhausted"}

Another session a few minutes later, still sending the expired token:

04:53:09.351Z [ERROR] [rust:rmcp::transport::worker] worker quit with fatal: Transport channel closed, when Client(OAuthChallenge { www_authenticate_header: "<redacted resource_metadata URL>", response: McpOAuthHttpResponse { status_code: 401, ... } })

Expected behavior

  • Refresh the access token shortly before expires_in using the stored refresh token, so active sessions never send an expired token.
  • Treat a 401 from a server with a stored refresh token as recoverable: run a single refresh (shared by all sessions using that server), then retry, instead of failing the transport.
  • Have list-change subscription recovery wait for an in-flight refresh, or back off for longer than about one second, before closing the connection.
  • Give the refreshed token to every session using the same server, instead of each session discovering the expiry on its own.
  • Fall back to interactive sign-in only if the refresh grant itself fails.

Additional context

Activity

  1. added theissue type on Dec 2, 2026
  2. added
    area:mcp
    and removed on Dec 3, 2026
  3. hstaudacher commented on Dec 3, 2026

    @hstaudacher
    Collaborator

    Thanks for the detailed logs and repro. Confirmed: when the list-change subscription ends with a 401, the client retries it three times within about a second without waiting for a token refresh, then closes the connection, so a refresh that completes a moment later can't keep the server's tools. Moved to the backlog.

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

    area:mcp

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions