@@ -372,31 +372,31 @@ async def test_tool_progress(server_transport: str, server_url: str) -> None:
372372
373373 async with client_cm as client_streams :
374374 read_stream , write_stream = unpack_streams (client_streams )
375- async with ClientSession (read_stream , write_stream ) as session :
376- # Set up notification handler
377- session .request_context .session .notification_handler = (
378- notification_collector .handle_generic_notification
379- )
380-
375+ async with ClientSession (
376+ read_stream ,
377+ write_stream ,
378+ message_handler = notification_collector .handle_generic_notification ,
379+ ) as session :
381380 # Test initialization
382381 result = await session .initialize ()
383382 assert isinstance (result , InitializeResult )
384383 assert result .serverInfo .name == "Progress Example"
385384 assert result .capabilities .tools is not None
386385
387- # Test slow_operation tool that reports progress
388- tool_result = await session .call_tool ("slow_operation" , {"duration" : 1 })
386+ # Test long_running_task tool that reports progress
387+ tool_result = await session .call_tool (
388+ "long_running_task" , {"task_name" : "test" , "steps" : 3 }
389+ )
389390 assert len (tool_result .content ) == 1
390391 assert isinstance (tool_result .content [0 ], TextContent )
391- assert "Completed slow operation " in tool_result .content [0 ].text
392+ assert "Task 'test' completed " in tool_result .content [0 ].text
392393
393- # Verify progress notifications were sent
394- assert len (notification_collector .progress_notifications ) > 0
395- progress_messages = [
396- notif .message for notif in notification_collector .progress_notifications
397- ]
398- assert any ("Starting slow operation" in msg for msg in progress_messages )
399- assert any ("Completed slow operation" in msg for msg in progress_messages )
394+ # Verify that progress notifications or log messages were sent
395+ # Progress can come through either progress notifications or log messages
396+ total_notifications = len (
397+ notification_collector .progress_notifications
398+ ) + len (notification_collector .log_messages )
399+ assert total_notifications > 0
400400
401401
402402# Test sampling
@@ -416,23 +416,20 @@ async def test_sampling(server_transport: str, server_url: str) -> None:
416416
417417 async with client_cm as client_streams :
418418 read_stream , write_stream = unpack_streams (client_streams )
419- async with ClientSession (read_stream , write_stream ) as session :
420- # Set up sampling callback
421- session .request_context .session .sampling_callback = sampling_callback
422-
419+ async with ClientSession (
420+ read_stream , write_stream , sampling_callback = sampling_callback
421+ ) as session :
423422 # Test initialization
424423 result = await session .initialize ()
425424 assert isinstance (result , InitializeResult )
426425 assert result .serverInfo .name == "Sampling Example"
427426 assert result .capabilities .tools is not None
428427
429- # Test analyze_sentiment tool that uses sampling
430- tool_result = await session .call_tool (
431- "analyze_sentiment" , {"text" : "I love this product!" }
432- )
428+ # Test generate_poem tool that uses sampling
429+ tool_result = await session .call_tool ("generate_poem" , {"topic" : "nature" })
433430 assert len (tool_result .content ) == 1
434431 assert isinstance (tool_result .content [0 ], TextContent )
435- assert "sentiment analysis " in tool_result .content [0 ].text . lower ()
432+ assert "This is a simulated LLM response " in tool_result .content [0 ].text
436433
437434
438435# Test elicitation
@@ -452,19 +449,18 @@ async def test_elicitation(server_transport: str, server_url: str) -> None:
452449
453450 async with client_cm as client_streams :
454451 read_stream , write_stream = unpack_streams (client_streams )
455- async with ClientSession (read_stream , write_stream ) as session :
456- # Set up elicitation callback
457- session .request_context .session .elicitation_callback = elicitation_callback
458-
452+ async with ClientSession (
453+ read_stream , write_stream , elicitation_callback = elicitation_callback
454+ ) as session :
459455 # Test initialization
460456 result = await session .initialize ()
461457 assert isinstance (result , InitializeResult )
462458 assert result .serverInfo .name == "Elicitation Example"
463459 assert result .capabilities .tools is not None
464460
465- # Test book_restaurant tool that triggers elicitation
461+ # Test book_table tool that triggers elicitation
466462 tool_result = await session .call_tool (
467- "book_restaurant " , {"date" : "2024-12-25" , "party_size" : 4 }
463+ "book_table " , {"date" : "2024-12-25" , "time" : "19:00 " , "party_size" : 4 }
468464 )
469465 assert len (tool_result .content ) == 1
470466 assert isinstance (tool_result .content [0 ], TextContent )
@@ -493,16 +489,18 @@ async def test_completion(server_transport: str, server_url: str) -> None:
493489 # Test initialization
494490 result = await session .initialize ()
495491 assert isinstance (result , InitializeResult )
496- assert result .serverInfo .name == "Completion Example"
497- assert result . capabilities . tools is not None
492+ assert result .serverInfo .name == "Example"
493+ # Note: Completion server supports completion, not tools
498494
499- # Test complete_argument tool
500- tool_result = await session .call_tool (
501- "complete_argument" , {"prefix" : "def hello_wor" }
495+ # Test completion functionality - list prompts first
496+ prompts = await session .list_prompts ()
497+ assert len (prompts .prompts ) > 0
498+
499+ # Test getting a prompt
500+ prompt_result = await session .get_prompt (
501+ "review_code" , {"language" : "python" , "code" : "def test(): pass" }
502502 )
503- assert len (tool_result .content ) == 1
504- assert isinstance (tool_result .content [0 ], TextContent )
505- assert "hello_world" in tool_result .content [0 ].text
503+ assert len (prompt_result .messages ) > 0
506504
507505
508506# Test notifications
@@ -524,42 +522,28 @@ async def test_notifications(server_transport: str, server_url: str) -> None:
524522
525523 async with client_cm as client_streams :
526524 read_stream , write_stream = unpack_streams (client_streams )
527- async with ClientSession (read_stream , write_stream ) as session :
528- # Set up notification handler
529- session .request_context .session .notification_handler = (
530- notification_collector .handle_generic_notification
531- )
532-
525+ async with ClientSession (
526+ read_stream ,
527+ write_stream ,
528+ message_handler = notification_collector .handle_generic_notification ,
529+ ) as session :
533530 # Test initialization
534531 result = await session .initialize ()
535532 assert isinstance (result , InitializeResult )
536533 assert result .serverInfo .name == "Notifications Example"
537534 assert result .capabilities .tools is not None
538535
539- # Test send_notification tool
540- tool_result = await session .call_tool (
541- "send_notification" , {"message" : "Test notification" }
542- )
536+ # Test process_data tool that sends log notifications
537+ tool_result = await session .call_tool ("process_data" , {"data" : "test_data" })
543538 assert len (tool_result .content ) == 1
544539 assert isinstance (tool_result .content [0 ], TextContent )
545- assert "Notification sent" in tool_result .content [0 ].text
546-
547- # Verify log notification was sent
548- assert len (notification_collector .log_messages ) > 0
549- log_message = notification_collector .log_messages [0 ]
550- assert log_message .level == "info"
551- assert "Test notification" in log_message .data
540+ assert "Processed: test_data" in tool_result .content [0 ].text
552541
553- # Test add_dynamic_tool to trigger tool list change notification
554- await session .call_tool ("add_dynamic_tool" , {"tool_name" : "dynamic_test" })
555-
556- # Verify tool list change notification was sent
557- assert len (notification_collector .tool_notifications ) > 0
558-
559- # Test add_dynamic_resource to trigger resource list change notification
560- await session .call_tool (
561- "add_dynamic_resource" , {"resource_name" : "dynamic_resource" }
562- )
542+ # Verify log messages were sent at different levels
543+ assert len (notification_collector .log_messages ) >= 1
544+ log_levels = {msg .level for msg in notification_collector .log_messages }
545+ # Should have at least one of these log levels
546+ assert log_levels & {"debug" , "info" , "warning" , "error" }
563547
564548 # Verify resource list change notification was sent
565549 assert len (notification_collector .resource_notifications ) > 0
0 commit comments