Skip to content

MCP client state: one vMCP session per agent, durable send-once and parked calls #2564

Open

Description

@ChrisJBurns

Depends on: #2527 (per-agent identities); stacklok/toolhive#6779 (session binding for the list methods), for session reuse only; "vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user" (stacklok/toolhive#6888) (binding to the client and agent)
Removes shortcut: a new vMCP session for every gateway call (#2451)
Removes shortcut: the send-once record, parked gateway calls, and vMCP session IDs are in memory, so a restart can send a call twice and loses parked calls and backend state (#2451)

Problem

mecak8s's MCP client sends the gateway calls. It opens a vMCP session per call, so backend state such as a selected repository is lost between an agent's calls. Its record of sent calls and its parked calls are in memory, so a restart could send a call twice or drop a parked one.

Implements

Scope

  • Landing order: send-once and parked-call durability can land before session reuse; only session reuse waits on vMCP: session identity binding is not enforced for tools/list (and other list methods) toolhive#6779.
  • Send-once: claims persisted with their argument hash; competing claims across replicas send once; deleting a session clears only its own claims, not a recreated same-ID session's.
  • Parked calls: persisted with their operation ID; resumed only after the broker authorizes again, otherwise an explicit unavailable or ambiguous outcome.
  • Session reuse: one vMCP session per instance, gateway, and user, outside the broker session; each call's own gateway token; a gone session recreated with one retry; explicit reset; IDs persisted and reattached.
  • Storage: mecak8s's own session storage, shared across replicas, pruned when the session or instance ends.
  • Not here: the broker's records (Durable broker state and recovery #2563); dropping sessions on sign-out everywhere (Sign-out and revocation #2568).

Decide before starting

  • Does the durable send-once record keep the in-memory limit (4096 calls per root session, oldest completed evicted, send_once_full otherwise)? If so, what may be evicted, and does send_once_full stay model-visible?

Done when

  • After a restart, a possibly sent call is not resent and reports an ambiguous outcome; a parked call resumes after a new authorization or reports an explicit outcome; competing claims send once.
  • An agent's consecutive calls reuse its vMCP session, reattached after a restart; two agents or users never share one; a gone session is recreated.

Earlier notes: #2730 (closed, merged here).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions