Mead.MCP.Protocol (mead v0.1.1)

Copy Markdown View Source

Pure JSON-RPC 2.0 codec for the slice of MCP that mead speaks as a client: initialize, notifications/initialized, tools/list, and tools/call.

Encoders return one-line JSON binaries (the JSON encoder escapes newlines inside strings), so a stdio transport can frame messages with a trailing newline. decode/1 never raises.

Summary

Types

decoded()

@type decoded() ::
  {:response, request_id(), map()}
  | {:error_response, request_id(),
     %{code: integer(), message: String.t(), data: term()}}
  | {:request, request_id(), String.t(), map()}
  | {:notification, String.t(), map()}
  | {:invalid,
     :not_binary
     | :malformed_json
     | :not_jsonrpc
     | :result_and_error
     | :unrecognized}

request_id()

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

Functions

call_tool_request(id, name, arguments)

@spec call_tool_request(request_id(), String.t(), map()) :: binary()

cancelled_notification(id, reason)

@spec cancelled_notification(request_id(), String.t()) :: binary()

Tells the server that nobody waits for the answer to request id any more.

decode(input)

@spec decode(term()) :: decoded()

error_response(id, code, message)

@spec error_response(request_id() | nil, integer(), String.t()) :: binary()

initialize_request(id)

@spec initialize_request(request_id()) :: binary()

initialized_notification()

@spec initialized_notification() :: binary()

list_tools_request(id, cursor \\ nil)

@spec list_tools_request(request_id(), String.t() | nil) :: binary()

protocol_version()

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

The one protocol version this client negotiates.

result_response(id, result)

@spec result_response(request_id(), map()) :: binary()

supported_version?(version)

@spec supported_version?(term()) :: boolean()