Sake.JSONRPC (Sake v0.1.0)

Copy Markdown View Source

JSON-RPC 2.0 messages as MCP uses them: requests with a string or integer id, notifications without one, results, errors, and batches (legacy revision 2025-03-26 only).

Summary

Types

id()

@type id() :: String.t() | integer()

parsed()

@type parsed() ::
  {:request, id(), String.t(), map()}
  | {:notification, String.t(), map()}
  | {:response, id(), map()}
  | {:error_response, id() | nil, map()}
  | {:batch, [parsed()]}
  | {:error, :malformed}

Functions

code(name)

@spec code(atom()) :: integer()

error(id, code, message, data \\ nil)

@spec error(id() | nil, integer(), String.t(), term()) :: map()

notification(method, params \\ nil)

@spec notification(String.t(), map() | nil) :: map()

parse(batch)

@spec parse(term()) :: parsed()

request(id, method, params \\ nil)

@spec request(id(), String.t(), map() | nil) :: map()

result(id, result)

@spec result(id(), map()) :: map()