GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: restore OAuth token expiry across process restarts by dhruvkej9 · Pull Request #3248 · modelcontextprotocol/python-sdk

Conversation

@dhruvkej9

@dhruvkej9 dhruvkej9 commented Aug 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Problem

OAuthClientProvider._initialize (and the client-credentials providers) reloads current_tokens from storage but never restores token_expiry_time. The persisted OAuthToken only carries the relative expires_in, so on a fresh process is_token_valid() returns True for an already-expired access token — a stale Bearer is sent and a 401 round-trip is wasted before re-authentication (mcp2cli issues #50, #57).

Fix

Persist the absolute expiry and restore it on init:

  • Add expires_at: float | None to OAuthToken (absolute unix timestamp), with a doc comment explaining the mcp2cli reproduction that motivated it.
  • Set it when tokens are stored (_handle_token_response, _handle_refresh_response).
  • Add OAuthContext.restore_token_expiry() and call it from all three _initialize methods (base, ClientCredentialsOAuthProvider, PrivateKeyJwtOAuthProvider).

Backwards compatible: expires_at defaults to None; existing stored tokens simply re-auth once, then persist the absolute expiry going forward.

Test

test_init_restores_expired_token_expiry — fails on main (expired token reported valid), passes with the fix. 210 auth tests pass, ruff + pyright clean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
dhruvkej9 Ubuntu
fix: restore OAuth token expiry across process restarts
7018afc
cubic-dev-ai[bot]
cubic-dev-ai Bot reviewed Aug 4, 2026
View reviewed changes

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dhruv Kejriwal Ubuntu
docs(auth): document expires_at rationale from mcp2cli reproduction
f5b4d89
@claude claude Bot mentioned this pull request Aug 7, 2026
fix(client/auth): discover AS metadata before cold-start token refresh, with issuer-binding check #3263
Open
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This repository only keeps pull requests open when they're linked to an issue that a maintainer has assigned to the author — CONTRIBUTING.md explains why and how we work. This PR has been closed for now because its description doesn't yet link an open issue in this repository (with Fixes #123 or similar).

If there isn't an issue for this yet, please open one — a clear description of the problem is genuinely the most useful thing for us. Then add Fixes #<number> to this PR's description. If a maintainer would like the change as a PR from you, they'll assign you to the issue and this PR will reopen automatically.

There's no need to open a new PR — this one will be reopened. While it's closed, please push any updates as new commits rather than force-pushing, since GitHub can't reopen a PR whose branch has been rewritten.

Maintainers: reopening this PR, removing the missing-issue-link label, or adding bypass-issue-check bypasses the check.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Aug 17, 2026
@maxisbey maxisbey mentioned this pull request Aug 17, 2026
OAuth client: refresh before re-authorizing, and discover before refreshing #3328
Closed
7 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cubic-dev-ai cubic-dev-ai[bot] cubic-dev-ai[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@dhruvkej9
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.