# `BB.MCP.EventBuffer`
[🔗](https://github.com/beam-bots/bb_mcp/blob/main/lib/bb/mcp/event_buffer.ex#L5)

Per-session ring buffer for BB pubsub events.

Each MCP session subscribes to all configured robots' pubsub trees and
records arriving messages in a bounded buffer that the agent can query
via the `query_events` tool.

The buffer is stored directly in `Anubis.Server.Frame.assigns[:event_buffer]`
and updated on every `handle_info({:bb, path, %BB.Message{}}, frame)` call —
no extra processes per session.

# `entry`

```elixir
@type entry() :: %{
  monotonic_ns: integer(),
  received_ns: integer(),
  robot: String.t(),
  path: [atom()],
  payload_module: module(),
  message: BB.Message.t()
}
```

# `filters`

```elixir
@type filters() :: %{
  optional(:robot) =&gt; String.t(),
  optional(:message_type) =&gt; String.t(),
  optional(:path_prefix) =&gt; String.t(),
  optional(:since_ms) =&gt; non_neg_integer(),
  optional(:limit) =&gt; pos_integer()
}
```

# `t`

```elixir
@type t() :: %{
  events: [entry()],
  capacity: pos_integer(),
  subscriptions: [{String.t(), module()}]
}
```

# `configured_capacity`

```elixir
@spec configured_capacity() :: pos_integer()
```

Capacity sourced from `:bb_mcp` app config, falling back to the default.

# `new`

```elixir
@spec new(pos_integer()) :: t()
```

Build an empty buffer with the given capacity.

# `push`

```elixir
@spec push(t(), String.t(), [atom()], BB.Message.t()) :: t()
```

Append a pubsub event to the buffer, dropping the oldest entry if at capacity.

# `query`

```elixir
@spec query(t(), filters()) :: [map()]
```

Return matching events, newest first, serialised to JSON-safe maps.

# `record_subscription`

```elixir
@spec record_subscription(t(), String.t(), module()) :: t()
```

Record a subscription pair so the session can unsubscribe later.

---

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