Anubis.Server.Session (anubis_mcp v1.0.0)

Copy Markdown

Per-client MCP session process.

Each Session is a GenServer that manages the lifecycle of a single MCP client connection. It handles protocol initialization, request/notification dispatch, server-initiated requests (sampling, roots), and session persistence.

Sessions are created by the transport layer (STDIO creates one at startup, HTTP transports create them dynamically via Anubis.Server.Supervisor).

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a Session process linked to the current process.

Types

t()

@type t() :: %{
  session_id: String.t(),
  server_module: module(),
  protocol_version: String.t() | nil,
  protocol_module: module() | nil,
  initialized: boolean(),
  client_info: map() | nil,
  client_capabilities: map() | nil,
  log_level: String.t() | nil,
  frame: Anubis.Server.Frame.t(),
  server_info: map(),
  capabilities: map(),
  supported_versions: [String.t()],
  transport: %{layer: module(), name: GenServer.name()},
  registry: module(),
  session_idle_timeout: pos_integer(),
  expiry_timer: reference() | nil,
  pending_requests: %{
    required(String.t()) => %{started_at: integer(), method: String.t()}
  },
  server_requests: %{
    required(String.t()) => %{method: String.t(), timer_ref: reference()}
  },
  timeout: pos_integer(),
  task_supervisor: GenServer.name()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_schema(atom)

parse_options(data)

parse_options!(data)

start_link(opts)

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

Starts a Session process linked to the current process.

Options

  • :session_id — unique session identifier (required)
  • :server_module — the MCP server module implementing Anubis.Server (required)
  • :name — GenServer registration name (required)
  • :transport — transport configuration [layer: module, name: name] (required)
  • :task_supervisor — name of the Task.Supervisor for async work (required)
  • :registry — session registry module (default: Anubis.Server.Registry)
  • :session_idle_timeout — idle timeout in ms before session expires (default: 30 min)
  • :timeout — request timeout in ms (default: 30s)