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. Aninitializeover 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.:infinitykeeps sessions untilDELETEor shutdown.:registry- aSnodo.Session.Registrymodule or{module, options}. Defaults toSnodo.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:principaland:client_idfields when the auth value is a map with a:principalkey, which is the shapesnodo_oauthassigns, 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.
Summary
Functions
Returns the configuration of a running manager.
Returns the number of open sessions.
Starts a manager. See the module documentation for the options.
Types
@type t() :: %Snodo.Session.Manager{ idle_timeout: pos_integer() | :infinity, max_sessions: pos_integer(), principal: (term() -> term()), registry: {module(), term()}, supervisor: pid() }
The configuration of a running manager, as config/1 returns it.
Functions
@spec config(GenServer.server() | t()) :: t()
Returns the configuration of a running manager.
@spec count(GenServer.server() | t()) :: non_neg_integer()
Returns the number of open sessions.
@spec start_link(keyword()) :: GenServer.on_start()
Starts a manager. See the module documentation for the options.