# `SuperPi.MCP.Sessions`
[🔗](https://github.com/oleksandr/super-pi-beam/blob/v0.1.0/lib/super_pi/mcp/sessions.ex#L1)

Sessions of the Streamable HTTP server (`SuperPi.MCP.HTTPPlug`): the id a client carries in
`Mcp-Session-Id`, and the connection state that `SuperPi.MCP.Server.handle_mcp_line/2` threads.

The table lives on the node that answered `initialize`. A request that reaches another node
finds no session and gets `404`, which a conforming client answers by starting a new session,
so a cluster needs no shared session store (sticky routing only saves the round trip).

A session expires after `mcp_session_ttl_ms` without a request (default one hour). At most
`mcp_max_sessions` exist at once (default 1000), so a client that only calls `initialize`
cannot fill memory.

# `clear`

Drops every session. For tests.

# `count`

Number of live sessions.

# `create`

```elixir
@spec create(map()) :: {:ok, String.t()} | {:error, :full}
```

Starts a session with `state`. Returns `{:ok, id}`, or `{:error, :full}` at the limit.

# `delete`

```elixir
@spec delete(term()) :: :ok | :error
```

Ends a session. Returns `:ok`, or `:error` when there was none.

# `fetch`

```elixir
@spec fetch(term()) :: {:ok, map()} | :error
```

The state of a live session. A request counts as use, so an active session does not expire.

# `put`

```elixir
@spec put(String.t(), map()) :: :ok
```

Stores the next state of a live session. A session that ended meanwhile stays ended.

---

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