@@ -31,6 +31,11 @@ def start_comprehensive_mcp_server(transport: Literal["sse", "streamable-http"],
31
31
32
32
mcp = FastMCP ("Comprehensive MCP Server" , port = port )
33
33
34
+ @mcp .tool (description = "Tool that will timeout" )
35
+ def timeout_tool () -> str :
36
+ time .sleep (10 )
37
+ return "This tool has timed out"
38
+
34
39
@mcp .tool (description = "Calculator tool which performs calculations" )
35
40
def calculator (x : int , y : int ) -> int :
36
41
return x + y
@@ -297,3 +302,27 @@ def slow_transport():
297
302
with client :
298
303
tools = client .list_tools_sync ()
299
304
assert len (tools ) >= 0 # Should work now
305
+
306
+
307
+ @pytest .mark .skipif (
308
+ condition = os .environ .get ("GITHUB_ACTIONS" ) == "true" ,
309
+ reason = "streamable transport is failing in GitHub actions, debugging if linux compatibility issue" ,
310
+ )
311
+ @pytest .mark .asyncio
312
+ async def test_streamable_http_mcp_client_times_out_before_tool ():
313
+ """Test an mcp server that timesout before the tool is able to respond."""
314
+ server_thread = threading .Thread (
315
+ target = start_comprehensive_mcp_server , kwargs = {"transport" : "streamable-http" , "port" : 8001 }, daemon = True
316
+ )
317
+ server_thread .start ()
318
+ time .sleep (2 ) # wait for server to startup completely
319
+
320
+ def transport_callback () -> MCPTransport :
321
+ return streamablehttp_client (sse_read_timeout = 2 , url = "http://127.0.0.1:8001/mcp" )
322
+
323
+ streamable_http_client = MCPClient (transport_callback )
324
+ with streamable_http_client :
325
+ # Test tools
326
+ result = await streamable_http_client .call_tool_async (tool_use_id = "123" , name = "timeout_tool" )
327
+ assert result ["status" ] == "error"
328
+ assert result ["content" ][0 ]["text" ] == "Tool execution failed: Connection closed"
0 commit comments