diff --git a/backend/open_webui/routers/tools.py b/backend/open_webui/routers/tools.py index ca23d17f7c..415e71fd02 100644 --- a/backend/open_webui/routers/tools.py +++ b/backend/open_webui/routers/tools.py @@ -122,12 +122,13 @@ async def get_tools( # MCP Tool Servers for server in await Config.get('tool_server.connections', []): - if server.get('type', 'openapi') == 'mcp' and server.get('config', {}).get('enable'): - server_id = server.get('info', {}).get('id') + if server.get('type', 'openapi') == 'mcp' and (server.get('config') or {}).get('enable'): + info = server.get('info') or {} + server_id = info.get('id') auth_type = server.get('auth_type', 'none') session_token = None - if auth_type in ('oauth_2.1', 'oauth_2.1_static'): + if auth_type in ('oauth_2.1', 'oauth_2.1_static') and server_id: splits = server_id.split(':') server_id = splits[-1] if len(splits) > 1 else server_id @@ -135,9 +136,9 @@ async def get_tools( user.id, f'mcp:{server_id}' ) - server_config = server.get('config', {}) + server_config = server.get('config') or {} - tool_id = f'server:mcp:{server.get("info", {}).get("id")}' + tool_id = f'server:mcp:{info.get("id")}' server_access_grants[tool_id] = server_config.get('access_grants', []) tools.append( @@ -145,9 +146,9 @@ async def get_tools( **{ 'id': tool_id, 'user_id': tool_id, - 'name': server.get('info', {}).get('name', 'MCP Tool Server'), + 'name': info.get('name', 'MCP Tool Server'), 'meta': { - 'description': server.get('info', {}).get('description', ''), + 'description': info.get('description', ''), }, 'updated_at': int(time.time()), 'created_at': int(time.time()), diff --git a/backend/open_webui/utils/oauth.py b/backend/open_webui/utils/oauth.py index 5b931222de..33cd4c334f 100644 --- a/backend/open_webui/utils/oauth.py +++ b/backend/open_webui/utils/oauth.py @@ -672,7 +672,7 @@ def resolve_oauth_client_info(connection: dict) -> dict: For oauth_2.1_static, overlays admin-provided credentials from info.oauth_client_id and info.oauth_client_secret onto the blob. """ - info = connection.get('info', {}) + info = connection.get('info') or {} data = decrypt_data(info.get('oauth_client_info', '')) if connection.get('auth_type') == 'oauth_2.1_static': @@ -838,7 +838,7 @@ class OAuthClientManager: if connection.get('auth_type', 'none') not in ('oauth_2.1', 'oauth_2.1_static'): continue - server_id = connection.get('info', {}).get('id') + server_id = (connection.get('info') or {}).get('id') if not server_id: continue @@ -846,7 +846,7 @@ class OAuthClientManager: if client_id != expected_client_id: continue - oauth_client_info = connection.get('info', {}).get('oauth_client_info', '') + oauth_client_info = (connection.get('info') or {}).get('oauth_client_info', '') if not oauth_client_info: continue