ConduitMcp.Session.Janitor (ConduitMCP v0.9.5)

Copy Markdown View Source

Periodically prunes expired sessions from a ConduitMcp.Session.Store.

ETS-backed stores accumulate session entries indefinitely without an explicit eviction loop. Without a janitor, every successful initialize request adds a row to the session table that lives until the BEAM restarts; for a public-facing MCP server this is an unbounded memory growth surface.

Stores backed by systems with native TTL (Redis with EX, Mnesia with TTL indices, etc.) do not need this janitor.

Usage

Add the janitor to your application supervision tree:

children = [
  {ConduitMcp.Session.Janitor,
   store: ConduitMcp.Session.EtsStore,
   ttl: :timer.minutes(30),
   interval: :timer.minutes(1)},
  # ...
]

Options

  • :store (required) — module implementing ConduitMcp.Session.Store that defines a cleanup/1 callback.
  • :ttl — maximum session age in milliseconds (default: 30 minutes). Sessions whose created_at exceeds this age are evicted.
  • :interval — interval between cleanup runs in milliseconds (default: 1 minute).
  • :name — registered process name (default: module name).

Emits [:conduit_mcp, :session, :cleanup] telemetry on each run with metadata %{store: store, removed: count}.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)