44
55import contextlib
66import logging
7+ from datetime import timedelta
78from collections .abc import AsyncGenerator , Awaitable , Callable
89from contextlib import asynccontextmanager
910from dataclasses import dataclass
@@ -640,16 +641,26 @@ async def terminate_session(self, client: httpx2.AsyncClient) -> None:
640641async def streamable_http_client (
641642 url : str ,
642643 * ,
644+ headers : dict [str , str ] | None = None ,
645+ timeout : httpx2 .Timeout | timedelta | None = None ,
646+ auth : httpx2 .Auth | None = None ,
643647 http_client : httpx2 .AsyncClient | None = None ,
644648 terminate_on_close : bool = True ,
645649) -> AsyncGenerator [TransportStreams , None ]:
646650 """Client transport for StreamableHTTP.
647651
648652 Args:
649653 url: The MCP server endpoint URL.
654+ headers: Optional HTTP headers to include with every request, including
655+ during auth discovery. A ``User-Agent`` header set here will be
656+ forwarded to OAuth metadata discovery requests. Ignored when
657+ ``http_client`` is provided.
658+ timeout: Request timeout. Ignored when ``http_client`` is provided.
659+ auth: Optional httpx2 authentication handler (e.g. OAuth). Ignored
660+ when ``http_client`` is provided.
650661 http_client: Optional pre-configured httpx2.AsyncClient. If None, a default
651- client with recommended MCP timeouts will be created. To configure headers,
652- authentication, or other HTTP settings, create an httpx2.AsyncClient and pass it here.
662+ client is created using ``headers``, ``timeout``, and ``auth`` if provided.
663+ To configure other HTTP settings, create an httpx2.AsyncClient and pass it here.
653664 terminate_on_close: If True, send a DELETE request to terminate the session when the context exits.
654665
655666 Yields:
@@ -665,8 +676,10 @@ async def streamable_http_client(
665676 client = http_client
666677
667678 if client is None :
668- # Create default client with recommended MCP timeouts
669- client = create_mcp_http_client ()
679+ # Normalize timedelta → httpx2.Timeout for caller convenience
680+ if isinstance (timeout , timedelta ):
681+ timeout = httpx2 .Timeout (timeout .total_seconds ())
682+ client = create_mcp_http_client (headers = headers , timeout = timeout , auth = auth )
670683
671684 transport = StreamableHTTPTransport (url )
672685
0 commit comments