Repository navigation
Description
Summary
Wrapping an already-configured transport with Client(transport, verify=True) silently replaces an OAuth client factory supplied by the caller:
transport = StreamableHttpTransport(url, auth=OAuth(httpx_client_factory=custom))
Client(transport, verify=True)
# transport.auth.httpx_client_factory is no longer `custom`The loss affects every OAuth discovery/preflight request the auth provider makes, so proxy headers, mTLS configuration, custom timeouts, or retry policies installed on that factory disappear. The transports themselves only inject a factory when it is still the bare httpx2.AsyncClient default (client/transports/http.py:110-119, sse.py:82-91), so caller-supplied factories are supposed to take precedence.
Reproduction (current main adf90b6, offline)
custom = lambda: httpx2.AsyncClient(proxy="http://proxy.internal:8080")
transport = StreamableHttpTransport("https://example.test/mcp", auth=OAuth(httpx_client_factory=custom))
print(transport.auth.httpx_client_factory is custom) # True
Client(transport, verify=True)
print(transport.auth.httpx_client_factory) # transport-generated verify factory, not customObserved False/replaced; expected the custom factory to survive while verify still applies wherever no caller factory exists.
Root cause
fastmcp_slim/fastmcp/client/client.py (~476-483): when verify is supplied, the client rebuilds the OAuth provider's factory whenever transport.httpx_client_factory is None, without checking transport.auth.httpx_client_factory. That guard is wrong for a caller-attached OAuth factory, and it also needs to keep overriding a factory the transport itself generated from its own verify setting.
Suggested fix
Only replace the OAuth factory when it is the bare default or a transport-generated verify factory (tag those at creation); preserve any caller-supplied factory. Keep the existing Client(transport, verify=True) override of a transport-level verify=False working.
Tests
A fix with six regression tests is ready (custom OAuth factory preserved over HTTP and SSE, default factory still resynced, no-auth transport unchanged for each). I'll open the linked PR with red/green evidence.
Activity
fix(client): preserve a caller-provided OAuth httpx client factory wh…
[4.1] Backport fixes for 4.1.8 (#6415)