@@ -72,14 +72,15 @@ class RequestContext:
7272class StreamableHTTPTransport :
7373 """StreamableHTTP client transport implementation."""
7474
75- def __init__ (self , url : str ) -> None :
75+ def __init__ (self , url : str , session_id : str | None = None ) -> None :
7676 """Initialize the StreamableHTTP transport.
7777
7878 Args:
7979 url: The endpoint URL.
80+ session_id: Optional pre-existing MCP session ID to resume.
8081 """
8182 self .url = url
82- self .session_id : str | None = None
83+ self .session_id : str | None = session_id
8384 self .protocol_version : str | None = None
8485
8586 def _prepare_headers (self ) -> dict [str , str ]:
@@ -512,6 +513,7 @@ async def streamable_http_client(
512513 * ,
513514 http_client : httpx .AsyncClient | None = None ,
514515 terminate_on_close : bool = True ,
516+ session_id : str | None = None ,
515517) -> AsyncGenerator [TransportStreams , None ]:
516518 """Client transport for StreamableHTTP.
517519
@@ -521,6 +523,8 @@ async def streamable_http_client(
521523 client with recommended MCP timeouts will be created. To configure headers,
522524 authentication, or other HTTP settings, create an httpx.AsyncClient and pass it here.
523525 terminate_on_close: If True, send a DELETE request to terminate the session when the context exits.
526+ session_id: Optional pre-existing MCP session ID to include in requests,
527+ enabling explicit session resumption.
524528
525529 Yields:
526530 Tuple containing:
@@ -538,7 +542,7 @@ async def streamable_http_client(
538542 # Create default client with recommended MCP timeouts
539543 client = create_mcp_http_client ()
540544
541- transport = StreamableHTTPTransport (url )
545+ transport = StreamableHTTPTransport (url , session_id = session_id )
542546
543547 logger .debug (f"Connecting to StreamableHTTP endpoint: { url } " )
544548
0 commit comments