@@ -1809,6 +1809,46 @@ def test_streamable_http_transport_includes_seeded_session_id_header():
18091809 assert headers ["mcp-session-id" ] == "resume-session-id"
18101810
18111811
1812+ @pytest .mark .anyio
1813+ async def test_streamable_http_client_resumption_starts_get_stream_once (monkeypatch : pytest .MonkeyPatch ):
1814+ start_count = 0
1815+
1816+ async def fake_handle_get_stream (
1817+ self : StreamableHTTPTransport ,
1818+ client : httpx .AsyncClient ,
1819+ read_stream_writer : anyio .abc .ObjectSendStream [SessionMessage | Exception ],
1820+ ) -> None :
1821+ nonlocal start_count
1822+ start_count += 1
1823+ await anyio .sleep (0 )
1824+
1825+ async def fake_post_writer (
1826+ self : StreamableHTTPTransport ,
1827+ client : httpx .AsyncClient ,
1828+ write_stream_reader : anyio .abc .ObjectReceiveStream [SessionMessage ],
1829+ read_stream_writer : anyio .abc .ObjectSendStream [SessionMessage | Exception ],
1830+ write_stream : anyio .abc .ObjectSendStream [SessionMessage ],
1831+ start_get_stream : Any ,
1832+ tg : anyio .abc .TaskGroup ,
1833+ ) -> None :
1834+ # Call twice; the second call should hit the early return guard.
1835+ start_get_stream ()
1836+ start_get_stream ()
1837+ await anyio .sleep (0 )
1838+
1839+ monkeypatch .setattr (StreamableHTTPTransport , "handle_get_stream" , fake_handle_get_stream )
1840+ monkeypatch .setattr (StreamableHTTPTransport , "post_writer" , fake_post_writer )
1841+
1842+ async with streamable_http_client (
1843+ "http://localhost:8000/mcp" ,
1844+ session_id = "resume-session-id" ,
1845+ terminate_on_close = False ,
1846+ ):
1847+ await anyio .sleep (0 )
1848+
1849+ assert start_count == 1
1850+
1851+
18121852@pytest .mark .anyio
18131853async def test_priming_event_not_sent_for_old_protocol_version ():
18141854 """Test that _maybe_send_priming_event skips for old protocol versions (backwards compat)."""
0 commit comments