ExMCP.Protocol (ex_mcp v0.1.0)
View SourceMCP protocol message encoding and decoding.
Implements the Model Context Protocol JSON-RPC message format. This module handles the low-level protocol details for both client and server implementations.
Summary
Functions
Encodes a tool call request.
Encodes a completion request.
Encodes an error response.
Encodes a prompt get request.
Encodes an initialize request from client to server.
Encodes an initialized notification.
Encodes a request to list available prompts.
Encodes a request to list available resources.
Encodes a request to list available tools.
Encodes a notification (no id field).
Encodes a resource read request.
Encodes a successful response.
Encodes a message to JSON string.
Generates a unique ID for requests.
Standard JSON-RPC error codes.
Parses a JSON-RPC message.
Types
Functions
Encodes a tool call request.
Encodes a completion request.
@spec encode_error(integer(), String.t(), any(), json_rpc_id()) :: map()
Encodes an error response.
Encodes a prompt get request.
Encodes an initialize request from client to server.
@spec encode_initialized() :: map()
Encodes an initialized notification.
@spec encode_list_prompts() :: map()
Encodes a request to list available prompts.
@spec encode_list_resources() :: map()
Encodes a request to list available resources.
@spec encode_list_tools() :: map()
Encodes a request to list available tools.
Encodes a notification (no id field).
Encodes a resource read request.
@spec encode_response(result(), json_rpc_id()) :: map()
Encodes a successful response.
Encodes a message to JSON string.
@spec generate_id() :: integer()
Generates a unique ID for requests.
Standard JSON-RPC error codes.
@spec parse_message(String.t() | map()) :: {:request, method(), params(), json_rpc_id()} | {:notification, method(), params()} | {:result, result(), json_rpc_id()} | {:error, error(), json_rpc_id()} | {:error, :invalid_message}
Parses a JSON-RPC message.
Returns one of:
{:request, method, params, id}
- An incoming request{:notification, method, params}
- An incoming notification{:result, result, id}
- A response to our request{:error, error, id}
- An error response{:error, :invalid_message}
- Invalid message format