FastestMCP.SessionStateStore behaviour (fastest_mcp v0.1.2)

Copy Markdown View Source

Behaviour for session-scoped state backends.

FastestMCP keeps session lifecycle in the runtime-owned session process, but the actual user-facing state can live in a pluggable backend. That split lets the runtime keep idle expiry and subscription tracking local while making the storage strategy configurable.

The built-in memory backend stores ordinary Elixir terms and is started once per running server. Custom backends can impose stricter serialization or persistence guarantees as long as they implement this behaviour.

Summary

Functions

Deletes one session value from the configured backend.

Deletes all state for the given session from the configured backend.

Reads one session value from the configured backend.

Stores one session value in the configured backend.

Types

key()

@type key() :: term()

session_id()

@type session_id() :: String.t()

store_ref()

@type store_ref() :: pid() | atom()

value()

@type value() :: term()

Callbacks

delete(store_ref, session_id, key)

@callback delete(store_ref(), session_id(), key()) :: :ok | {:error, term()}

delete_session(store_ref, session_id)

@callback delete_session(store_ref(), session_id()) :: :ok | {:error, term()}

get(store_ref, session_id, key)

@callback get(store_ref(), session_id(), key()) ::
  {:ok, value()} | :error | {:error, term()}

put(store_ref, session_id, key, value)

@callback put(store_ref(), session_id(), key(), value()) :: :ok | {:error, term()}

start_link(keyword)

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

Functions

delete(map, session_id, key)

Deletes one session value from the configured backend.

delete_session(map, session_id)

Deletes all state for the given session from the configured backend.

get(map, session_id, key)

Reads one session value from the configured backend.

put(map, session_id, key, value)

Stores one session value in the configured backend.