diff --git a/pydantic_ai_slim/pydantic_ai/mcp.py b/pydantic_ai_slim/pydantic_ai/mcp.py index be8797615c..e40b40e6d6 100644 --- a/pydantic_ai_slim/pydantic_ai/mcp.py +++ b/pydantic_ai_slim/pydantic_ai/mcp.py @@ -2771,6 +2771,7 @@ def factory( headers: dict[str, str] | None = None, timeout: httpx.Timeout | None = None, auth: httpx.Auth | None = None, + **_kwargs: Any, ) -> httpx.AsyncClient: return http_client diff --git a/tests/test_mcp_toolset.py b/tests/test_mcp_toolset.py index 8eeac1839d..e65e3a67de 100644 --- a/tests/test_mcp_toolset.py +++ b/tests/test_mcp_toolset.py @@ -107,6 +107,17 @@ def test_sse_url_with_http_client_uses_factory(self): assert toolset.client.transport.httpx_client_factory is not None assert toolset.client.transport.httpx_client_factory() is client + def test_http_client_factory_tolerates_extra_kwargs(self): + """The factory returned by _make_httpx_client_factory must accept extra + kwargs (e.g. ``follow_redirects``) that FastMCP transports may pass.""" + client = httpx.AsyncClient() + toolset = MCPToolset('https://example.com/mcp', http_client=client) + factory = toolset.client.transport.httpx_client_factory + assert factory is not None + # FastMCP's StreamableHttpTransport passes follow_redirects= + result = factory(follow_redirects=True) + assert result is client + def test_http_kwargs_with_non_url_input_raises(self): """HTTP-only kwargs (headers/auth/verify/http_client) must error out when the connection target isn't an HTTP URL — otherwise the kwargs are silently dropped on stdio / Path /