@@ -31,6 +31,11 @@ def start_comprehensive_mcp_server(transport: Literal["sse", "streamable-http"],
3131
3232 mcp = FastMCP ("Comprehensive MCP Server" , port = port )
3333
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+
3439 @mcp .tool (description = "Calculator tool which performs calculations" )
3540 def calculator (x : int , y : int ) -> int :
3641 return x + y
@@ -297,3 +302,27 @@ def slow_transport():
297302 with client :
298303 tools = client .list_tools_sync ()
299304 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