use pmcp::types::{ProgressNotification, ProgressToken};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
println!("=== MCP Progress Notifications Example ===");
let progress_tracker = Arc::new(Mutex::new(HashMap::<ProgressToken, f64>::new()));
let notifications = vec![
ProgressNotification::new(
ProgressToken::String("task-1".to_string()),
10.0,
Some("Starting task...".to_string()),
),
ProgressNotification::new(
ProgressToken::String("task-1".to_string()),
25.0,
Some("Processing data...".to_string()),
),
ProgressNotification::new(
ProgressToken::String("task-1".to_string()),
50.0,
Some("Halfway there...".to_string()),
),
ProgressNotification::new(
ProgressToken::String("task-1".to_string()),
100.0,
Some("Task completed!".to_string()),
),
];
println!("Simulating progress notifications:");
for notification in notifications {
let percentage = notification.progress;
let progress_bar = "█".repeat((percentage / 5.0) as usize);
let empty_bar = "░".repeat(20 - (percentage / 5.0) as usize);
println!(
"📊 Progress [{}{}] {:.1}% - {} (Token: {:?})",
progress_bar,
empty_bar,
percentage,
notification.message.as_deref().unwrap_or("Working..."),
notification.progress_token
);
progress_tracker
.lock()
.unwrap()
.insert(notification.progress_token.clone(), notification.progress);
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
}
println!("✅ Progress tracking completed!");
let tracker = progress_tracker.lock().unwrap();
println!("Final progress state: {:?}", *tracker);
Ok(())
}