# `ExMCP.HttpPlug.SessionRegistry`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/http_plug/session_registry.ex#L1)

Supervised owner of the SSE session table used by `ExMCP.HttpPlug`.

`ExMCP.HttpPlug` runs inside short-lived HTTP request processes, so the ETS
table mapping session ids to SSE handler pids must be owned by a long-lived
process — otherwise every registration would vanish as soon as the request
process that happened to create the table exits. This GenServer creates the
named public table in `init/1` and simply holds it for the lifetime of the
`:ex_mcp` application, which starts it as part of its supervision tree.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `lookup`

```elixir
@spec lookup(String.t()) ::
  {:ok, pid()} | {:error, :not_found | :registry_not_started}
```

Looks up the SSE handler pid registered for a session id.

# `register`

```elixir
@spec register(String.t(), pid()) :: :ok | {:error, :registry_not_started}
```

Registers the SSE handler pid for a session id.

Returns `{:error, :registry_not_started}` when the owning process (and thus
the table) is not running, which usually means the `:ex_mcp` application has
not been started.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

# `table`

```elixir
@spec table() :: atom()
```

Returns the name of the ETS table holding session registrations.

# `unregister`

```elixir
@spec unregister(String.t()) :: :ok
```

Removes the registration for a session id.

# `unregister`

```elixir
@spec unregister(String.t(), pid()) :: :ok
```

Removes the registration for a session id only if it still points at
`handler_pid`.

Used by handlers cleaning up after themselves in `terminate/2` without
clobbering a newer registration made for the same session id.

---

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