JSON-RPC helpers used by the MCP transport.
This module is intentionally small and focused on message shape detection, decoding, and standard protocol error payloads.
Examples
iex> MCPKit.Protocol.request?(%{"jsonrpc" => "2.0", "method" => "ping", "id" => 1})
true
iex> MCPKit.Protocol.success(1, %{"ok" => true})
%{"jsonrpc" => "2.0", "id" => 1, "result" => %{"ok" => true}}
Summary
Functions
Decodes a raw JSON-RPC request body.
Encodes a JSON-RPC payload to JSON.
Builds a JSON-RPC forbidden payload.
Builds a JSON-RPC internal error payload.
Builds a JSON-RPC invalid params payload.
Builds a JSON-RPC invalid request payload.
Builds a JSON-RPC method not found payload.
Returns true when the payload is a JSON-RPC notification.
Builds a JSON-RPC parse error payload.
Returns true when the payload is a JSON-RPC request.
Returns true when the payload is a JSON-RPC response.
Builds a successful JSON-RPC response payload.
Functions
Decodes a raw JSON-RPC request body.
Examples
iex> MCPKit.Protocol.decode(~s({"jsonrpc":"2.0","method":"ping","id":1}))
{:ok, %{"id" => 1, "jsonrpc" => "2.0", "method" => "ping"}}
iex> MCPKit.Protocol.decode("{")
{:error, :parse_error}
Encodes a JSON-RPC payload to JSON.
Builds a JSON-RPC forbidden payload.
Builds a JSON-RPC internal error payload.
Builds a JSON-RPC invalid params payload.
Builds a JSON-RPC invalid request payload.
Builds a JSON-RPC method not found payload.
Returns true when the payload is a JSON-RPC notification.
Builds a JSON-RPC parse error payload.
Returns true when the payload is a JSON-RPC request.
Returns true when the payload is a JSON-RPC response.
Builds a successful JSON-RPC response payload.