MCPKit.SessionStore behaviour (mcp_kit v0.2.4)

Copy Markdown View Source

Storage contract for persistent MCP sessions.

The session store is the durable authority for MCP session metadata. Runtime stream state, queued notifications, and pending outbound requests live in MCPKit.Runtime, not in the store.

Summary

Callbacks

Creates a new persistent MCP session.

Deletes a persisted session by id.

Fetches a persisted MCP session by id.

Marks a session as initialized after notifications/initialized.

Updates any session heartbeat or last-seen metadata after a successful request.

Callbacks

create_session(map)

@callback create_session(map()) :: {:ok, struct() | map()} | {:error, term()}

Creates a new persistent MCP session.

Implementations should persist the session id, initialization status, negotiated protocol version, and any client metadata needed by the host app.

delete_session(t)

@callback delete_session(String.t()) ::
  {:ok, struct() | map()} | {:error, :not_found | term()}

Deletes a persisted session by id.

Returns {:error, :not_found} when the session does not exist.

fetch_session(t)

@callback fetch_session(String.t()) ::
  {:ok, struct() | map()} | {:error, :not_found | term()}

Fetches a persisted MCP session by id.

Returns {:error, :not_found} when the session does not exist.

mark_initialized(arg1)

@callback mark_initialized(struct() | map()) :: {:ok, struct() | map()} | {:error, term()}

Marks a session as initialized after notifications/initialized.

touch_session(arg1)

@callback touch_session(struct() | map()) :: {:ok, struct() | map()} | {:error, term()}

Updates any session heartbeat or last-seen metadata after a successful request.