Lightweight ETS-backed circuit breaker for MCP tool/resource callbacks.
Tracks failure counts per key and transitions through three states:
- closed -- normal operation, failures below threshold
- open -- callback blocked after repeated failures, returns
{:error, :circuit_open} - half_open -- recovery probe allowed after cooldown; success resets, failure re-opens
No GenServer -- all state lives in a public ETS table with atomic counter
updates. The table is created by the owning process (typically MCP.Registry).
Configuration
Defaults can be overridden via application env or per-call opts:
config :raxol_mcp, :circuit_breaker,
failure_threshold: 5,
recovery_ms: 30_000
Summary
Functions
Check the circuit state for a key.
Create a new circuit breaker ETS table.
Record a failed callback invocation.
Record a successful callback invocation. Resets the circuit to closed.
Manually reset a circuit to closed.
Reset all circuit breaker state.
Get the current status of a circuit.
Types
Functions
Check the circuit state for a key.
Returns :closed (proceed), :open (block), or :half_open (probe).
Automatically transitions from open to half_open after the recovery period.
Create a new circuit breaker ETS table.
Record a failed callback invocation.
Increments the failure counter. Transitions to open when the threshold is reached. In half_open state, a single failure re-opens the circuit.
Record a successful callback invocation. Resets the circuit to closed.
Manually reset a circuit to closed.
@spec reset_all(:ets.tid()) :: :ok
Reset all circuit breaker state.
@spec status(:ets.tid(), key()) :: %{state: state(), failures: non_neg_integer()}
Get the current status of a circuit.