JSON-RPC 2.0 encoding/decoding for MCP messages.
Summary
Functions
Decodes a JSON string into a classified message struct.
Classifies a decoded JSON map into the appropriate message struct.
Encodes a message struct to a JSON string.
Encodes a message struct to a JSON string, raising on error.
Returns the JSON-RPC version.
Returns the MCP protocol version this library targets.
Functions
@spec decode(String.t()) :: {:ok, MCP.Protocol.Messages.Request.t() | MCP.Protocol.Messages.Response.t() | MCP.Protocol.Messages.Notification.t()} | {:error, MCP.Protocol.Error.t()}
Decodes a JSON string into a classified message struct.
@spec decode_message(map()) :: {:ok, MCP.Protocol.Messages.Request.t() | MCP.Protocol.Messages.Response.t() | MCP.Protocol.Messages.Notification.t()} | {:error, MCP.Protocol.Error.t()}
Classifies a decoded JSON map into the appropriate message struct.
@spec encode( MCP.Protocol.Messages.Request.t() | MCP.Protocol.Messages.Response.t() | MCP.Protocol.Messages.Notification.t() ) :: {:ok, String.t()} | {:error, term()}
Encodes a message struct to a JSON string.
@spec encode!( MCP.Protocol.Messages.Request.t() | MCP.Protocol.Messages.Response.t() | MCP.Protocol.Messages.Notification.t() ) :: String.t()
Encodes a message struct to a JSON string, raising on error.
@spec jsonrpc_version() :: String.t()
Returns the JSON-RPC version.
@spec protocol_version() :: String.t()
Returns the MCP protocol version this library targets.