Skip to content

Commit 77ddcd5

Browse files
author
Jah-yee
committed
fix(auth): preserve existing refresh_token when server omits it
Per RFC 6749 Section 6, issuing a new refresh token in the refresh response is optional. When the authorization server does not return a new refresh_token, the previously stored refresh_token is now preserved instead of being discarded. Fixes: #2270
1 parent 62eb08e commit 77ddcd5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/mcp/client/auth/oauth2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ async def _handle_refresh_response(self, response: httpx.Response) -> bool: # p
458458
content = await response.aread()
459459
token_response = OAuthToken.model_validate_json(content)
460460

461+
# Per RFC 6749 Section 6, the server may not return a new refresh_token.
462+
# If the server omits it, preserve the existing refresh_token.
463+
if not token_response.refresh_token and self.context.current_tokens:
464+
token_response.refresh_token = self.context.current_tokens.refresh_token
465+
461466
self.context.current_tokens = token_response
462467
self.context.update_token_expiry(token_response)
463468
await self.context.storage.set_tokens(token_response)

0 commit comments

Comments
 (0)