Skip to main content

rust_mcp_schema/generated_schema/
protocol_version.rs

1use std::fmt::Display;
2#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
3pub enum ProtocolVersion {
4    V2024_11_05,
5    V2025_03_26,
6    V2025_06_18,
7    V2025_11_25,
8    V2026_07_28,
9    Draft,
10}
11impl ProtocolVersion {
12    /// Returns a list of supported protocol versions.
13    ///
14    /// By default, this does not include the `Draft` version.
15    /// If `include_draft` is `true`, the `Draft` version will be included as well.
16    pub fn supported_versions(include_draft: bool) -> Vec<ProtocolVersion> {
17        let mut versions = vec![
18            ProtocolVersion::V2024_11_05,
19            ProtocolVersion::V2025_03_26,
20            ProtocolVersion::V2025_06_18,
21            ProtocolVersion::V2025_11_25,
22            ProtocolVersion::V2026_07_28,
23        ];
24        if include_draft {
25            versions.push(ProtocolVersion::Draft);
26        }
27        versions
28    }
29    /// Returns the latest stable protocol version.
30    pub const fn latest() -> Self {
31        ProtocolVersion::V2026_07_28
32    }
33}
34impl Display for ProtocolVersion {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            ProtocolVersion::V2024_11_05 => write!(f, "2024-11-05"),
38            ProtocolVersion::V2025_03_26 => write!(f, "2025-03-26"),
39            ProtocolVersion::V2025_06_18 => write!(f, "2025-06-18"),
40            ProtocolVersion::V2025_11_25 => write!(f, "2025-11-25"),
41            ProtocolVersion::V2026_07_28 => write!(f, "2026-07-28"),
42            ProtocolVersion::Draft => write!(f, "DRAFT"),
43        }
44    }
45}
46#[allow(clippy::from_over_into)]
47impl Into<String> for ProtocolVersion {
48    fn into(self) -> String {
49        self.to_string()
50    }
51}
52#[derive(Debug)]
53pub struct ParseProtocolVersionError {
54    details: String,
55}
56impl std::fmt::Display for ParseProtocolVersionError {
57    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58        write!(
59            f,
60            "Unsupported protocol version : {}. Supported versions: {}",
61            self.details,
62            ProtocolVersion::supported_versions(false)
63                .iter()
64                .map(|p| p.to_string())
65                .collect::<Vec<_>>()
66                .join(", ")
67        )
68    }
69}
70impl std::error::Error for ParseProtocolVersionError {}
71impl TryFrom<&str> for ProtocolVersion {
72    type Error = ParseProtocolVersionError;
73    fn try_from(value: &str) -> Result<Self, Self::Error> {
74        match value {
75            "2024-11-05" => Ok(ProtocolVersion::V2024_11_05),
76            "2025-03-26" => Ok(ProtocolVersion::V2025_03_26),
77            "2025-06-18" => Ok(ProtocolVersion::V2025_06_18),
78            "2025-11-25" => Ok(ProtocolVersion::V2025_11_25),
79            "2026-07-28" => Ok(ProtocolVersion::V2026_07_28),
80            "DRAFT" => Ok(ProtocolVersion::Draft),
81            other => Err(ParseProtocolVersionError {
82                details: other.to_string(),
83            }),
84        }
85    }
86}