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