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    Draft,
8}
9impl ProtocolVersion {
10    pub fn supported_versions(include_draft: bool) -> Vec<ProtocolVersion> {
11        let mut versions = vec![
12            ProtocolVersion::V2024_11_05,
13            ProtocolVersion::V2025_03_26,
14            ProtocolVersion::V2025_06_18,
15        ];
16        if include_draft {
17            versions.push(ProtocolVersion::Draft);
18        }
19        versions
20    }
21}
22impl Display for ProtocolVersion {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            ProtocolVersion::V2024_11_05 => write!(f, "2024-11-05"),
26            ProtocolVersion::V2025_03_26 => write!(f, "2025-03-26"),
27            ProtocolVersion::V2025_06_18 => write!(f, "2025-06-18"),
28            ProtocolVersion::Draft => write!(f, "DRAFT-2025-v3"),
29        }
30    }
31}
32#[derive(Debug)]
33pub struct ParseProtocolVersionError {
34    details: String,
35}
36impl std::fmt::Display for ParseProtocolVersionError {
37    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
38        write!(
39            f,
40            "Unsupported protocol version : {}. Supported versions: {}",
41            self.details,
42            ProtocolVersion::supported_versions(false)
43                .iter()
44                .map(|p| p.to_string())
45                .collect::<Vec<_>>()
46                .join(", ")
47        )
48    }
49}
50impl std::error::Error for ParseProtocolVersionError {}
51impl TryFrom<&str> for ProtocolVersion {
52    type Error = ParseProtocolVersionError;
53    fn try_from(value: &str) -> Result<Self, Self::Error> {
54        match value {
55            "2024-11-05" => Ok(ProtocolVersion::V2024_11_05),
56            "2025-03-26" => Ok(ProtocolVersion::V2025_03_26),
57            "2025-06-18" => Ok(ProtocolVersion::V2025_06_18),
58            "DRAFT-2025-v3" => Ok(ProtocolVersion::Draft),
59            "DRAFT" => Ok(ProtocolVersion::Draft),
60            other => Err(ParseProtocolVersionError {
61                details: other.to_string(),
62            }),
63        }
64    }
65}