feat(mcp): expose auth and httpx_client_factory in SSE/StreamableHttp params#2713
Merged
seratch merged 2 commits intoopenai:mainfrom Mar 19, 2026
Merged
Conversation
… params MCPServerSseParams was missing both auth and httpx_client_factory even though the underlying sse_client supports them. MCPServerStreamableHttpParams was missing auth even though streamablehttp_client supports it. Changes: - Add auth: NotRequired[httpx.Auth | None] to MCPServerSseParams - Add httpx_client_factory: NotRequired[HttpClientFactory] to MCPServerSseParams - Add auth: NotRequired[httpx.Auth | None] to MCPServerStreamableHttpParams - Wire all three through their create_streams() implementations - Refactor MCPServerStreamableHttp.create_streams() to use kwargs dict (eliminates the if/else branch, matching the SSE pattern) This allows users to pass OAuth token-refresh handlers, custom SSL certs, proxies, and other httpx-level authentication/transport config without having to resort to custom subclasses.
seratch
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2712
Summary
Adds missing transport-level parameters to
MCPServerSseParamsandMCPServerStreamableHttpParams, bringing both in line with what the underlying MCP SDK clients already support.authhttpx_client_factoryAlso refactors
MCPServerStreamableHttp.create_streams()to use akwargsdict (matching the new SSE pattern), eliminating theif httpx_client_factory / elsebranch.Changes
src/agents/mcp/server.py: addauth+httpx_client_factorytoMCPServerSseParams, wire throughMCPServerSse.create_streams(); addauthtoMCPServerStreamableHttpParams, refactorcreate_streams()tests/mcp/test_mcp_auth_params.py: 7 new tests covering all new param combinations for both server typesMotivation
The underlying
sse_clientandstreamablehttp_clientfunctions already acceptauth: httpx.Auth | Noneandhttpx_client_factory. Without exposing them in the TypedDicts, users are forced to subclass just to pass standard httpx auth (OAuth token refresh, BasicAuth, custom cert chains, proxies).