@@ -2339,15 +2339,17 @@ async def test_streamable_http_client_reconnect_failure_propagates_error() -> No
23392339 "content-type" : "application/json" ,
23402340 "mcp-session-id" : "test-session" ,
23412341 }
2342- mock_response .aread .return_value = json .dumps ({
2343- "jsonrpc" : "2.0" ,
2344- "id" : 1 ,
2345- "result" : {
2346- "protocolVersion" : "2025-06-18" ,
2347- "capabilities" : {},
2348- "serverInfo" : {"name" : "test-server" , "version" : "1.0" },
2342+ mock_response .aread .return_value = json .dumps (
2343+ {
2344+ "jsonrpc" : "2.0" ,
2345+ "id" : 1 ,
2346+ "result" : {
2347+ "protocolVersion" : "2025-06-18" ,
2348+ "capabilities" : {},
2349+ "serverInfo" : {"name" : "test-server" , "version" : "1.0" },
2350+ },
23492351 }
2350- } ).encode ("utf-8" )
2352+ ).encode ("utf-8" )
23512353
23522354 mock_initialized_response = AsyncMock (spec = httpx2 .Response )
23532355 mock_initialized_response .status_code = 202
@@ -2361,47 +2363,50 @@ async def mock_stream(*args: Any, **kwargs: Any):
23612363
23622364 client .stream = mock_stream
23632365
2364-
23652366 # Mock client.sse to raise httpx2.HTTPError
23662367 client .sse .side_effect = httpx2 .HTTPError ("SSE connection refused" )
23672368
23682369 # Patch anyio.sleep to avoid waiting during reconnect attempts
23692370 with patch ("mcp.client.streamable_http.anyio.sleep" , new_callable = AsyncMock ) as mock_sleep :
23702371 with pytest .raises (StreamableHTTPError ) as exc_info :
23712372 with anyio .fail_after (5 ):
2372- async with streamable_http_client ("http://localhost:8000/mcp" , http_client = client ) as (read_stream , write_stream ):
2373+ async with streamable_http_client ("http://localhost:8000/mcp" , http_client = client ) as (
2374+ read_stream ,
2375+ write_stream ,
2376+ ):
23732377 # Send initialize message
2374- await write_stream .send (SessionMessage (
2375- types .JSONRPCRequest (
2376- jsonrpc = "2.0" ,
2377- id = 1 ,
2378- method = "initialize" ,
2379- params = {
2380- "protocolVersion" : "2025-06-18" ,
2381- "capabilities" : {},
2382- "clientInfo" : {"name" : "test-client" , "version" : "1.0" },
2383- },
2378+ await write_stream .send (
2379+ SessionMessage (
2380+ types .JSONRPCRequest (
2381+ jsonrpc = "2.0" ,
2382+ id = 1 ,
2383+ method = "initialize" ,
2384+ params = {
2385+ "protocolVersion" : "2025-06-18" ,
2386+ "capabilities" : {},
2387+ "clientInfo" : {"name" : "test-client" , "version" : "1.0" },
2388+ },
2389+ )
23842390 )
2385- ))
2391+ )
23862392
23872393 # Receive the response
23882394 await read_stream .receive ()
23892395
23902396 # Send notifications/initialized (which will trigger start_get_stream)
2391- await write_stream .send (SessionMessage (
2392- types .JSONRPCNotification (
2393- jsonrpc = "2.0" ,
2394- method = "notifications/initialized" ,
2397+ await write_stream .send (
2398+ SessionMessage (
2399+ types .JSONRPCNotification (
2400+ jsonrpc = "2.0" ,
2401+ method = "notifications/initialized" ,
2402+ )
23952403 )
2396- ))
2404+ )
23972405
23982406 # Wait for the task group to fail
23992407 event = anyio .Event ()
24002408 await event .wait ()
24012409
2402-
24032410 assert "Failed to connect to GET stream" in str (exc_info .value )
24042411 assert client .sse .call_count == 2
24052412 mock_sleep .assert_called_once_with (1.0 )
2406-
2407-
0 commit comments