Hermes.Protocol (hermes_mcp v0.9.1)
Protocol version management and feature validation for MCP.
This module handles protocol version compatibility, feature detection, and transport validation following the MCP specification.
Protocol Versions
2024-11-05
: Initial stable release with SSE and basic features2025-03-26
: Enhanced version with Streamable HTTP, authorization, batching, and extended features
Examples
iex> Hermes.Protocol.validate_transport("2024-11-05", Hermes.Transport.SSE)
:ok
iex> Hermes.Protocol.validate_transport("2024-11-05", Hermes.Transport.StreamableHTTP)
{:error, %Hermes.MCP.Error{reason: :incompatible_transport}}
iex> Hermes.Protocol.supports_feature?("2025-03-26", :json_rpc_batching)
true
Summary
Functions
Returns transport modules that support a protocol version.
Returns the fallback protocol version for compatibility.
Returns the set of features supported by a protocol version.
Returns the latest supported protocol version.
Negotiates protocol version between client and server versions.
Returns all supported protocol versions.
Checks if a feature is supported by a protocol version.
Validates client configuration for protocol compatibility.
Validates if a transport is compatible with a protocol version.
Validates if a protocol version is supported.
Types
Functions
Returns transport modules that support a protocol version.
Parameters
version
- The protocol versiontransport_modules
- List of transport modules to check
Examples
iex> transports = [Hermes.Transport.STDIO, Hermes.Transport.SSE]
iex> Hermes.Protocol.compatible_transports("2024-11-05", transports)
[Hermes.Transport.STDIO, Hermes.Transport.SSE]
@spec fallback_version() :: version()
Returns the fallback protocol version for compatibility.
Examples
iex> Hermes.Protocol.fallback_version()
"2024-11-05"
Returns the set of features supported by a protocol version.
Parameters
version
- The protocol version
Examples
iex> features = Hermes.Protocol.get_features("2025-03-26")
iex> MapSet.member?(features, :json_rpc_batching)
true
@spec latest_version() :: version()
Returns the latest supported protocol version.
Examples
iex> Hermes.Protocol.latest_version()
"2025-03-26"
@spec negotiate_version(version(), version()) :: {:ok, version()} | {:error, Hermes.MCP.Error.t()}
Negotiates protocol version between client and server versions.
Returns the best compatible version or an error if incompatible.
Parameters
client_version
- The client's preferred protocol versionserver_version
- The server's supported protocol version
Examples
iex> Hermes.Protocol.negotiate_version("2025-03-26", "2025-03-26")
{:ok, "2025-03-26"}
iex> Hermes.Protocol.negotiate_version("2025-03-26", "2024-11-05")
{:ok, "2024-11-05"}
iex> Hermes.Protocol.negotiate_version("2024-11-05", "1.0.0")
{:error, %Hermes.MCP.Error{reason: :incompatible_versions}}
@spec supported_versions() :: [version()]
Returns all supported protocol versions.
Examples
iex> Hermes.Protocol.supported_versions()
["2024-11-05", "2025-03-26"]
Checks if a feature is supported by a protocol version.
Parameters
version
- The protocol versionfeature
- The feature to check
Examples
iex> Hermes.Protocol.supports_feature?("2025-03-26", :json_rpc_batching)
true
iex> Hermes.Protocol.supports_feature?("2024-11-05", :authorization)
false
@spec validate_client_config(version(), module(), map()) :: :ok | {:error, Hermes.MCP.Error.t()}
Validates client configuration for protocol compatibility.
This function checks if the client configuration is compatible with the specified protocol version, including transport and capabilities.
Parameters
version
- The protocol versiontransport_module
- The transport module being usedcapabilities
- The client capabilities
Examples
iex> capabilities = %{"resources" => %{}, "tools" => %{}}
iex> Hermes.Protocol.validate_client_config("2024-11-05", Hermes.Transport.SSE, capabilities)
:ok
@spec validate_transport(version(), module()) :: :ok | {:error, Hermes.MCP.Error.t()}
Validates if a transport is compatible with a protocol version.
Parameters
version
- The protocol versiontransport_module
- The transport module to validate
Examples
iex> Hermes.Protocol.validate_transport("2024-11-05", Hermes.Transport.SSE)
:ok
iex> Hermes.Protocol.validate_transport("2024-11-05", Hermes.Transport.StreamableHTTP)
{:error, %Hermes.MCP.Error{reason: :incompatible_transport}}
@spec validate_version(version()) :: :ok | {:error, Hermes.MCP.Error.t()}
Validates if a protocol version is supported.
Parameters
version
- The protocol version to validate
Examples
iex> Hermes.Protocol.validate_version("2024-11-05")
:ok
iex> Hermes.Protocol.validate_version("1.0.0")
{:error, %Hermes.MCP.Error{reason: :unsupported_protocol_version}}