Skip to content

Commit fa8d4b2

Browse files
committed
Apply optional GET SSE workaround on top of v1.27.0
Adds `enable_get_stream: bool = True` parameter to streamable_http_client. Setting False skips the GET SSE setup, avoiding the OAuthClientProvider context.lock deadlock that blocks tools/call POST for ~16s on lazy MCP connect. Workaround for upstream issue: modelcontextprotocol#1326 Backward compatible: default True preserves existing behavior.
1 parent 6524782 commit fa8d4b2

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/mcp/client/streamable_http.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ async def streamable_http_client(
602602
url: str,
603603
*,
604604
http_client: httpx.AsyncClient | None = None,
605+
enable_get_stream: bool = True,
605606
terminate_on_close: bool = True,
606607
) -> AsyncGenerator[
607608
tuple[
@@ -654,7 +655,8 @@ async def streamable_http_client(
654655
await stack.enter_async_context(client)
655656

656657
def start_get_stream() -> None:
657-
tg.start_soon(transport.handle_get_stream, client, read_stream_writer)
658+
if enable_get_stream:
659+
tg.start_soon(transport.handle_get_stream, client, read_stream_writer)
658660

659661
tg.start_soon(
660662
transport.post_writer,
@@ -687,6 +689,7 @@ async def streamablehttp_client(
687689
url: str,
688690
headers: dict[str, str] | None = None,
689691
timeout: float | timedelta = 30,
692+
enable_get_stream: bool = True,
690693
sse_read_timeout: float | timedelta = 60 * 5,
691694
terminate_on_close: bool = True,
692695
httpx_client_factory: McpHttpClientFactory = create_mcp_http_client,
@@ -717,6 +720,7 @@ async def streamablehttp_client(
717720
async with streamable_http_client(
718721
url,
719722
http_client=client,
723+
enable_get_stream=enable_get_stream,
720724
terminate_on_close=terminate_on_close,
721725
) as streams:
722726
yield streams

0 commit comments

Comments
 (0)