MCPEx.Protocol.Errors (MCPEx v0.1.0)
Defines and handles MCP protocol errors.
This module provides utilities for creating and processing JSON-RPC error objects according to the MCP specification.
JSON-RPC Error Codes
Pre-defined JSON-RPC 2.0 error codes:
-32700
: Parse error - Invalid JSON was received-32600
: Invalid Request - The JSON sent is not a valid Request object-32601
: Method not found - The method does not exist / is not available-32602
: Invalid params - Invalid method parameter(s)-32603
: Internal error - Internal JSON-RPC error-32000 to -32099
: Server error - Reserved for implementation-defined server-errors
MCP-specific error codes:
-32800
: Request cancelled - The request was cancelled-32801
: Content too large - The content is too large
Summary
Functions
Creates a content too large error object.
Creates a JSON-RPC error object.
Creates a complete JSON-RPC error response.
Returns a JSON string for an error response.
Handles various error types and converts them to standardized JSON-RPC errors.
Creates an internal error object.
Creates an invalid params error object.
Creates an invalid request error object.
Creates a method not found error object.
Creates a parse error object.
Creates a request cancelled error object.
Functions
Creates a content too large error object.
Parameters
details
- Details about the content size issues
Returns
map()
- The error object
Creates a JSON-RPC error object.
Parameters
code
- The error codemessage
- The error messagedata
- Optional additional data
Returns
map()
- The error object
Examples
iex> MCPEx.Protocol.Errors.create_error(-32600, "Invalid Request")
%{code: -32600, message: "Invalid Request"}
iex> MCPEx.Protocol.Errors.create_error(-32602, "Missing param", %{param: "id"})
%{code: -32602, message: "Missing param", data: %{param: "id"}}
Creates a complete JSON-RPC error response.
Parameters
id
- The request ID (or nil for notifications)error
- The error object
Returns
map()
- The complete error response
Returns a JSON string for an error response.
Parameters
id
- The request IDerror
- The error object
Returns
String.t()
- The JSON string
Handles various error types and converts them to standardized JSON-RPC errors.
Parameters
error
- The error to handle
Returns
{:error, map()}
- Standardized error map
Creates an internal error object.
Parameters
details
- Optional details about the internal error
Returns
map()
- The error object
Creates an invalid params error object.
Parameters
details
- Details about the invalid parameters
Returns
map()
- The error object
Creates an invalid request error object.
Parameters
message
- Optional custom error message
Returns
map()
- The error object
Creates a method not found error object.
Parameters
method
- The method that was not found
Returns
map()
- The error object
Creates a parse error object.
Parameters
message
- Optional custom error message
Returns
map()
- The error object
Examples
iex> MCPEx.Protocol.Errors.parse_error()
%{code: -32700, message: "Parse error"}
Creates a request cancelled error object.
Parameters
details
- Details about the cancellation
Returns
map()
- The error object