FastestMCP.ApplicationSession (fastest_mcp v0.3.0)

Copy Markdown View Source

Application-owned state shared across MCP requests.

Application sessions reuse the configured FastestMCP.SessionStateStore but are deliberately separate from MCP transport sessions. The current session is a private bucket for one authenticated principal. Explicit sessions have opaque public identifiers and must be fetched again in each request.

Explicit sessions are principal-scoped by default. A server may opt into anonymous bearer sessions with application_sessions: [allow_anonymous: true].

Summary

Functions

Creates a new explicit application session.

Creates a new explicit application session or raises.

Returns the authenticated principal's application-session bucket.

Returns the authenticated principal's application-session bucket or raises.

Deletes one value from the application session.

Fetches an explicit application session visible to the current caller.

Fetches an explicit application session or raises.

Reads a value, returning the supplied default when the key is absent.

Returns an explicit application's public session identifier, or nil for current/1.

Stores a value in the application session.

Terminates an explicit application session and removes all of its values.

Types

t()

@opaque t()

Functions

create(context)

@spec create(FastestMCP.Context.t()) :: {:ok, t()} | {:error, FastestMCP.Error.t()}

Creates a new explicit application session.

create!(context)

@spec create!(FastestMCP.Context.t()) :: t()

Creates a new explicit application session or raises.

current(context)

@spec current(FastestMCP.Context.t()) :: {:ok, t()} | {:error, FastestMCP.Error.t()}

Returns the authenticated principal's application-session bucket.

current!(context)

@spec current!(FastestMCP.Context.t()) :: t()

Returns the authenticated principal's application-session bucket or raises.

delete(session, key)

@spec delete(t(), term()) :: :ok | {:error, FastestMCP.Error.t()}

Deletes one value from the application session.

fetch(context, id)

@spec fetch(FastestMCP.Context.t(), String.t()) ::
  {:ok, t()} | {:error, FastestMCP.Error.t()}

Fetches an explicit application session visible to the current caller.

fetch!(context, id)

@spec fetch!(FastestMCP.Context.t(), String.t()) :: t()

Fetches an explicit application session or raises.

get(session, key, default \\ nil)

@spec get(t(), term(), term()) :: {:ok, term()} | {:error, FastestMCP.Error.t()}

Reads a value, returning the supplied default when the key is absent.

id(application_session)

@spec id(t()) :: String.t() | nil

Returns an explicit application's public session identifier, or nil for current/1.

put(session, key, value)

@spec put(t(), term(), term()) :: :ok | {:error, FastestMCP.Error.t()}

Stores a value in the application session.

terminate(session)

@spec terminate(t()) :: :ok | {:error, FastestMCP.Error.t()}

Terminates an explicit application session and removes all of its values.