Noizu.MCP.Error exception (Noizu MCP v0.1.0)

Copy Markdown View Source

Protocol-level MCP / JSON-RPC error.

Returned as {:error, %Noizu.MCP.Error{}} from handlers to produce a JSON-RPC error response. Distinct from tool execution errors — return {:error, "message"} from a tool handler to produce an isError: true tool result the model can read and self-correct from.

Use the constructors (invalid_params/2, resource_not_found/1, custom/3, …) rather than building the struct by hand so spec error codes stay consistent.

Summary

Types

t()

@type t() :: %Noizu.MCP.Error{
  __exception__: term(),
  code: integer(),
  data: term(),
  message: String.t(),
  reason: atom() | nil
}

Functions

capability_not_supported(capability)

@spec capability_not_supported(atom() | String.t()) :: t()

custom(code, message, data \\ nil)

@spec custom(integer(), String.t(), term()) :: t()

Application-defined error. Codes above -32000 are reserved for the protocol.

from_map(map)

@spec from_map(map()) :: t()

Build from a decoded JSON-RPC error object.

internal(message \\ "Internal error", data \\ nil)

@spec internal(String.t(), term()) :: t()

invalid_params(message \\ "Invalid params", data \\ nil)

@spec invalid_params(String.t(), term()) :: t()

invalid_request(message \\ "Invalid request")

@spec invalid_request(String.t()) :: t()

method_not_found(method)

@spec method_not_found(String.t()) :: t()

parse_error(message \\ "Parse error")

@spec parse_error(String.t()) :: t()

resource_not_found(uri)

@spec resource_not_found(String.t()) :: t()

to_map(error)

@spec to_map(t()) :: map()

Render as a JSON-RPC error object map.