Skip to content

Commit 1ad8864

Browse files
wukathcopybara-github
authored andcommitted
fix: Fix MCP debug client factory compatibility with keyword-only factories
Pass keyword arguments instead of positional arguments to the base_factory in _DebugHttpxClientFactory.__call__. This resolves a regression introduced in cl/938200678 where positional arguments were passed to factories that only accept keyword arguments (e.g., EnvoylopeStreamableHTTPConnectionParams). Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 938765189
1 parent 6a50b8d commit 1ad8864

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/google/adk/tools/mcp_tool/mcp_session_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def __call__(
233233
timeout: httpx.Timeout | None = None,
234234
auth: httpx.Auth | None = None,
235235
) -> httpx.AsyncClient:
236-
client = self._base_factory(headers, timeout, auth)
236+
client = self._base_factory(headers=headers, timeout=timeout, auth=auth)
237237
if hasattr(client, 'event_hooks') and isinstance(client.event_hooks, dict):
238238
client.event_hooks.setdefault('response', []).append(self._response_hook)
239239
return client

tests/unittests/tools/mcp_tool/test_mcp_session_manager.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,3 +1430,22 @@ async def test_response_hook_skips_sse_body(self):
14301430
assert record["response_body"] == "<SSE stream>"
14311431
mock_response.aread.assert_not_called()
14321432
await base_client.aclose()
1433+
1434+
@pytest.mark.asyncio
1435+
async def test_debug_factory_passes_keyword_arguments(self):
1436+
"""Test that the debug factory passes keyword arguments to base_factory."""
1437+
base_client = httpx.AsyncClient()
1438+
1439+
# A factory function that only accepts keyword arguments
1440+
def keyword_only_factory(**kwargs) -> httpx.AsyncClient:
1441+
assert "headers" in kwargs
1442+
assert "timeout" in kwargs
1443+
assert "auth" in kwargs
1444+
return base_client
1445+
1446+
debug_factory = _DebugHttpxClientFactory(keyword_only_factory)
1447+
1448+
# Should work when called with positional arguments (which maps them to parameter names)
1449+
client = debug_factory({"X-Test": "Val"}, None, None)
1450+
assert client is base_client
1451+
await base_client.aclose()

0 commit comments

Comments
 (0)