Skip to main content

turbomcp_protocol/types/
logging.rs

1//! Logging and progress types
2//!
3//! This module contains types for MCP logging and progress notifications.
4
5use serde::{Deserialize, Serialize};
6
7/// Log level enumeration
8#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
9#[serde(rename_all = "lowercase")]
10pub enum LogLevel {
11    /// Debug level
12    Debug,
13    /// Info level
14    Info,
15    /// Notice level
16    Notice,
17    /// Warning level
18    Warning,
19    /// Error level
20    Error,
21    /// Critical level
22    Critical,
23    /// Alert level
24    Alert,
25    /// Emergency level
26    Emergency,
27}
28
29/// Set logging level request
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct SetLevelRequest {
32    /// Log level to set
33    pub level: LogLevel,
34}
35
36/// Set logging level result (empty)
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct SetLevelResult {}
39
40/// Logging notification
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct LoggingNotification {
43    /// Log level
44    pub level: LogLevel,
45    /// Log message
46    pub data: serde_json::Value,
47    /// Optional logger name
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub logger: Option<String>,
50}
51
52/// Progress notification for reporting progress on long-running operations.
53///
54/// Servers can send progress notifications to clients to update them on
55/// the status of operations. The `progress_token` should match the token
56/// provided in the original request's `_meta` field.
57///
58/// # Example
59///
60/// ```rust
61/// use turbomcp_protocol::types::ProgressNotification;
62///
63/// let notification = ProgressNotification {
64///     progress_token: "request-123".to_string(),
65///     progress: 50,
66///     total: Some(100),
67///     message: Some("Processing files...".to_string()),
68/// };
69/// ```
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ProgressNotification {
72    /// Token identifying the request this progress is for.
73    /// This should match the `progressToken` from the request's `_meta` field.
74    #[serde(rename = "progressToken")]
75    pub progress_token: String,
76
77    /// Current progress value.
78    pub progress: u64,
79
80    /// Optional total value (for percentage calculation).
81    /// If provided, progress/total gives the completion percentage.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub total: Option<u64>,
84
85    /// Optional human-readable progress message.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub message: Option<String>,
88}