Skip to main content

systemprompt_mcp/
progress.rs

1use rmcp::model::{ProgressNotificationParam, ProgressToken};
2use rmcp::service::{Peer, RoleServer};
3use std::future::Future;
4use std::pin::Pin;
5
6pub type ProgressCallback = Box<
7    dyn Fn(f64, Option<f64>, Option<String>) -> Pin<Box<dyn Future<Output = ()> + Send>>
8        + Send
9        + Sync,
10>;
11
12#[must_use]
13pub fn create_progress_callback(token: ProgressToken, peer: Peer<RoleServer>) -> ProgressCallback {
14    Box::new(
15        move |progress: f64, total: Option<f64>, message: Option<String>| {
16            let token = token.clone();
17            let peer = peer.clone();
18            let fut: Pin<Box<dyn Future<Output = ()> + Send>> = Box::pin(async move {
19                let _ = peer
20                    .notify_progress(ProgressNotificationParam {
21                        progress_token: token,
22                        progress,
23                        total,
24                        message,
25                    })
26                    .await;
27            });
28            fut
29        },
30    )
31}