Skip to content

[Bug] Client(verify=...) replaces a caller-provided OAuth httpx_client_factory #5848

Closed

Description

@BlueX888

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 custom

Observed 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

  1. added
    authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    clientRelated to the FastMCP client SDK or client-side functionality.
    on Oct 19, 2026
  2. added a commit that references this issue on Nov 10, 2026
    b7c6568
  3. added a commit that references this issue on Nov 10, 2026
    95c9608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.clientRelated to the FastMCP client SDK or client-side functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions