fix(oauth): preserve existing refresh_token when refresh response omits it by oedokumaci · Pull Request #2271 · modelcontextprotocol/python-sdk · GitHub
Skip to content

fix(oauth): preserve existing refresh_token when refresh response omits it - #2271

Closed
oedokumaci wants to merge 1 commit into
modelcontextprotocol:mainfrom
oedokumaci:fix/preserve-refresh-token
Closed

oedokumaci wants to merge 1 commit into
modelcontextprotocol:mainfrom
oedokumaci:fix/preserve-refresh-token

Conversation

@oedokumaci

@oedokumaci oedokumaci commented Mar 11, 2026

Copy link
Copy Markdown

Fixes #2270

Per RFC 6749 Section 6, the authorization server MAY issue a new refresh token in the refresh response. When it doesn't, _handle_refresh_response overwrites the stored token as-is, discarding the existing refresh_token. After the first successful refresh, can_refresh_token() returns False and subsequent refreshes fail.

This preserves the existing refresh_token when the response omits one, using model_copy(update=...).

Also removes # pragma: no cover from _handle_refresh_response (added in a bulk coverage baseline, not intentional) and adds tests covering all branches: success with preservation, success with rotation, no prior tokens, non-200 failure, and invalid JSON.

Note: #2270 hasn't received the ready for work label yet. Submitting this early since the fix is small and self-contained. Happy to wait or adjust based on maintainer feedback.

@mikeasick-fennec

Copy link
Copy Markdown

@maxisbey

Copy link
Copy Markdown
Contributor

@maxisbey maxisbey closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_handle_refresh_response discards existing refresh_token when server omits it

3 participants