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
7use super::core::ProgressToken;
8
9/// Log level enumeration
10#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
11#[serde(rename_all = "lowercase")]
12pub enum LogLevel {
13 /// Debug level
14 Debug,
15 /// Info level
16 Info,
17 /// Notice level
18 Notice,
19 /// Warning level
20 Warning,
21 /// Error level
22 Error,
23 /// Critical level
24 Critical,
25 /// Alert level
26 Alert,
27 /// Emergency level
28 Emergency,
29}
30
31/// Set logging level request
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct SetLevelRequest {
34 /// Log level to set
35 pub level: LogLevel,
36}
37
38/// Set logging level result (empty)
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct SetLevelResult {}
41
42/// Logging notification (sent by server on `notifications/message`).
43///
44/// Spec name is `LoggingMessageNotification` (`schema.ts:1551`); the local
45/// `LoggingNotification` alias predates the spec rename. Both names refer
46/// to the same wire shape — see also [`LoggingMessageNotification`] for the
47/// spec-faithful name.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct LoggingNotification {
50 /// Log level
51 pub level: LogLevel,
52 /// Log message
53 pub data: serde_json::Value,
54 /// Optional logger name
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub logger: Option<String>,
57}
58
59/// Spec-faithful name for `notifications/message` — same wire shape as
60/// [`LoggingNotification`] (kept as an alias for backwards compatibility).
61pub type LoggingMessageNotification = LoggingNotification;
62
63/// Progress notification for reporting progress on long-running operations.
64///
65/// Servers can send progress notifications to clients to update them on
66/// the status of operations. The `progress_token` should match the token
67/// provided in the original request's `_meta` field.
68///
69/// Per MCP 2025-11-25 (`schema.ts:23`, `:1551-1561`):
70/// - `progressToken` is `string | number` — see [`ProgressToken`].
71/// - `progress` and `total` are JSON numbers (floats); they MAY express
72/// fractional progress (e.g., `45.7 / 100.0`).
73///
74/// # Example
75///
76/// ```rust
77/// use turbomcp_protocol::types::{ProgressNotification, ProgressToken};
78///
79/// let notification = ProgressNotification {
80/// progress_token: ProgressToken::from("request-123"),
81/// progress: 50.0,
82/// total: Some(100.0),
83/// message: Some("Processing files...".to_string()),
84/// };
85/// ```
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct ProgressNotification {
88 /// Token identifying the request this progress is for.
89 /// This should match the `progressToken` from the request's `_meta` field.
90 #[serde(rename = "progressToken")]
91 pub progress_token: ProgressToken,
92
93 /// Current progress value (JSON number; floats permitted).
94 pub progress: f64,
95
96 /// Optional total value (for percentage calculation).
97 /// If provided, progress/total gives the completion percentage.
98 #[serde(skip_serializing_if = "Option::is_none")]
99 pub total: Option<f64>,
100
101 /// Optional human-readable progress message.
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub message: Option<String>,
104}