AttestoMCP.Server.JSONRPC (attesto_mcp_server v0.8.0)

Copy Markdown View Source

Strict JSON-RPC 2.0 decoding and encoding for MCP wire messages.

Summary

Types

extensions()

@type extensions() :: json_object()

id()

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

json_object()

@type json_object() :: %{optional(String.t()) => json_value()}

json_value()

@type json_value() ::
  nil | boolean() | number() | String.t() | [json_value()] | json_object()

notification()

@type notification() :: %{
  :kind => :notification,
  :method => String.t(),
  :params => map(),
  optional(:extensions) => extensions()
}

request()

@type request() :: %{
  :kind => :request,
  :id => id(),
  :method => String.t(),
  :params => map(),
  optional(:extensions) => extensions()
}

response()

@type response() :: %{
  :kind => :response,
  :id => id(),
  :result => json_value(),
  :error => map() | nil,
  optional(:extensions) => extensions()
}

Functions

decode(payload, opts \\ [])

@spec decode(
  binary(),
  keyword()
) ::
  {:ok, request() | notification() | response()}
  | {:error, AttestoMCP.Server.Error.t()}

encode(message)

@spec encode(map()) :: binary()

error_response(id, error)

recover_id(payload, opts \\ [])

@spec recover_id(
  binary(),
  keyword()
) :: id() | nil

Recovers a valid JSON-RPC ID from an otherwise invalid JSON object.

response(id, result)

@spec response(term(), term()) :: map()