mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-10 06:45:28 -05:00
fix(mcp): Refresh expired OAuth tokens before tool discovery
The discover_tools endpoint was reading raw access tokens from stored credentials without checking if they had expired. This caused users to be prompted to re-authenticate every time the token expired (~1h). Now uses creds_manager.refresh_if_needed() to transparently refresh expired tokens before using them.
This commit is contained in:
@@ -98,6 +98,8 @@ async def discover_tools(
|
||||
):
|
||||
best_cred = cred
|
||||
if best_cred:
|
||||
# Refresh the token if expired before using it
|
||||
best_cred = await creds_manager.refresh_if_needed(user_id, best_cred)
|
||||
logger.info(
|
||||
f"Using MCP credential {best_cred.id} for {request.server_url}, "
|
||||
f"expires_at={best_cred.access_token_expires_at}"
|
||||
|
||||
Reference in New Issue
Block a user