-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
🔴 Required Information
Is your feature request related to a specific problem?
I'm always frustrated when I cannot customize the httpx.AsyncClient for MCP connections using the SSE transport, while the same capability is fully supported for Streamable HTTP transport.
Currently, the SseConnectionParams model in /src/google/adk/tools/mcp_tool/mcp_session_manager.py does not include the httpx_client_factory parameter, even though the underlying sse_client function from the official MCP Python SDK natively supports this parameter. In contrast, the StreamableHTTPConnectionParams model already exposes this parameter, creating inconsistent behavior between the two MCP transport types.
This gap prevents users from configuring custom HTTP client logic for SSE-based MCP connections, including custom authentication flows, enterprise proxy settings, TLS certificate configurations, advanced timeout policies, and other httpx client customizations that are critical for integrating with many production MCP services.
Describe the Solution You'd Like
I request two aligned changes to achieve feature parity between SSE and Streamable HTTP transports for MCP tools:
- Update the
SseConnectionParamsPydantic model to add thehttpx_client_factoryfield, matching the implementation pattern ofStreamableHTTPConnectionParams:- Add the field with type
CheckableMcpHttpClientFactory, default valuecreate_mcp_http_client
- Add the field with type
- Modify the SSE client initialization logic in
mcp_session_manager.pyto pass thehttpx_client_factoryparameter fromSseConnectionParamsinto thesse_clientfunction call, aligning with how Streamable HTTP transport handles the factory.
These changes will not introduce breaking changes, as the parameter will have a sensible default matching the current behavior, and will fully align the customization capabilities of the two MCP transport types.
Impact on your work
This feature is critical for my team's ability to integrate with third-party and internal MCP services. Many standard-compliant MCP servers only expose SSE transport endpoints, and we require custom httpx.AsyncClient configurations to connect to them: including auto-refreshing OAuth2 authentication, corporate proxy routing, and internal PKI TLS certificate setup.
Without this feature, we cannot use ADK's MCP tooling with these SSE-only MCP services, forcing us to build and maintain custom MCP integration logic outside of the ADK framework. We would like to see this feature implemented as soon as possible to unblock our production agent development.
Willingness to contribute
Yes
🟡 Recommended Information
Describe Alternatives You've Considered
- Subclassing
SseConnectionParams: I tried extending the model to add thehttpx_client_factoryfield, but the core session manager code does not read or pass this parameter to thesse_clientfunction, so this had no effect. - Rewrite model: Custom rewrite the mcp_session_manager.py module file. In the code, utilize the rewritten mcp_session_manager to hack into the runtime. This will cause a split in the Google ADK.”
- Migrating to Streamable HTTP transport: This is not a viable workaround, as most of the MCP services we need to integrate with only support SSE transport per the MCP specification.
Proposed API / Implementation
1. Updated SseConnectionParams model: Add httpx_client_factory parameter
class SseConnectionParams(BaseModel):
"""Parameters for the MCP SSE connection.
See MCP SSE Client documentation for more details.
https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py
Attributes:
url: URL for the MCP SSE server.
headers: Headers for the MCP SSE connection.
timeout: Timeout in seconds for establishing the connection to the MCP SSE
server.
sse_read_timeout: Timeout in seconds for reading data from the MCP SSE
server.
httpx_client_factory: Factory function to create a custom HTTPX client. If
not provided, a default factory will be used.
"""
model_config = ConfigDict(arbitrary_types_allowed=True)
url: str
headers: dict[str, Any] | None = None
timeout: float = 5.0
sse_read_timeout: float = 60 * 5.0
httpx_client_factory: CheckableMcpHttpClientFactory = create_mcp_http_client2. Updated SSE client initialization
elif isinstance(self._connection_params, SseConnectionParams):
client = sse_client(
url=self._connection_params.url,
headers=merged_headers,
timeout=self._connection_params.timeout,
sse_read_timeout=self._connection_params.sse_read_timeout,
httpx_client_factory=self._connection_params.httpx_client_factory,
)Additional Context
- The underlying
sse_clientfunction from the MCP Python SDK already fully supports thehttpx_client_factoryparameter, as confirmed in the official SDK source code: https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L31-L36 - The
StreamableHTTPConnectionParamsmodel already implements this exact pattern, so this change will only bring API consistency between the two transport types, with no new architectural patterns introduced. - This change is fully backward compatible, as the new parameter uses the existing default
create_mcp_http_clientfactory, preserving all current behavior for existing users.