McpHouse.Server.SessionStore behaviour (mcp_house v0.1.0)

Copy Markdown View Source

Provisional atomic session adapter for a host-mounted MCP endpoint.

Generate each ID from at least 128 cryptographically random bits, encoded as visible ASCII (for example unpadded base64url). Each operation is atomic with respect to other operations on the same session. Check the namespace and principal before reporting a revision mismatch. Expired, closed, foreign and unknown sessions all return {:error, :not_found}. An outage returns {:error, :unavailable}.

TTLs are positive millisecond durations measured by the adapter's own clock. Successful admission refreshes idle expiry up to the absolute expiry. Rejection never refreshes it. The initialized notification advances the phase idempotently; admission may occur immediately after initialize. Closing prevents new admissions. Already admitted work can finish.

Adapter authors can load priv/session_store_contract.exs in ExUnit and use McpHouse.Server.SessionStore.Contract with an isolated store and clock.

Summary

Types

namespace()

@type namespace() :: binary()

principal()

@type principal() :: binary()

ref()

@type ref() :: term()

rejection()

@type rejection() :: {:error, :not_found | :wrong_revision | :unavailable}

Callbacks

admit(ref, namespace, binary, principal, binary, arg6)

@callback admit(
  ref(),
  namespace(),
  binary(),
  principal(),
  binary(),
  :initialized | :request
) ::
  :ok | rejection()

close(ref, namespace, binary, principal, binary)

@callback close(ref(), namespace(), binary(), principal(), binary()) :: :ok | rejection()

open(ref, namespace, principal, binary, pos_integer, pos_integer)

@callback open(ref(), namespace(), principal(), binary(), pos_integer(), pos_integer()) ::
  {:ok, binary()} | {:error, :unavailable}