# `Snodo.Session.Manager`
[🔗](https://github.com/joshrotenberg/snodo/blob/v0.5.0/lib/snodo/session/manager.ex#L1)

Starts and bounds the session processes of initialize-era clients.

A manager owns a `Snodo.Session.Registry` and a `DynamicSupervisor` for
`Snodo.Session` processes. `Snodo.Transport.StreamableHTTP.Server` starts its
own when it is given `sessions: true` or a keyword list of these options.
`Snodo.Transport.Plug` takes the name of one the application starts under
its supervision tree, because a Plug's options can be built at compile time:

    children = [
      {Snodo.Session.Manager, name: MyApp.MCPSessions},
      {Bandit,
       plug:
         {Snodo.Transport.Plug,
          runtime: MyApp.Server.runtime(),
          executor: MyApp.Executor,
          sessions: MyApp.MCPSessions}}
    ]

Options:

  * `:name` - a registered name for the manager.
  * `:max_sessions` - the most sessions open at once, default 1,024. An
    `initialize` over the limit gets 503 and no session.
  * `:idle_timeout` - milliseconds a session may go without a request, a
    response, or an open stream before it ends, default 1,800,000 (30
    minutes). A request for an ended session gets 404, and the client
    initializes again. `:infinity` keeps sessions until `DELETE` or shutdown.
  * `:registry` - a `Snodo.Session.Registry` module or `{module, options}`.
    Defaults to `Snodo.Session.Registry.Local`.
  * `:principal` - a function of one argument that maps a request's auth
    value (`Snodo.Context.auth`) to the principal a session is bound to.
    The default uses the `:principal` and `:client_id` fields when the auth
    value is a map with a `:principal` key, which is the shape
    `snodo_oauth` assigns, so a refreshed token for the same subject keeps
    the session; otherwise it uses the whole auth value.

Sessions live on the node that handled `initialize`. A deployment with more
than one node needs sticky load balancing that routes every request for a
session to that node; the core does not route sessions between nodes.

# `t`

```elixir
@type t() :: %Snodo.Session.Manager{
  idle_timeout: pos_integer() | :infinity,
  max_sessions: pos_integer(),
  principal: (term() -&gt; term()),
  registry: {module(), term()},
  supervisor: pid()
}
```

The configuration of a running manager, as `config/1` returns it.

# `config`

```elixir
@spec config(GenServer.server() | t()) :: t()
```

Returns the configuration of a running manager.

# `count`

```elixir
@spec count(GenServer.server() | t()) :: non_neg_integer()
```

Returns the number of open sessions.

# `start_link`

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

Starts a manager. See the module documentation for the options.

---

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