SEP-2207: Refresh token guidance #2039
Draft
+392
−17
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.
Implement OIDC-flavored refresh token guidance (SEP-2207) in the Python SDK client.
Motivation and Context
MCP clients interacting with OIDC-flavored Authorization Servers often don't receive refresh tokens because they aren't requesting
offline_access. This leads to poor UX (frequent re-authentication). SEP-2207 provides guidance for how MCP clients should handle this.The Python SDK's default
OAuthClientMetadataalready includesrefresh_tokeningrant_types, but the client was not augmenting authorization request scopes withoffline_accesswhen the Authorization Server advertises support for it. This change brings the Python SDK in line with the TypeScript SDK's implementation.How Has This Been Tested?
offline_accessscope augmentation inget_client_metadata_scopesoffline_accessandprompt=consentbased on AS metadataBreaking Changes
None. This is additive behavior. Clients that previously did not request
offline_accesswill now request it automatically when the AS advertises it inscopes_supportedand the client supports therefresh_tokengrant. Authorization Servers that don't recognizeoffline_accesswill simply ignore it per OAuth 2.1.Types of changes
Checklist
Additional context
get_client_metadata_scopes()now acceptsclient_grant_typesand appendsoffline_accessto the selected scopes when the AS metadata advertises it inscopes_supportedand the client includesrefresh_tokenin itsgrant_types.prompt=consentwhenoffline_accessis in the scope, per the OIDC Core spec. This matches the TypeScript SDK's behavior.insufficient_scopehandler now also passes AS metadata and client grant types toget_client_metadata_scopes, fixing a pre-existing omission.