Function ensure_server_protocole_compatibility

Source
pub fn ensure_server_protocole_compatibility(
    client_protocol_version: &str,
    server_protocol_version: &str,
) -> SdkResult<()>
Expand description

Checks if the client and server protocol versions are compatible by ensuring they are equal.

This function compares the provided client and server protocol versions. If they are equal, it returns Ok(()), indicating compatibility. If they differ (either the client version is lower or higher than the server version), it returns an error with details about the incompatible versions.

§Arguments

  • client_protocol_version - A string slice representing the client’s protocol version.
  • server_protocol_version - A string slice representing the server’s protocol version.

§Returns

  • Ok(()) if the versions are equal.
  • Err(McpSdkError::IncompatibleProtocolVersion) if the versions differ, containing the client and server versions as strings.

§Examples

use rust_mcp_sdk::mcp_client::ensure_server_protocole_compatibility;
use rust_mcp_sdk::error::McpSdkError;

// Compatible versions
let result = ensure_server_protocole_compatibility("2024_11_05", "2024_11_05");
assert!(result.is_ok());

// Incompatible versions (client < server)
let result = ensure_server_protocole_compatibility("2024_11_05", "2025_03_26");
assert!(matches!(
    result,
    Err(McpSdkError::IncompatibleProtocolVersion(client, server))
    if client == "2024_11_05" && server == "2025_03_26"
));

// Incompatible versions (client > server)
let result = ensure_server_protocole_compatibility("2025_03_26", "2024_11_05");
assert!(matches!(
    result,
    Err(McpSdkError::IncompatibleProtocolVersion(client, server))
    if client == "2025_03_26" && server == "2024_11_05"
));