ProgressHandler

Trait ProgressHandler 

Source
pub trait ProgressHandler:
    Send
    + Sync
    + Debug {
    // Required method
    fn handle_progress<'life0, 'async_trait>(
        &'life0 self,
        notification: ProgressNotification,
    ) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Handler for server progress notifications

Progress handlers receive notifications about long-running server operations. This allows clients to display progress bars, status updates, or other feedback to users during operations that take significant time.

§Examples

use turbomcp_client::handlers::{ProgressHandler, ProgressNotification, HandlerResult};
use async_trait::async_trait;

#[derive(Debug)]
struct ProgressBarHandler;

#[async_trait]
impl ProgressHandler for ProgressBarHandler {
    async fn handle_progress(&self, notification: ProgressNotification) -> HandlerResult<()> {
        let progress_val = notification.progress.progress;
        if let Some(total) = notification.progress.total {
            let percentage = (progress_val / total) * 100.0;
            println!("Progress: {:.1}% - {}", percentage,
                notification.message.unwrap_or_default());
        } else {
            println!("Progress: {} - {}", progress_val,
                notification.message.unwrap_or_default());
        }
         
        if notification.completed {
            if let Some(error) = notification.error {
                println!("Operation failed: {}", error);
            } else {
                println!("Operation completed successfully!");
            }
        }
         
        Ok(())
    }
}

Required Methods§

Source

fn handle_progress<'life0, 'async_trait>( &'life0 self, notification: ProgressNotification, ) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a progress notification from the server

This method is called when the server sends progress updates for long-running operations.

§Arguments
  • notification - Progress information including current status and completion state
§Returns

Returns Ok(()) if the notification was processed successfully.

Implementors§