Skip to main content

check_protocol_header

Function check_protocol_header 

Source
pub fn check_protocol_header(
    negotiated: ProtocolVersion,
    header: Option<&str>,
) -> Result<(), NegotiationError>
Expand description

Checks an MCP-Protocol-Version header against the negotiated version.

Three outcomes, and the middle one is the point:

The header only became mandatory at 2025-06-18 (PR #548). Before that a Streamable HTTP request carried no version, so requiring one would reject peers the specification had not yet required anything of.

§Errors

NegotiationError::HeaderMismatch when the header names a different revision than the session negotiated.

NegotiationError::HeaderNotAVersion when the header is not a version this build can parse. That is distinct from a mismatch: a malformed header is a client that is broken, not one that disagrees.

§Examples

use protocol_droid::domain::{ProtocolVersion, check_protocol_header};

let negotiated = ProtocolVersion::V2025_06_18;
assert!(check_protocol_header(negotiated, Some("2025-06-18")).is_ok());
assert!(check_protocol_header(negotiated, Some("2024-11-05")).is_err());
assert!(check_protocol_header(negotiated, None).is_ok());