ExMCP.Protocol.VersionNegotiator (ex_mcp v0.10.0)

View Source

Handles 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_capabilities(negotiated_version)

@spec build_capabilities(String.t()) :: map()

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.

latest_version()

@spec latest_version() :: String.t()

Get the latest supported protocol version.

negotiate(client_versions)

@spec negotiate([String.t()]) :: {:ok, String.t()} | {:error, :no_compatible_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}

supported?(version)

@spec supported?(String.t()) :: boolean()

Check if a specific version is supported.

supported_versions()

@spec supported_versions() :: [String.t()]

Get the list of supported protocol versions.