@@ -75,15 +75,16 @@ def snake_to_lower_camel(snake_case_string: str):
7575
7676AuthPreparationState = Literal ["pending" , "done" ]
7777
78- HttpxClientFactory = Callable [... , httpx .AsyncClient ]
79- """Type alias for a factory returning an ``httpx.AsyncClient``.
78+ HttpxClientFactory = Callable [[] , httpx .AsyncClient ]
79+ """Type alias for a zero-argument factory returning an ``httpx.AsyncClient``.
8080
8181When supplied to ``RestApiTool`` or ``OpenAPIToolset``, the factory is invoked
82- once per API call and its returned client is used (as an async context
83- manager) to issue the request, in place of the default
84- ``httpx.AsyncClient(verify=..., timeout=None)``. This unlocks knobs that the
85- narrower ``ssl_verify`` parameter can't reach: proxies, HTTP/2, custom
86- transports (e.g. request-signing), shared connection pools, and so on.
82+ once per API call and its returned client is used as an async context manager
83+ to issue the request, in place of the default
84+ ``httpx.AsyncClient(verify=..., timeout=None)``. Because the client is closed
85+ when the request completes, the factory must return a fresh client on every
86+ call. This unlocks knobs that the narrower ``ssl_verify`` parameter can't
87+ reach: proxies, HTTP/2, custom transports (e.g. request-signing), and so on.
8788"""
8889
8990
@@ -155,13 +156,14 @@ def __init__(
155156 context. Useful for adding custom headers like correlation IDs,
156157 authentication tokens, or other request metadata.
157158 httpx_client_factory: Optional zero-argument callable returning an
158- ``httpx.AsyncClient``. When provided, the returned client is used to
159- issue the request, allowing callers to configure proxies, HTTP/2,
160- custom transports (e.g. request signing), shared connection pools,
161- or any other ``httpx.AsyncClient`` option that ``ssl_verify`` can't
162- reach. When ``None`` (default), behaviour is unchanged: a fresh
163- ``httpx.AsyncClient(verify=..., timeout=None)`` is created per
164- request. Mirrors the pattern exposed for MCP by
159+ ``httpx.AsyncClient``. When provided, the returned client is used as
160+ an async context manager to issue the request and is closed once the
161+ request completes, so the factory must return a fresh client on each
162+ call. This lets callers configure proxies, HTTP/2, custom transports
163+ (e.g. request signing), or any other ``httpx.AsyncClient`` option
164+ that ``ssl_verify`` can't reach. When ``None`` (default), behaviour
165+ is unchanged: a fresh ``httpx.AsyncClient(verify=..., timeout=None)``
166+ is created per request. Mirrors the pattern exposed for MCP by
165167 ``StreamableHTTPConnectionParams.httpx_client_factory``.
166168 credential_key: Optional stable key used for interactive auth and
167169 credential caching.
0 commit comments