# `ExMCP.Reliability.CircuitBreaker.Core`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/reliability/circuit_breaker/core.ex#L1)

Pure circuit-breaker state machine used by `ExMCP.Reliability.CircuitBreaker`.

# `config`

```elixir
@type config() :: %{
  failure_threshold: non_neg_integer(),
  success_threshold: non_neg_integer(),
  timeout: non_neg_integer(),
  failure_rate_threshold: float(),
  minimum_throughput: non_neg_integer(),
  reset_timeout: non_neg_integer()
}
```

# `state`

```elixir
@type state() :: :closed | :open | :half_open
```

# `t`

```elixir
@type t() :: %ExMCP.Reliability.CircuitBreaker.Core{
  config: map(),
  failure_count: non_neg_integer(),
  last_failure_time: integer() | nil,
  last_success_time: integer() | nil,
  opened_at: integer() | nil,
  state: state(),
  stats: map(),
  success_count: non_neg_integer()
}
```

# `allow_request?`

```elixir
@spec allow_request?(t()) :: boolean()
```

Checks if a request should be allowed based on the current circuit state.

# `allow_request_with_state?`

```elixir
@spec allow_request_with_state?(t()) :: {boolean(), t()}
```

Checks if a request should be allowed and returns both the result and updated state.

# `force_state`

```elixir
@spec force_state(t(), state()) :: t()
```

Forces the circuit breaker to a specific state.

# `get_state`

```elixir
@spec get_state(t()) :: state()
```

Gets the current state of the circuit breaker.

# `get_stats`

```elixir
@spec get_stats(t()) :: map()
```

Gets circuit breaker statistics.

# `new`

```elixir
@spec new(config() | map()) :: t()
```

Creates a new circuit breaker with the given configuration.

# `record_failure`

```elixir
@spec record_failure(t()) :: t()
```

Records a failed operation and updates the circuit breaker state.

# `record_success`

```elixir
@spec record_success(t()) :: t()
```

Records a successful operation and updates the circuit breaker state.

# `reset`

```elixir
@spec reset(t()) :: t()
```

Resets the circuit breaker to its initial state.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
