@@ -11,7 +11,7 @@ use rmcp::{
1111} ;
1212use serde_json:: json;
1313use tokio_stream:: StreamExt ;
14- use tracing:: debug;
14+ use tracing:: { debug, info } ;
1515
1616// a Stream data source that generates data in chunks
1717#[ derive( Clone ) ]
@@ -30,7 +30,7 @@ impl StreamDataSource {
3030 }
3131 }
3232 pub fn from_text ( text : & str ) -> Self {
33- Self :: new ( text. as_bytes ( ) . to_vec ( ) , 1 )
33+ Self :: new ( text. as_bytes ( ) . to_vec ( ) , 5 )
3434 }
3535}
3636
@@ -61,7 +61,7 @@ impl ProgressDemo {
6161 #[ allow( dead_code) ]
6262 pub fn new ( ) -> Self {
6363 Self {
64- data_source : StreamDataSource :: from_text ( "Hello, world! " ) ,
64+ data_source : StreamDataSource :: from_text ( "1111122222333334444455555 " ) ,
6565 }
6666 }
6767 #[ tool( description = "Process data stream with progress updates" ) ]
@@ -70,6 +70,21 @@ impl ProgressDemo {
7070 ctx : RequestContext < RoleServer > ,
7171 ) -> Result < CallToolResult , McpError > {
7272 let mut counter = 0 ;
73+ info ! (
74+ "Processing stream with progress token {:?}" ,
75+ ctx. meta. get_key_value( "progressToken" )
76+ ) ;
77+ let Some ( ( _, progress_token) ) = ctx. meta . get_key_value ( "progressToken" ) else {
78+ return Err ( McpError :: internal_error ( format ! ( "No progress token" ) , None ) ) ;
79+ } ;
80+
81+ let Ok ( progress_token) = serde_json:: from_value :: < NumberOrString > ( progress_token. clone ( ) )
82+ else {
83+ return Err ( McpError :: internal_error (
84+ format ! ( "Invalid format of the progress token" ) ,
85+ None ,
86+ ) ) ;
87+ } ;
7388
7489 let mut data_source = self . data_source . clone ( ) ;
7590 loop {
@@ -83,9 +98,9 @@ impl ProgressDemo {
8398 counter += 1 ;
8499 // create progress notification param
85100 let progress_param = ProgressNotificationParam {
86- progress_token : ProgressToken ( NumberOrString :: Number ( counter ) ) ,
101+ progress_token : ProgressToken ( progress_token . clone ( ) ) ,
87102 progress : counter as f64 ,
88- total : None ,
103+ total : Some ( 5.0 ) ,
89104 message : Some ( chunk_str. to_string ( ) ) ,
90105 } ;
91106
@@ -104,6 +119,7 @@ impl ProgressDemo {
104119 ) ) ;
105120 }
106121 }
122+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
107123 }
108124
109125 Ok ( CallToolResult :: success ( vec ! [ Content :: text( format!(
0 commit comments