JSON-RPC 2.0 and MCP-specific error codes.
This module provides constants and helper functions for working with error codes in the MCP protocol. All error codes follow the JSON-RPC 2.0 specification with MCP-specific extensions.
Standard 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 or is not available-32602- Invalid params: Invalid method parameter(s)-32603- Internal error: Internal JSON-RPC error
MCP-Specific Error Codes
-32001- Request cancelled: The request was cancelled by the client-32002- Consent required: User consent is required for the operation-32003- Consent denied: User denied consent for the operation-32020- Header mismatch-32021- Missing required client capability-32022- Unsupported protocol version-32000- Generic server error: Catch-all for server-side errors
Compatibility note
The existing 1.x API assigns -32002 to consent-required,
resource-not-found, and prompt errors. Consequently,
error_message(:resource_not_found) returns "Consent required". The
collision is retained through 1.x to avoid changing public and wire values.
Usage
iex> ExMCP.Protocol.ErrorCodes.invalid_params()
-32602
iex> ExMCP.Protocol.ErrorCodes.error_message(:invalid_params)
"Invalid params"
iex> ExMCP.Protocol.ErrorCodes.is_protocol_error?(-32602)
true
Summary
Functions
Consent denied: User denied consent for the operation
Consent required: User consent is required for the operation.
Returns a human-readable error message for the given error code or atom.
Creates an error response map with the given code and message.
Header mismatch between negotiated protocol state and the request
Internal error: Internal JSON-RPC error
Invalid params: Invalid method parameter(s)
Invalid Request: The JSON sent is not a valid Request object
Checks if the given error code is an MCP-specific error.
Checks if the given error code is a standard JSON-RPC protocol error.
Method not found: The method does not exist or is not available
A required client capability was not declared
Parse error: Invalid JSON was received by the server
Request cancelled: The request was cancelled by the client
Resource not found: The requested resource does not exist.
Generic server error: Catch-all for server-side errors
The requested protocol version is not supported
URL elicitation required: The server requires URL-mode elicitation
Functions
Consent denied: User denied consent for the operation
Consent required: User consent is required for the operation.
This legacy constructor shares -32002 with resource-not-found and prompt
errors. It is retained for compatibility.
Returns a human-readable error message for the given error code or atom.
Examples
iex> ExMCP.Protocol.ErrorCodes.error_message(-32602)
"Invalid params"
iex> ExMCP.Protocol.ErrorCodes.error_message(:invalid_params)
"Invalid params"
Creates an error response map with the given code and message.
Examples
iex> ExMCP.Protocol.ErrorCodes.error_response(:invalid_params, "Missing required field: name")
%{code: -32602, message: "Invalid params: Missing required field: name"}
Header mismatch between negotiated protocol state and the request
Internal error: Internal JSON-RPC error
Invalid params: Invalid method parameter(s)
Invalid Request: The JSON sent is not a valid Request object
Checks if the given error code is an MCP-specific error.
Examples
iex> ExMCP.Protocol.ErrorCodes.is_mcp_error?(-32001)
true
iex> ExMCP.Protocol.ErrorCodes.is_mcp_error?(-32602)
false
Checks if the given error code is a standard JSON-RPC protocol error.
Examples
iex> ExMCP.Protocol.ErrorCodes.is_protocol_error?(-32602)
true
iex> ExMCP.Protocol.ErrorCodes.is_protocol_error?(-32001)
false
Method not found: The method does not exist or is not available
A required client capability was not declared
Parse error: Invalid JSON was received by the server
Request cancelled: The request was cancelled by the client
Resource not found: The requested resource does not exist.
This legacy constructor returns -32002, which also means consent-required
and prompt error in 1.x. It is retained for compatibility.
Generic server error: Catch-all for server-side errors
The requested protocol version is not supported
URL elicitation required: The server requires URL-mode elicitation