pub struct ProtocolVersion(/* private fields */);Expand description
Represents the MCP protocol version used for communication.
This ensures compatibility between clients and servers by specifying which version of the Model Context Protocol is being used.
Implementations§
Source§impl ProtocolVersion
impl ProtocolVersion
pub const V_2026_07_28: Self
pub const V_2025_11_25: Self
pub const V_2025_06_18: Self
pub const V_2025_03_26: Self
pub const V_2024_11_05: Self
Sourcepub const STANDARD_HEADERS: Self = Self::V_2026_07_28
pub const STANDARD_HEADERS: Self = Self::V_2026_07_28
First protocol version that requires SEP-2243 standard HTTP headers.
Sourcepub const NO_INITIALIZE: Self = Self::V_2026_07_28
pub const NO_INITIALIZE: Self = Self::V_2026_07_28
First protocol version that replaced the initialize handshake with
per-request _meta (SEP-2567).
Sourcepub const LATEST_WITH_INITIALIZE: Self = Self::V_2025_11_25
pub const LATEST_WITH_INITIALIZE: Self = Self::V_2025_11_25
The newest protocol version that still has an initialize handshake.
From Self::NO_INITIALIZE onward the lifecycle moved into per-request
_meta, so there is no handshake left to answer. A server replying to
initialize can therefore never name Self::LATEST once LATEST
reaches that revision — it has to name this one instead.
Use this, not LATEST, whenever the subject is the handshake itself:
the version a server can echo from initialize, or the version a test
needs in order to exercise session-based behavior.
assert!(ProtocolVersion::LATEST_WITH_INITIALIZE.has_initialize());
assert!(!ProtocolVersion::LATEST.has_initialize());Sourcepub const KNOWN_VERSIONS: &[Self]
pub const KNOWN_VERSIONS: &[Self]
All protocol versions known to this SDK, oldest first.
Sourcepub fn has_initialize(&self) -> bool
pub fn has_initialize(&self) -> bool
Whether this revision negotiates its lifecycle over the initialize
handshake.
false from Self::NO_INITIALIZE onward, where SEP-2567 moved the
lifecycle into per-request _meta. Unknown versions are compared
lexically, which orders correctly because every revision is dated
YYYY-MM-DD.
assert!(ProtocolVersion::V_2025_11_25.has_initialize());
assert!(!ProtocolVersion::V_2026_07_28.has_initialize());Sourcepub fn known_up_to(max: &Self) -> &'static [Self]
pub fn known_up_to(max: &Self) -> &'static [Self]
The known versions up to and including max, oldest first.
Servers that implement every revision up to some ceiling can return
this from supported_protocol_versions instead of filtering
Self::KNOWN_VERSIONS by hand. max itself need not be a known
version; the result is empty when it predates all of them.
The result borrows from Self::KNOWN_VERSIONS, so call it directly
in the method body — it needs no static and no LazyLock:
const MAX_SUPPORTED: ProtocolVersion = ProtocolVersion::V_2025_11_25;
fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
Cow::Borrowed(ProtocolVersion::known_up_to(&MAX_SUPPORTED))
}assert_eq!(
ProtocolVersion::known_up_to(&ProtocolVersion::V_2025_06_18),
&[
ProtocolVersion::V_2024_11_05,
ProtocolVersion::V_2025_03_26,
ProtocolVersion::V_2025_06_18,
],
);Trait Implementations§
Source§impl Clone for ProtocolVersion
impl Clone for ProtocolVersion
Source§impl Debug for ProtocolVersion
impl Debug for ProtocolVersion
Source§impl Default for ProtocolVersion
impl Default for ProtocolVersion
Source§impl<'de> Deserialize<'de> for ProtocolVersion
impl<'de> Deserialize<'de> for ProtocolVersion
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for ProtocolVersion
impl Display for ProtocolVersion
impl Eq for ProtocolVersion
Source§impl Hash for ProtocolVersion
impl Hash for ProtocolVersion
Source§impl JsonSchema for ProtocolVersion
Available on crate feature schemars only.
impl JsonSchema for ProtocolVersion
schemars only.Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for ProtocolVersion
impl PartialEq for ProtocolVersion
Source§impl PartialOrd for ProtocolVersion
impl PartialOrd for ProtocolVersion
Source§impl Serialize for ProtocolVersion
impl Serialize for ProtocolVersion
impl StructuralPartialEq for ProtocolVersion
Auto Trait Implementations§
impl Freeze for ProtocolVersion
impl RefUnwindSafe for ProtocolVersion
impl Send for ProtocolVersion
impl Sync for ProtocolVersion
impl Unpin for ProtocolVersion
impl UnsafeUnpin for ProtocolVersion
impl UnwindSafe for ProtocolVersion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.