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