@@ -24,14 +24,18 @@ public McpServerTests(ITestOutputHelper testOutputHelper)
2424 _serviceProvider = new ServiceCollection ( ) . BuildServiceProvider ( ) ;
2525 }
2626
27- private static McpServerOptions CreateOptions ( ServerCapabilities ? capabilities = null )
27+ private static McpServerOptions CreateOptions (
28+ ServerCapabilities ? capabilities = null ,
29+ IReadOnlyDictionary < string , List < Func < JsonRpcNotification , Task > > > ? notificationHandlers = null )
2830 {
31+ notificationHandlers ??= new Dictionary < string , List < Func < JsonRpcNotification , Task > > > ( ) ;
2932 return new McpServerOptions
3033 {
3134 ServerInfo = new Implementation { Name = "TestServer" , Version = "1.0" } ,
3235 ProtocolVersion = "2024" ,
3336 InitializationTimeout = TimeSpan . FromSeconds ( 30 ) ,
3437 Capabilities = capabilities ,
38+ NotificationHandlers = notificationHandlers ,
3539 } ;
3640 }
3741
@@ -640,18 +644,20 @@ public Task RunAsync(CancellationToken cancellationToken = default) =>
640644 public async Task NotifyProgress_Should_Be_Handled ( )
641645 {
642646 await using TestServerTransport transport = new ( ) ;
643- var options = CreateOptions ( ) ;
644-
645- var notificationReceived = new TaskCompletionSource < JsonRpcNotification > ( ) ;
646-
647- var server = McpServerFactory . Create ( transport , options , LoggerFactory , _serviceProvider ) ;
648- server . AddNotificationHandler ( NotificationMethods . ProgressNotification , notification =>
647+ TaskCompletionSource < JsonRpcNotification > notificationReceived = new ( ) ;
648+ var token = TestContext . Current . CancellationToken ;
649+
650+ Task SetNotificationHandler ( JsonRpcNotification notification )
649651 {
650652 notificationReceived . SetResult ( notification ) ;
651653 return Task . CompletedTask ;
654+ }
655+ var options = CreateOptions ( notificationHandlers : new Dictionary < string , List < Func < JsonRpcNotification , Task > > > ( )
656+ {
657+ { NotificationMethods . ProgressNotification , [ SetNotificationHandler ] } ,
652658 } ) ;
653-
654- Task serverTask = server . RunAsync ( TestContext . Current . CancellationToken ) ;
659+ var server = McpServerFactory . Create ( transport , options , LoggerFactory , _serviceProvider ) ;
660+ Task serverTask = server . RunAsync ( token ) ;
655661
656662 await transport . SendMessageAsync ( new JsonRpcNotification
657663 {
@@ -666,14 +672,16 @@ await transport.SendMessageAsync(new JsonRpcNotification
666672 Message = "Progress message" ,
667673 } ,
668674 } ,
669- } , TestContext . Current . CancellationToken ) ;
675+ } , token ) ;
670676
671677 var notification = await notificationReceived . Task ;
672678 var progress = ( ProgressNotification ) notification . Params ! ;
673679 Assert . Equal ( "\" abc\" " , progress . ProgressToken . ToString ( ) ) ;
674- Assert . Equal ( 50 , progress . Progress . Progress ) ;
675- Assert . Equal ( 100 , progress . Progress . Total ) ;
676- Assert . Equal ( "Progress message" , progress . Progress . Message ) ;
680+
681+ var progressValue = progress . Progress ;
682+ Assert . Equal ( 50 , progressValue . Progress ) ;
683+ Assert . Equal ( 100 , progressValue . Total ) ;
684+ Assert . Equal ( "Progress message" , progressValue . Message ) ;
677685
678686 await server . DisposeAsync ( ) ;
679687 await serverTask ;
0 commit comments