11import anyio
22import pytest
3- from pydantic import AnyUrl
43
54from mcp .server .fastmcp import FastMCP
65from mcp .shared .memory import create_connected_server_and_client_session as create_session
76
8- _resource_name = "slow://slow_resource"
9-
107
118@pytest .mark .anyio
129async def test_messages_are_executed_concurrently ():
@@ -23,25 +20,27 @@ async def sleep_tool():
2320 call_order .append ("tool_end" )
2421 return "done"
2522
26- @server .resource ( _resource_name )
27- async def slow_resource ():
23+ @server .tool ( "trigger" )
24+ async def trigger ():
2825 # Wait for tool to start before setting the event
2926 await tool_started .wait ()
27+ call_order .append ("trigger_started" )
3028 event .set ()
31- call_order .append ("resource_end " )
29+ call_order .append ("trigger_end " )
3230 return "slow"
3331
3432 async with create_session (server ._mcp_server ) as client_session :
3533 # First tool will wait on event, second will set it
3634 async with anyio .create_task_group () as tg :
3735 # Start the tool first (it will wait on event)
3836 tg .start_soon (client_session .call_tool , "sleep" )
39- # Then the resource (it will set the event)
40- tg . start_soon ( client_session .read_resource , AnyUrl ( _resource_name ) )
37+ # Then the trigger tool will set the event to allow the first tool to continue
38+ await client_session .call_tool ( "trigger" )
4139
4240 # Verify that both ran concurrently
4341 assert call_order == [
4442 "waiting_for_event" ,
45- "resource_end" ,
43+ "trigger_started" ,
44+ "trigger_end" ,
4645 "tool_end" ,
4746 ], f"Expected concurrent execution, but got: { call_order } "
0 commit comments