This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-24 17:16:01 -04:00
1 parent 363ad352fe
commit 91917b2395
3 files changed
+44 -11

No files matched your search

+24 -2
View File
@@ -13,6 +13,7 @@ from uuid import uuid4
import aiohttp import aiohttp
import anyio.to_thread import anyio.to_thread
from cryptography.fernet import InvalidToken
from fastapi import ( from fastapi import (
Depends, Depends,
FastAPI, FastAPI,
@@ -625,8 +626,18 @@ async def initialize_runtime_config(app: FastAPI):
f'mcp:{server_id}', f'mcp:{server_id}',
OAuthClientInformationFull(**oauth_client_info), OAuthClientInformationFull(**oauth_client_info),
) )
except InvalidToken:
log.error(
'Error adding OAuth client for MCP tool server %s: InvalidToken. '
'Stored OAuth client data is invalid; reconnect this tool server.',
server_id,
)
except Exception as e: except Exception as e:
log.error(f'Error adding OAuth client for MCP tool server {server_id}: {e}') log.error(
'Error adding OAuth client for MCP tool server %s: %s',
server_id,
f'{type(e).__name__}: {e}' if str(e) else type(e).__name__,
)
arena_models = await Config.get('evaluation.arena.models', []) or [] arena_models = await Config.get('evaluation.arena.models', []) or []
if any('access_control' in m.get('meta', {}) for m in arena_models): if any('access_control' in m.get('meta', {}) for m in arena_models):
@@ -2686,8 +2697,19 @@ async def register_client(request, client_id: str) -> bool:
oauth_server_key, oauth_server_key,
oauth_scope=oauth_scope, oauth_scope=oauth_scope,
) )
except InvalidToken:
log.error(
'OAuth client re-registration failed for %s: InvalidToken. '
'Stored OAuth client data is invalid; reconnect this tool server.',
client_id,
)
return False
except Exception as e: except Exception as e:
log.error(f'OAuth client re-registration failed for {client_id}: {e}') log.error(
'OAuth client re-registration failed for %s: %s',
client_id,
f'{type(e).__name__}: {e}' if str(e) else type(e).__name__,
)
return False return False
try: try:
+5 -1
View File
@@ -279,7 +279,11 @@ async def set_tool_servers_config(
OAuthClientInformationFull(**oauth_client_info), OAuthClientInformationFull(**oauth_client_info),
) )
except Exception as e: except Exception as e:
log.debug('Failed to add OAuth client for MCP tool server: %s', e) log.debug(
'Failed to add OAuth client for MCP tool server %s: %s',
server_id,
f'{type(e).__name__}: {e}' if str(e) else type(e).__name__,
)
continue continue
await publish_event( await publish_event(
+15 -8
View File
@@ -18,7 +18,7 @@ import jwt
from authlib.integrations.starlette_client import OAuth from authlib.integrations.starlette_client import OAuth
from authlib.oauth2.rfc6749.errors import OAuth2Error from authlib.oauth2.rfc6749.errors import OAuth2Error
from authlib.oidc.core import UserInfo from authlib.oidc.core import UserInfo
from cryptography.fernet import Fernet from cryptography.fernet import Fernet, InvalidToken
from fastapi import ( from fastapi import (
HTTPException, HTTPException,
status, status,
@@ -275,12 +275,8 @@ def encrypt_data(data) -> str:
def decrypt_data(data: str): def decrypt_data(data: str):
"""Decrypt data from storage""" """Decrypt data from storage"""
try: decrypted = FERNET.decrypt(data.encode()).decode()
decrypted = FERNET.decrypt(data.encode()).decode() return JSONCodec.loads(decrypted)
return JSONCodec.loads(decrypted)
except Exception as e:
log.error(f'Error decrypting data: {e}')
raise
def _build_oauth_callback_error_message(e: Exception) -> str: def _build_oauth_callback_error_message(e: Exception) -> str:
@@ -909,8 +905,19 @@ class OAuthClientManager:
oauth_client_info = await recover_static_oauth_client_metadata(connection, oauth_client_info) oauth_client_info = await recover_static_oauth_client_metadata(connection, oauth_client_info)
oauth_client_info = apply_connection_oauth_options(connection, oauth_client_info) oauth_client_info = apply_connection_oauth_options(connection, oauth_client_info)
return self.add_client(expected_client_id, OAuthClientInformationFull(**oauth_client_info))['client'] return self.add_client(expected_client_id, OAuthClientInformationFull(**oauth_client_info))['client']
except InvalidToken:
log.error(
'Failed to lazily add OAuth client %s from config: InvalidToken. '
'Stored OAuth client data is invalid; reconnect this tool server.',
expected_client_id,
)
continue
except Exception as e: except Exception as e:
log.error(f'Failed to lazily add OAuth client {expected_client_id} from config: {e}') log.error(
'Failed to lazily add OAuth client %s from config: %s',
expected_client_id,
f'{type(e).__name__}: {e}' if str(e) else type(e).__name__,
)
continue continue
return None return None