Module Spindle_mcp_protocol

The Model Context Protocol's messages, as both ends read and write them: JSON-RPC 2.0 as MCP 2026-07-28 uses it, and the protocol's version. It does no I/O, so the server and the client read one message one way.

val version : string

"2026-07-28": the one version spoken, by both ends.

type id =
  1. | Int of int
  2. | String of string

A request's id: MCP's are a string or an integer, never null.

val id_to_value : id -> Wiretype.Value.t
type message =
  1. | Request of {
    1. id : id;
    2. meth : string;
    3. params : Wiretype.Value.t option;
    }
  2. | Notification of {
    1. meth : string;
    2. params : Wiretype.Value.t option;
    }

A message a client sends.

type error =
  1. | Parse_error
    (*

    not JSON

    *)
  2. | Invalid_request of string
    (*

    JSON, but no request or notification: a batch, which MCP has none of, a null id, a response, or no "jsonrpc": "2.0" and method; in words

    *)

Why a body is no message a client may send.

val read : string -> (message, error) Stdlib.result
val member : string -> Wiretype.Value.t option -> Wiretype.Value.t option

member name params: that member of an object, where there is one.

Answers

val result : id -> (string * Wiretype.Value.t) list -> string

A result response: the members given, in order.

val notification : string -> (string * Wiretype.Value.t) list -> string

notification meth params: a message no answer follows.

module Code : sig ... end

The codes MCP answers with: JSON-RPC's -32700, -32600, -32601, -32602 and -32603, and MCP's own -32020, -32021 and -32022.

val error : ?id:id -> ?data:Wiretype.Value.t -> int -> string -> string

An error response: the code, the message, and data where given. id is the request's, and absent where it could not be read.