@@ -881,81 +881,6 @@ async def test_elicitation_callback(context: RequestContext[ClientSession, None]
881881 pytest .fail (f"Test timed out after { max_polls } polls" )
882882
883883
884- # Test async elicitation tool with stdio transport (works as expected)
885- @pytest .mark .anyio
886- async def test_async_elicitation_tool_stdio () -> None :
887- """Test async elicitation tool functionality using stdio transport.
888-
889- This test works because stdio transport properly handles elicitation during async operations.
890- """
891- import os
892-
893- from mcp import StdioServerParameters
894- from mcp .client .stdio import stdio_client
895-
896- # Use the same server parameters as the client
897- server_params = StdioServerParameters (
898- command = "uv" ,
899- args = ["run" , "server" , "async_tools" , "stdio" ],
900- env = {"UV_INDEX" : os .environ .get ("UV_INDEX" , "" )},
901- )
902-
903- # Use the same elicitation callback as the client
904- async def test_elicitation_callback (context : RequestContext [ClientSession , None ], params : ElicitRequestParams ):
905- """Handle elicitation requests from the server."""
906- logger .debug (f"Client elicitation callback called with message: { params .message } " )
907- if "data_migration" in params .message :
908- logger .debug ("Client accepting elicitation request" )
909- return ElicitResult (
910- action = "accept" ,
911- content = {"continue_processing" : True , "priority_level" : "normal" },
912- )
913- else :
914- logger .debug ("Client declining elicitation request" )
915- return ElicitResult (action = "decline" )
916-
917- async with stdio_client (server_params ) as (read , write ):
918- async with ClientSession (
919- read ,
920- write ,
921- protocol_version = "next" ,
922- elicitation_callback = test_elicitation_callback ,
923- ) as session :
924- # Test initialization
925- result = await session .initialize ()
926- assert isinstance (result , InitializeResult )
927- assert result .serverInfo .name == "Async Tools Demo"
928-
929- # Test async elicitation tool
930- elicit_result = await session .call_tool ("async_elicitation_tool" , {"operation" : "data_migration" })
931- assert elicit_result .operation is not None
932- token = elicit_result .operation .token
933-
934- # Poll for completion
935- max_polls = 20
936- poll_count = 0
937- while poll_count < max_polls :
938- status = await session .get_operation_status (token )
939- if status .status == "completed" :
940- final_result = await session .get_operation_result (token )
941- assert not final_result .result .isError
942- assert len (final_result .result .content ) == 1
943- content = final_result .result .content [0 ]
944- assert isinstance (content , TextContent )
945- assert "Operation 'data_migration'" in content .text
946- assert "completed successfully" in content .text
947- return
948- elif status .status == "failed" :
949- pytest .fail (f"Async elicitation failed: { status .error } " )
950- elif status .status in ("canceled" , "unknown" ):
951- pytest .fail (f"Operation ended with status: { status .status } " )
952-
953- poll_count += 1
954- await asyncio .sleep (0.5 )
955-
956- pytest .fail (f"Test timed out after { max_polls } polls" )
957-
958-
959884# Test async tools example with legacy protocol
960885@pytest .mark .anyio
961886@pytest .mark .parametrize (
0 commit comments