|
33 | 33 | "name": "test-mcp-server-2", |
34 | 34 | "urls": ["mcp.server2.com"], |
35 | 35 | }, |
| 36 | + { |
| 37 | + "name": "test-mcp-server-google", |
| 38 | + "urls": ["mcp.googleapis.com"], |
| 39 | + }, |
36 | 40 | { |
37 | 41 | "name": "test-mcp-server-no-url", |
38 | 42 | }, |
@@ -79,7 +83,7 @@ def test_init_success(self, MockHttpClient): |
79 | 83 | api_registry_project_id=self.project_id, location=self.location |
80 | 84 | ) |
81 | 85 |
|
82 | | - self.assertEqual(len(api_registry._mcp_servers), 5) |
| 86 | + self.assertEqual(len(api_registry._mcp_servers), 6) |
83 | 87 | self.assertIn("test-mcp-server-1", api_registry._mcp_servers) |
84 | 88 | self.assertIn("test-mcp-server-2", api_registry._mcp_servers) |
85 | 89 | self.assertIn("test-mcp-server-no-url", api_registry._mcp_servers) |
@@ -107,7 +111,7 @@ def test_init_with_quota_project_id_success(self, MockHttpClient): |
107 | 111 | api_registry_project_id=self.project_id, location=self.location |
108 | 112 | ) |
109 | 113 |
|
110 | | - self.assertEqual(len(api_registry._mcp_servers), 5) |
| 114 | + self.assertEqual(len(api_registry._mcp_servers), 6) |
111 | 115 | self.assertIn("test-mcp-server-1", api_registry._mcp_servers) |
112 | 116 | self.assertIn("test-mcp-server-2", api_registry._mcp_servers) |
113 | 117 | self.assertIn("test-mcp-server-no-url", api_registry._mcp_servers) |
@@ -237,9 +241,43 @@ async def test_get_toolset_success(self, MockHttpClient, MockMcpToolset): |
237 | 241 |
|
238 | 242 | toolset = api_registry.get_toolset("test-mcp-server-1") |
239 | 243 |
|
| 244 | + # A non-Google host must not receive the runtime's ADC credentials. |
240 | 245 | MockMcpToolset.assert_called_once_with( |
241 | 246 | connection_params=StreamableHTTPConnectionParams( |
242 | 247 | url="https://mcp.server1.com", |
| 248 | + headers={}, |
| 249 | + ), |
| 250 | + tool_filter=None, |
| 251 | + tool_name_prefix=None, |
| 252 | + header_provider=None, |
| 253 | + ) |
| 254 | + self.assertEqual(toolset, MockMcpToolset.return_value) |
| 255 | + |
| 256 | + @patch( |
| 257 | + "google.adk.integrations.api_registry.api_registry.McpToolset", |
| 258 | + autospec=True, |
| 259 | + ) |
| 260 | + @patch("httpx.Client", autospec=True) |
| 261 | + async def test_get_toolset_google_host_includes_credentials( |
| 262 | + self, MockHttpClient, MockMcpToolset |
| 263 | + ): |
| 264 | + mock_response = MagicMock() |
| 265 | + mock_response.raise_for_status = MagicMock() |
| 266 | + mock_response.json = MagicMock(return_value=MOCK_MCP_SERVERS_LIST) |
| 267 | + mock_client_instance = MockHttpClient.return_value |
| 268 | + mock_client_instance.__enter__.return_value = mock_client_instance |
| 269 | + mock_client_instance.get.return_value = mock_response |
| 270 | + |
| 271 | + api_registry = ApiRegistry( |
| 272 | + api_registry_project_id=self.project_id, location=self.location |
| 273 | + ) |
| 274 | + |
| 275 | + toolset = api_registry.get_toolset("test-mcp-server-google") |
| 276 | + |
| 277 | + # A Google API host receives the runtime's ADC credentials. |
| 278 | + MockMcpToolset.assert_called_once_with( |
| 279 | + connection_params=StreamableHTTPConnectionParams( |
| 280 | + url="https://mcp.googleapis.com", |
243 | 281 | headers={"Authorization": "Bearer mock_token"}, |
244 | 282 | ), |
245 | 283 | tool_filter=None, |
@@ -267,11 +305,11 @@ async def test_get_toolset_with_quota_project_id_success( |
267 | 305 | api_registry_project_id=self.project_id, location=self.location |
268 | 306 | ) |
269 | 307 |
|
270 | | - toolset = api_registry.get_toolset("test-mcp-server-1") |
| 308 | + toolset = api_registry.get_toolset("test-mcp-server-google") |
271 | 309 |
|
272 | 310 | MockMcpToolset.assert_called_once_with( |
273 | 311 | connection_params=StreamableHTTPConnectionParams( |
274 | | - url="https://mcp.server1.com", |
| 312 | + url="https://mcp.googleapis.com", |
275 | 313 | headers={ |
276 | 314 | "Authorization": "Bearer mock_token", |
277 | 315 | "x-goog-user-project": "quota-project", |
@@ -312,7 +350,7 @@ async def test_get_toolset_with_filter_and_prefix( |
312 | 350 | MockMcpToolset.assert_called_once_with( |
313 | 351 | connection_params=StreamableHTTPConnectionParams( |
314 | 352 | url="https://mcp.server1.com", |
315 | | - headers={"Authorization": "Bearer mock_token"}, |
| 353 | + headers={}, |
316 | 354 | ), |
317 | 355 | tool_filter=tool_filter, |
318 | 356 | tool_name_prefix=tool_name_prefix, |
@@ -348,7 +386,7 @@ def test_get_toolset_url_scheme(self): |
348 | 386 | MockMcpToolset.assert_called_once_with( |
349 | 387 | connection_params=StreamableHTTPConnectionParams( |
350 | 388 | url=mock_url, |
351 | | - headers={"Authorization": "Bearer mock_token"}, |
| 389 | + headers={}, |
352 | 390 | ), |
353 | 391 | tool_filter=None, |
354 | 392 | tool_name_prefix=None, |
|
0 commit comments