ExMCP.Error exception (ex_mcp v1.0.0-rc.0)

View Source

Error types and utilities for ExMCP.

This module provides structured error handling with proper error types that can be pattern matched and provide useful debugging information.

Summary

Functions

Creates a connection error.

Creates an error struct from a JSON-RPC error response.

Creates a JSON-RPC internal error.

Creates a JSON-RPC invalid params error.

Creates a JSON-RPC invalid request error.

Creates a JSON-RPC method not found error.

Creates a JSON-RPC parse error.

Creates an MCP prompt error.

Creates a protocol error exception with the given JSON-RPC error code.

Creates a transport error exception.

Creates a validation error.

Wraps a function call and converts exceptions to proper error tuples.

Wraps a function call with a custom error transformer.

Types

t()

@type t() :: %ExMCP.Error{
  __exception__: true,
  code: integer(),
  data: any(),
  message: String.t(),
  request_id: String.t() | nil
}

Functions

authentication_error(details)

authorization_error(details)

category(arg1)

connection_error(details)

Creates a connection error.

connection_error(details, opts)

connection_error_struct(details)

connection_error_struct(details, opts)

exception(value)

from_json_rpc_error(json_error, opts \\ [])

Creates an error struct from a JSON-RPC error response.

internal_error(details, opts \\ [])

Creates a JSON-RPC internal error.

invalid_params(details, opts \\ [])

Creates a JSON-RPC invalid params error.

invalid_request(details, opts \\ [])

Creates a JSON-RPC invalid request error.

json_rpc_error?(arg1)

mcp_error?(arg1)

message(error)

method_not_found(method, opts \\ [])

Creates a JSON-RPC method not found error.

parse_error(details \\ "", opts \\ [])

Creates a JSON-RPC parse error.

prompt_error(details, prompt_name, opts \\ [])

Creates an MCP prompt error.

protocol_error(code, message, data \\ nil)

Creates a protocol error exception with the given JSON-RPC error code.

Standard JSON-RPC Error Codes

  • -32700 - Parse error
  • -32600 - Invalid Request
  • -32601 - Method not found
  • -32602 - Invalid params
  • -32603 - Internal error
  • -32000 to -32099 - Server error

resource_error(details, uri)

resource_error(uri, operation, reason)

to_json_rpc(error)

tool_error(details)

tool_error(details, tool_name)

tool_error(details, tool_name, opts)

transport_error(details)

Creates a transport error exception.

transport_error(details, opts)

transport_error(transport, reason, details)

validation_error(field, value, reason)

Creates a validation error.

wrap(fun)

Wraps a function call and converts exceptions to proper error tuples.

Examples

ExMCP.Error.wrap(fn ->
  do_something_dangerous()
end)
# => {:ok, result} or {:error, %ExMCP.Error.SomeError{}}

wrap_with(fun, error_transformer)

Wraps a function call with a custom error transformer.

Examples

ExMCP.Error.wrap_with(fn ->
  read_file(path)
end, fn
  {:error, :enoent} -> ExMCP.Error.resource_error(path, :read, :not_found)
  error -> error
end)