@@ -22,6 +22,11 @@ class StreamableHTTPServerParams(BaseModel):
2222 url : str
2323 headers : dict [str , Any ] | None = None
2424 timeout : float = 30
25+ # Whether the httpx client trusts the ambient environment (HTTP(S)_PROXY,
26+ # SSL_CERT_FILE/DIR, .netrc). Defaults to httpx's default (True). Set False to
27+ # reach the endpoint directly without an ambient egress proxy, e.g. for an
28+ # in-cluster URL on a host whose external egress is proxied.
29+ trust_env : bool = True
2530
2631
2732class MCPClientStreamableHTTP (MCPClientBase ):
@@ -50,15 +55,16 @@ async def _get_transport(
5055 MemoryObjectReceiveStream [SessionMessage | Exception ],
5156 MemoryObjectSendStream [SessionMessage ],
5257 ]:
53- # trust_env=False so the client does not inherit an ambient HTTP(S)_PROXY:
54- # the MCP endpoint is reached directly, and routing it through an egress
55- # proxy meant for external traffic can make the connection hang.
58+ # trust_env controls whether the client inherits the ambient
59+ # HTTP(S)_PROXY / cert / netrc env. Set it False (see params) to reach an
60+ # in-cluster endpoint directly, bypassing a proxy meant for external
61+ # traffic that would make the connection hang.
5662 http_client = await exit_stack .enter_async_context (
5763 httpx .AsyncClient (
5864 headers = self ._params .headers ,
5965 timeout = self ._params .timeout ,
6066 follow_redirects = True ,
61- trust_env = False ,
67+ trust_env = self . _params . trust_env ,
6268 )
6369 )
6470 read_stream , write_stream , _ = await exit_stack .enter_async_context (
0 commit comments