This commit is contained in:
Timothy Jaeryang Baek 2025-09-26 14:40:30 -05:00
parent a80d5240f6
commit ac08529380

View file

@ -207,20 +207,21 @@ async def verify_tool_servers_config(
if form_data.type == "mcp": if form_data.type == "mcp":
if form_data.auth_type == "oauth_2.1": if form_data.auth_type == "oauth_2.1":
discovery_urls = get_discovery_urls(form_data.url) discovery_urls = get_discovery_urls(form_data.url)
for discovery_url in discovery_urls:
log.debug(
f"Trying to fetch OAuth 2.1 discovery document from {discovery_url}"
)
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get( async with session.get(
discovery_urls[0] discovery_urls[0]
) as oauth_server_metadata_response: ) as oauth_server_metadata_response:
if oauth_server_metadata_response.status != 200: if oauth_server_metadata_response.status == 200:
raise HTTPException(
status_code=400,
detail=f"Failed to fetch OAuth 2.1 discovery document from {discovery_urls[0]}",
)
try: try:
oauth_server_metadata = OAuthMetadata.model_validate( oauth_server_metadata = (
OAuthMetadata.model_validate(
await oauth_server_metadata_response.json() await oauth_server_metadata_response.json()
) )
)
return { return {
"status": True, "status": True,
"oauth_server_metadata": oauth_server_metadata.model_dump( "oauth_server_metadata": oauth_server_metadata.model_dump(
@ -238,7 +239,7 @@ async def verify_tool_servers_config(
raise HTTPException( raise HTTPException(
status_code=400, status_code=400,
detail=f"Failed to fetch OAuth 2.1 discovery document from {discovery_urls[0]}", detail=f"Failed to fetch OAuth 2.1 discovery document from {discovery_urls}",
) )
else: else:
try: try: