@@ -757,6 +757,7 @@ async def test_async_tool_basic(server_transport: str, server_url: str) -> None:
757
757
@pytest .mark .parametrize (
758
758
"server_transport" ,
759
759
[
760
+ # ("async_tool_basic", "sse"),
760
761
("async_tool_basic" , "streamable-http" ),
761
762
],
762
763
indirect = True ,
@@ -795,6 +796,59 @@ async def test_async_tool_basic_legacy_protocol(server_transport: str, server_ur
795
796
assert "Processed: HELLO" in hybrid_result .content [0 ].text
796
797
797
798
799
+ @pytest .mark .anyio
800
+ @pytest .mark .parametrize (
801
+ "server_transport" ,
802
+ [
803
+ # ("async_tool_basic", "sse"),
804
+ ("async_tool_basic" , "streamable-http" ),
805
+ ],
806
+ indirect = True ,
807
+ )
808
+ async def test_async_tool_reconnection (server_transport : str , server_url : str ) -> None :
809
+ """Test that async operations can be retrieved after reconnecting with a new session."""
810
+ transport = server_transport
811
+ client_cm1 = create_client_for_transport (transport , server_url )
812
+
813
+ # Start async operation in first session
814
+ async with client_cm1 as client_streams :
815
+ read_stream , write_stream = unpack_streams (client_streams )
816
+ async with ClientSession (read_stream , write_stream , protocol_version = "next" ) as session1 :
817
+ await session1 .initialize ()
818
+
819
+ # Start async operation
820
+ result = await session1 .call_tool ("process_text" , {"text" : "test data" })
821
+ assert result .operation is not None
822
+ token = result .operation .token
823
+
824
+ # Reconnect with new session and retrieve result
825
+ client_cm2 = create_client_for_transport (transport , server_url )
826
+ async with client_cm2 as client_streams :
827
+ read_stream , write_stream = unpack_streams (client_streams )
828
+ async with ClientSession (read_stream , write_stream , protocol_version = "next" ) as session2 :
829
+ await session2 .initialize ()
830
+
831
+ # Poll for completion in new session
832
+ max_attempts = 20
833
+ attempt = 0
834
+ while attempt < max_attempts :
835
+ status = await session2 .get_operation_status (token )
836
+ if status .status == "completed" :
837
+ final_result = await session2 .get_operation_result (token )
838
+ assert not final_result .result .isError
839
+ assert len (final_result .result .content ) == 1
840
+ content = final_result .result .content [0 ]
841
+ assert isinstance (content , TextContent )
842
+ break
843
+ elif status .status == "failed" :
844
+ pytest .fail (f"Operation failed: { status .error } " )
845
+
846
+ attempt += 1
847
+ await anyio .sleep (0.5 )
848
+ else :
849
+ pytest .fail ("Async operation timed out" )
850
+
851
+
798
852
# Test structured output example
799
853
@pytest .mark .anyio
800
854
@pytest .mark .parametrize (
0 commit comments