refac
This commit is contained in:
1 parent
8927c9bb3d
commit
cdd7b88bec
2 files changed
+11
-10
No files matched your search
@@ -122,12 +122,13 @@ async def get_tools(
|
|||||||
|
|
||||||
# MCP Tool Servers
|
# MCP Tool Servers
|
||||||
for server in await Config.get('tool_server.connections', []):
|
for server in await Config.get('tool_server.connections', []):
|
||||||
if server.get('type', 'openapi') == 'mcp' and server.get('config', {}).get('enable'):
|
if server.get('type', 'openapi') == 'mcp' and (server.get('config') or {}).get('enable'):
|
||||||
server_id = server.get('info', {}).get('id')
|
info = server.get('info') or {}
|
||||||
|
server_id = info.get('id')
|
||||||
auth_type = server.get('auth_type', 'none')
|
auth_type = server.get('auth_type', 'none')
|
||||||
|
|
||||||
session_token = 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(':')
|
splits = server_id.split(':')
|
||||||
server_id = splits[-1] if len(splits) > 1 else server_id
|
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}'
|
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', [])
|
server_access_grants[tool_id] = server_config.get('access_grants', [])
|
||||||
|
|
||||||
tools.append(
|
tools.append(
|
||||||
@@ -145,9 +146,9 @@ async def get_tools(
|
|||||||
**{
|
**{
|
||||||
'id': tool_id,
|
'id': tool_id,
|
||||||
'user_id': tool_id,
|
'user_id': tool_id,
|
||||||
'name': server.get('info', {}).get('name', 'MCP Tool Server'),
|
'name': info.get('name', 'MCP Tool Server'),
|
||||||
'meta': {
|
'meta': {
|
||||||
'description': server.get('info', {}).get('description', ''),
|
'description': info.get('description', ''),
|
||||||
},
|
},
|
||||||
'updated_at': int(time.time()),
|
'updated_at': int(time.time()),
|
||||||
'created_at': int(time.time()),
|
'created_at': int(time.time()),
|
||||||
|
|||||||
@@ -672,7 +672,7 @@ def resolve_oauth_client_info(connection: dict) -> dict:
|
|||||||
For oauth_2.1_static, overlays admin-provided credentials from
|
For oauth_2.1_static, overlays admin-provided credentials from
|
||||||
info.oauth_client_id and info.oauth_client_secret onto the blob.
|
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', ''))
|
data = decrypt_data(info.get('oauth_client_info', ''))
|
||||||
|
|
||||||
if connection.get('auth_type') == 'oauth_2.1_static':
|
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'):
|
if connection.get('auth_type', 'none') not in ('oauth_2.1', 'oauth_2.1_static'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
server_id = connection.get('info', {}).get('id')
|
server_id = (connection.get('info') or {}).get('id')
|
||||||
if not server_id:
|
if not server_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -846,7 +846,7 @@ class OAuthClientManager:
|
|||||||
if client_id != expected_client_id:
|
if client_id != expected_client_id:
|
||||||
continue
|
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:
|
if not oauth_client_info:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user