@@ -172,7 +172,8 @@ async def handle_call_tool(name: str, args: dict) -> list[TextContent]:
172172 related_request_id = ctx .request_id , # need for stream association
173173 )
174174
175- await anyio .sleep (0.1 )
175+ # need to wait for long enough that the client can reliably stop the tool before this finishes
176+ await anyio .sleep (1 )
176177
177178 await ctx .session .send_log_message (
178179 level = "info" ,
@@ -181,6 +182,16 @@ async def handle_call_tool(name: str, args: dict) -> list[TextContent]:
181182 related_request_id = ctx .request_id ,
182183 )
183184
185+ # Adding another message just to make it even less likely that this tool will exit before the client can stop it
186+ await anyio .sleep (1 )
187+
188+ await ctx .session .send_log_message (
189+ level = "info" ,
190+ data = "Tool is done" ,
191+ logger = "tool" ,
192+ related_request_id = ctx .request_id ,
193+ )
194+
184195 return [TextContent (type = "text" , text = "Completed!" )]
185196
186197 elif name == "test_sampling_tool" :
@@ -1033,6 +1044,7 @@ async def test_streamablehttp_client_resumption(event_server):
10331044 """Test client session to resume a long running tool."""
10341045 _ , server_url = event_server
10351046
1047+ print ("what is happening" )
10361048 # Variables to track the state
10371049 captured_session_id = None
10381050 captured_resumption_token = None
@@ -1099,6 +1111,10 @@ async def run_tool():
10991111 await anyio .sleep (0.1 )
11001112 tg .cancel_scope .cancel ()
11011113
1114+ # Make sure we only have one notification.. otherwise the test is flaky
1115+ # More than one notification means the tool likely could have finished already and will not call the message handler again upon resumption
1116+ assert len (captured_notifications ) == 1
1117+
11021118 # Store pre notifications and clear the captured notifications
11031119 # for the post-resumption check
11041120 captured_notifications_pre = captured_notifications .copy ()
0 commit comments