JSON-RPC 2.0 message encoding, decoding, and builders for the Caravela MCP server.
Stdio MCP transport is one JSON message per line: every frame is serialized with a trailing newline; every incoming line parses as a complete message. No Content-Length framing (that's the LSP convention, not MCP's).
The standard error codes follow JSON-RPC 2.0:
-32700Parse error — invalid JSON was received-32600Invalid Request — not a valid request object-32601Method not found-32602Invalid params-32603Internal error
Summary
Functions
Decode a single JSON-RPC message from a line of input. Returns
{:ok, map} on success or {:error, reason} on malformed JSON.
Encode a message as a newline-terminated JSON string.
Build a JSON-RPC 2.0 error response. code is a JSON-RPC error
code (see moduledoc); data is an optional arbitrary term attached
to help the client diagnose.
Shorthand: -32603 internal error.
Shorthand: -32602 invalid params.
Shorthand: -32600 invalid request.
Shorthand: -32601 method not found.
Shorthand: -32700 parse error response.
True if the request carries an id field (i.e. expects a response).
Build a JSON-RPC 2.0 success response.
Functions
Decode a single JSON-RPC message from a line of input. Returns
{:ok, map} on success or {:error, reason} on malformed JSON.
Encode a message as a newline-terminated JSON string.
Build a JSON-RPC 2.0 error response. code is a JSON-RPC error
code (see moduledoc); data is an optional arbitrary term attached
to help the client diagnose.
Shorthand: -32603 internal error.
Shorthand: -32602 invalid params.
Shorthand: -32600 invalid request.
Shorthand: -32601 method not found.
Shorthand: -32700 parse error response.
True if the request carries an id field (i.e. expects a response).
Build a JSON-RPC 2.0 success response.