@@ -17,9 +17,9 @@ namespace ModelContextProtocol.Tests.Client;
1717/// </summary>
1818public class McpClientMrtrTests : ClientServerTestBase
1919{
20- private readonly TaskCompletionSource _handlerTokenCancelled = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
21- private readonly TaskCompletionSource _handlerStarted = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
22- private readonly TaskCompletionSource _handlerResumed = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
20+ private readonly TaskCompletionSource < bool > _handlerTokenCancelled = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
21+ private readonly TaskCompletionSource < bool > _handlerStarted = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
22+ private readonly TaskCompletionSource < bool > _handlerResumed = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2323 private readonly TaskCompletionSource < bool > _releaseHandler = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2424
2525 public McpClientMrtrTests ( ITestOutputHelper testOutputHelper )
@@ -157,8 +157,8 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
157157 async ( McpServer server , CancellationToken ct ) =>
158158 {
159159 var handlerTokenCancelled = _handlerTokenCancelled ;
160- ct . Register ( static state => ( ( TaskCompletionSource ) state ! ) . TrySetResult ( ) , handlerTokenCancelled ) ;
161- _handlerStarted . TrySetResult ( ) ;
160+ ct . Register ( static state => ( ( TaskCompletionSource < bool > ) state ! ) . TrySetResult ( true ) , handlerTokenCancelled ) ;
161+ _handlerStarted . TrySetResult ( true ) ;
162162
163163 await server . ElicitAsync ( new ElicitRequestParams
164164 {
@@ -179,15 +179,15 @@ await server.ElicitAsync(new ElicitRequestParams
179179 // Elicit first, then block forever — the retry request stays in-flight
180180 // until the client cancels, verifying that notifications/cancelled for
181181 // the retry's request ID flows through to cancel this handler.
182- _handlerStarted . TrySetResult ( ) ;
182+ _handlerStarted . TrySetResult ( true ) ;
183183 var result = await server . ElicitAsync ( new ElicitRequestParams
184184 {
185185 Message = message ,
186186 RequestedSchema = new ( )
187187 } , ct ) ;
188188
189189 // Signal that we resumed after ElicitAsync, then block.
190- _handlerResumed . TrySetResult ( ) ;
190+ _handlerResumed . TrySetResult ( true ) ;
191191 await Task . Delay ( Timeout . Infinite , ct ) ;
192192 return "unreachable" ;
193193 } ,
@@ -208,7 +208,7 @@ await server.ElicitAsync(new ElicitRequestParams
208208 } , ct ) ;
209209
210210 // Signal that round 1 completed so the test can inject the stale notification.
211- _handlerResumed . TrySetResult ( ) ;
211+ _handlerResumed . TrySetResult ( true ) ;
212212
213213 var r2 = await server . ElicitAsync ( new ElicitRequestParams
214214 {
@@ -227,14 +227,14 @@ await server.ElicitAsync(new ElicitRequestParams
227227 async ( string message , McpServer server , CancellationToken ct ) =>
228228 {
229229 // Elicit, resume, then wait on _releaseHandler for the dispose test.
230- _handlerStarted . TrySetResult ( ) ;
230+ _handlerStarted . TrySetResult ( true ) ;
231231 await server . ElicitAsync ( new ElicitRequestParams
232232 {
233233 Message = message ,
234234 RequestedSchema = new ( )
235235 } , ct ) ;
236236
237- _handlerResumed . TrySetResult ( ) ;
237+ _handlerResumed . TrySetResult ( true ) ;
238238 await _releaseHandler . Task ;
239239 return "handler-completed" ;
240240 } ,
@@ -543,13 +543,13 @@ public async Task ServerDisposal_CancelsHandlerCancellationToken_DuringMrtr()
543543 // (the `ct` parameter), not just the exchange ResponseTcs. Before the HandlerCts fix,
544544 // the handler's CT was from a disposed CTS and could never be triggered.
545545 StartServer ( ) ;
546- var elicitHandlerCalled = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
546+ var elicitHandlerCalled = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
547547
548548 var clientOptions = new McpClientOptions { ExperimentalProtocolVersion = "2026-06-XX" } ;
549549 clientOptions . Handlers . ElicitationHandler = async ( request , ct ) =>
550550 {
551551 // Signal that the MRTR round trip reached the client, then block indefinitely.
552- elicitHandlerCalled . TrySetResult ( ) ;
552+ elicitHandlerCalled . TrySetResult ( true ) ;
553553 await Task . Delay ( Timeout . Infinite , ct ) ;
554554 throw new OperationCanceledException ( ct ) ;
555555 } ;
0 commit comments