fix verify mcp connection with oauth type (#19149)

This commit is contained in:
Oleg Yermolenko
2025-11-12 22:05:17 +02:00
committed by GitHub
parent 6eea0d40ab
commit 8dde493e8e

View File

@@ -270,17 +270,18 @@ async def verify_tool_servers_config(
elif form_data.auth_type == "session":
token = request.state.token.credentials
elif form_data.auth_type == "system_oauth":
oauth_token = None
try:
if request.cookies.get("oauth_session_id", None):
token = await request.app.state.oauth_manager.get_oauth_token(
oauth_token = await request.app.state.oauth_manager.get_oauth_token(
user.id,
request.cookies.get("oauth_session_id", None),
)
except Exception as e:
pass
if token:
headers = {"Authorization": f"Bearer {token}"}
if oauth_token:
headers = {"Authorization": f"Bearer {oauth_token.get('access_token', '')}"}
await client.connect(form_data.url, headers=headers)
specs = await client.list_tool_specs()
@@ -306,10 +307,14 @@ async def verify_tool_servers_config(
elif form_data.auth_type == "system_oauth":
try:
if request.cookies.get("oauth_session_id", None):
token = await request.app.state.oauth_manager.get_oauth_token(
oauth_token = await request.app.state.oauth_manager.get_oauth_token(
user.id,
request.cookies.get("oauth_session_id", None),
)
if oauth_token:
token = f"{oauth_token.get('access_token', '')}"
except Exception as e:
pass