File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141var raw = await client . CallToolAsTaskAsync ( new CallToolRequestParams { Name = "run-report" } ) ;
4242if ( ! raw . IsTask )
4343{
44+ // Either the server doesn't advertise the tasks extension or it chose to run the call
45+ // synchronously despite the client opt-in. Surface the inline result and stop.
4446 Console . WriteLine ( $ " result (inline): { ( ( TextContentBlock ) raw . Result ! . Content [ 0 ] ) . Text } ") ;
4547 return ;
4648}
6466 switch ( state )
6567 {
6668 case CompletedTaskResult completed :
69+ // The Result property carries the wrapped CallToolResult as a raw JsonElement.
6770 var callToolResult = completed . Result . Deserialize < CallToolResult > ( ) ! ;
6871 Console . WriteLine ( $ " task completed after { pollCount } poll(s): { ( ( TextContentBlock ) callToolResult . Content [ 0 ] ) . Text } ") ;
6972 return ;
@@ -91,6 +94,8 @@ internal static class SlowTools
9194 [ Description ( "Runs a short simulated report and returns when it's done." ) ]
9295 public static async Task < string > RunReport ( CancellationToken cancellationToken )
9396 {
97+ // Real-world workloads would do meaningful work here; we just sleep so the polling
98+ // path is observable in the console output.
9499 await Task . Delay ( TimeSpan . FromSeconds ( 1 ) , cancellationToken ) ;
95100 return "report ready" ;
96101 }
You can’t perform that action at this time.
0 commit comments