use crate::mcp::{GenericMeta, IntoMcpNotification, McpNotification};
use derive_more::From;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, From)]
#[serde(untagged)]
pub enum ProgressToken {
#[from(String, &str, &String)]
String(String),
#[from(i64, i32)]
Number(i64),
}
pub type Cursor = String;
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProgressNotificationParams {
#[serde(rename = "_meta")]
pub meta: Option<GenericMeta>,
pub progress_token: ProgressToken,
pub progress: i64,
pub total: Option<i64>,
pub message: Option<String>,
}
impl ProgressNotificationParams {
pub fn new(progress_token: impl Into<ProgressToken>, progress: i64) -> Self {
Self {
meta: None,
progress_token: progress_token.into(),
progress,
total: None,
message: None,
}
}
pub fn with_meta(mut self, meta: GenericMeta) -> Self {
self.meta = Some(meta);
self
}
pub fn with_total(mut self, total: i64) -> Self {
self.total = Some(total);
self
}
pub fn with_message(mut self, message: impl Into<String>) -> Self {
self.message = Some(message.into());
self
}
}
impl IntoMcpNotification for ProgressNotificationParams {
const METHOD: &'static str = "notifications/progress";
}
pub type ProgressNotification = McpNotification<ProgressNotificationParams>;