ExMCP.Error exception (ex_mcp v0.9.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 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)

See ExMCP.ErrorHelpers.connection_error/1.

connection_error(details, opts)

See ExMCP.ErrorHelpers.connection_error/2.

connection_error_struct(details)

connection_error_struct(details, opts)

exception(value)

from_json_rpc_error(json_error, opts \\ [])

See ExMCP.ErrorHelpers.from_json_rpc_error/2.

internal_error(details, opts \\ [])

See ExMCP.ErrorHelpers.internal_error/2.

invalid_params(details, opts \\ [])

See ExMCP.ErrorHelpers.invalid_params/2.

invalid_request(details, opts \\ [])

See ExMCP.ErrorHelpers.invalid_request/2.

json_rpc_error?(arg1)

mcp_error?(arg1)

message(error)

method_not_found(method, opts \\ [])

See ExMCP.ErrorHelpers.method_not_found/2.

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

See ExMCP.ErrorHelpers.parse_error/2.

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

See ExMCP.ErrorHelpers.prompt_error/3.

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)