@@ -958,4 +958,75 @@ void testLoggingNotification() {
958
958
mcpServer .close ();
959
959
}
960
960
961
+ // ---------------------------------------
962
+ // Progress Tests
963
+ // ---------------------------------------
964
+ @ Test
965
+ void testProgressNotification () {
966
+ // Create a list to store received logging notifications
967
+ List <McpSchema .ProgressNotification > receivedNotifications = new ArrayList <>();
968
+
969
+ // Create server with a tool that sends logging notifications
970
+ McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
971
+ new McpSchema .Tool ("progress-test" , "Test progress notifications" , emptyJsonSchema ),
972
+ (exchange , request ) -> {
973
+
974
+ var progressToken = (String ) request ._meta ().get ("progressToken" );
975
+
976
+ exchange
977
+ .notification (McpSchema .METHOD_NOTIFICATION_PROGRESS ,
978
+ new McpSchema .ProgressNotification (progressToken , 0.1 , 1.0 , "Test progress 1/10" ))
979
+ .block ();
980
+
981
+ exchange
982
+ .notification (McpSchema .METHOD_NOTIFICATION_PROGRESS ,
983
+ new McpSchema .ProgressNotification (progressToken , 0.5 , 1.0 , "Test progress 5/10" ))
984
+ .block ();
985
+
986
+ exchange
987
+ .notification (McpSchema .METHOD_NOTIFICATION_PROGRESS ,
988
+ new McpSchema .ProgressNotification (progressToken , 1.0 , 1.0 , "Test progress 10/10" ))
989
+ .block ();
990
+
991
+ return Mono .just (new CallToolResult ("Progress test completed" , false ));
992
+ });
993
+
994
+ var mcpServer = McpServer .async (mcpServerTransportProvider )
995
+ .serverInfo ("test-server" , "1.0.0" )
996
+ .capabilities (ServerCapabilities .builder ().logging ().tools (true ).build ())
997
+ .tools (tool )
998
+ .build ();
999
+ try (
1000
+ // Create client with progress notification handler
1001
+ var mcpClient = clientBuilder .progressConsumer (receivedNotifications ::add ).build ()) {
1002
+
1003
+ // Initialize client
1004
+ InitializeResult initResult = mcpClient .initialize ();
1005
+ assertThat (initResult ).isNotNull ();
1006
+
1007
+ // Call the tool that sends progress notifications
1008
+ CallToolResult result = mcpClient .callTool (
1009
+ new McpSchema .CallToolRequest ("progress-test" , Map .of (), Map .of ("progressToken" , "test-token" )));
1010
+ assertThat (result ).isNotNull ();
1011
+ assertThat (result .content ().get (0 )).isInstanceOf (McpSchema .TextContent .class );
1012
+ assertThat (((McpSchema .TextContent ) result .content ().get (0 )).text ()).isEqualTo ("Progress test completed" );
1013
+
1014
+ // Wait for notifications to be processed
1015
+ await ().atMost (Duration .ofSeconds (5 )).untilAsserted (() -> {
1016
+
1017
+ System .out .println ("Received notifications: " + receivedNotifications );
1018
+
1019
+ // Should have received 3 notifications
1020
+ assertThat (receivedNotifications ).hasSize (3 );
1021
+
1022
+ // Check the progress notifications
1023
+ assertThat (receivedNotifications .stream ().map (McpSchema .ProgressNotification ::progressToken ))
1024
+ .containsExactlyInAnyOrder ("test-token" , "test-token" , "test-token" );
1025
+ assertThat (receivedNotifications .stream ().map (McpSchema .ProgressNotification ::progress ))
1026
+ .containsExactlyInAnyOrder (0.1 , 0.5 , 1.0 );
1027
+ });
1028
+ }
1029
+ mcpServer .close ();
1030
+ }
1031
+
961
1032
}
0 commit comments