Snodo.Session.Manager (snodo v0.5.0)

Copy Markdown View Source

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.

Summary

Types

t()

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

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

t()

@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

config(config)

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

Returns the configuration of a running manager.

count(manager)

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

Returns the number of open sessions.

start_link(opts \\ [])

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

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