mcp-session-lifecycle

Explain MCP NotebookSession lifecycle across proxy, session state, and daemon rooms.

158|12|Updated Feb 11, 2026
One-click install
npx skills add https://github.com/nteract/nteract --skill mcp-session-lifecycle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mcp-session-lifecycle
Source: https://github.com/nteract/nteract/tree/main/.agents/skills/mcp-session-lifecycle
Command: npx skills add https://github.com/nteract/nteract --skill mcp-session-lifecycle

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Understand the MCP server session lifecycle: proxy supervision, daemon watch loop, session state machine, rejoin/reconnect races, and room eviction. Use when debugging session state, changing reconnection logic, or reasoning about races between background rejoin and user-initiated tool calls.

Core Features & Use Cases

  • Three layers: MCP Client, runt-mcp-proxy, runt-mcp, and runtimed, with responsibilities outlined.
  • Proxy Layer: Spawns child, restarts on upgrade, seeds NTERACT_MCP_REJOIN_NOTEBOOK env var, detects binary version changes.
  • Session State Layer: Manages NotebookSession with Arc<RwLock>, guard in rejoin to avoid overwriting active session.
  • Daemon Room Layer: Manages rooms by UUID, eviction after no peers for a configurable window.
  • The Watch Loop State Machine: classify → act loop guiding rejoin decisions.
  • Session Access Pattern: require_handle pattern to minimize lock contention.

Quick Start

Review the MCP session lifecycle to identify and fix race conditions between rejoin and user-tool calls.

Frequently Asked Questions about mcp-session-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does the MCP server manage notebook session lifecycle across daemon restarts?

The MCP server manages notebook session lifecycle using a proxy supervision layer that spawns child processes, detects binary version changes, and seeds rejoin environment variables to restore sessions after daemon restarts. A daemon watch loop continuously classifies and acts on rejoin decisions.

What causes race conditions between background rejoin and user tool calls in MCP?

Race conditions between background rejoin and user tool calls in MCP occur when concurrent operations attempt to modify the shared notebook session state simultaneously. The session state layer uses Arc<RwLock<Option<NotebookSession>>> with rejoin guards to prevent background rejoin from overwriting active user-initiated sessions.

How do I debug MCP session state and reconnection logic issues?

Debug MCP session state and reconnection logic by examining the three-layer architecture: the proxy layer for child process spawning, the session state layer for Arc<RwLock> lock contention, and the daemon room layer for peer-based eviction timing after configurable windows with no peers.

When does the MCP daemon evict rooms and how is room state managed?

The MCP daemon evicts rooms by UUID after a configurable window passes with no connected peers. Room state management is handled by the daemon room layer, which tracks peer presence and cleans up idle sessions to maintain system stability across the session lifecycle.

What is the require_handle pattern in MCP session access and why is it used?

The require_handle pattern in MCP session access is a concurrency strategy used to minimize lock contention when accessing the notebook session. It ensures efficient read access to the shared session state without holding exclusive locks that would block rejoin operations.

Does the MCP proxy handle binary version changes during session reconnection?

Yes, the MCP proxy detects binary version changes during session reconnection. When an upgrade occurs, the proxy layer restarts the child process and seeds the NTERACT_MCP_REJOIN_NOTEBOOK environment variable to guide the reconnection logic back to the active notebook session.