ExMCP.Protocol.VersionNegotiator (ex_mcp v0.9.2)
View SourceHandles protocol version negotiation during the MCP initialization phase.
This module is responsible for negotiating the protocol version between client and server during the initialization handshake, as specified in the MCP 2025-06-18 specification.
Summary
Functions
Build the server capabilities response including protocol version info.
Get the latest supported protocol version.
Negotiate the protocol version based on client capabilities.
Check if a specific version is supported.
Get the list of supported protocol versions.
Functions
Build the server capabilities response including protocol version info.
This is used during the initialization response to inform the client about server capabilities and the negotiated protocol version.
@spec latest_version() :: String.t()
Get the latest supported protocol version.
Negotiate the protocol version based on client capabilities.
Takes the client's supported versions and returns the best matching version that both client and server support.
Parameters
client_versions- List of protocol versions supported by the client
Returns
{:ok, version}- Successfully negotiated version{:error, :no_compatible_version}- No compatible version found
Examples
iex> ExMCP.Protocol.VersionNegotiator.negotiate(["2025-06-18", "2025-03-26"])
{:ok, "2025-06-18"}
iex> ExMCP.Protocol.VersionNegotiator.negotiate(["2024-01-01"])
{:error, :no_compatible_version}
Check if a specific version is supported.
@spec supported_versions() :: [String.t()]
Get the list of supported protocol versions.