diff --git a/api/core/mcp/auth/auth_flow.py b/api/core/mcp/auth/auth_flow.py index 5f3b20121a..138be598c8 100644 --- a/api/core/mcp/auth/auth_flow.py +++ b/api/core/mcp/auth/auth_flow.py @@ -106,8 +106,8 @@ def handle_callback(state_key: str, authorization_code: str, mcp_service: "MCPTo def check_support_resource_discovery(server_url: str) -> tuple[bool, str]: """Check if the server supports OAuth 2.0 Resource Discovery.""" - b_scheme, b_netloc, _, _, b_query, b_fragment = urlparse(server_url, "", True) - url_for_resource_discovery = f"{b_scheme}://{b_netloc}/.well-known/oauth-protected-resource" + b_scheme, b_netloc, b_path, _, b_query, b_fragment = urlparse(server_url, "", True) + url_for_resource_discovery = f"{b_scheme}://{b_netloc}/.well-known/oauth-protected-resource{b_path}" if b_query: url_for_resource_discovery += f"?{b_query}" if b_fragment: diff --git a/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py b/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py index cce77aa018..986dbefdf6 100644 --- a/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py +++ b/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py @@ -189,7 +189,7 @@ class TestOAuthDiscovery: def test_discover_oauth_metadata_with_resource_discovery(self, mock_get): """Test OAuth metadata discovery with resource discovery support.""" with patch("core.mcp.auth.auth_flow.check_support_resource_discovery") as mock_check: - mock_check.return_value = (True, "https://auth.example.com/.well-known/oauth-authorization-server") + mock_check.return_value = (True, "https://auth.example.com") mock_response = Mock() mock_response.status_code = 200 @@ -207,7 +207,7 @@ class TestOAuthDiscovery: assert metadata.authorization_endpoint == "https://auth.example.com/authorize" assert metadata.token_endpoint == "https://auth.example.com/token" mock_get.assert_called_once_with( - "https://auth.example.com/.well-known/oauth-authorization-server", + "https://auth.example.com/.well-known/openid-configuration", headers={"MCP-Protocol-Version": "2025-03-26"}, )