mcp-session-lifecycle

mcp-session-lifecycle is a skill for Claude Code, Codex from nteract/nteract. It costs 71 tokens per session (2,994 once invoked), scanned A, original, BSD-3-Clause.

Technical guidance for understanding how runt-mcp keeps notebook connections alive across proxies, background reconnects, daemon upgrades, and room removal. MCP is a standard for connecting an AI agent to external tools and services.

In plain words
What is it for?
Use it when debugging or changing runt-mcp, its proxy, daemon watching, reconnect logic, or notebook room lifecycle.
Why use it?
It explains the shared session state and timing issues that can otherwise cause reconnects, joins, or tool calls to race with each other.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: installed under .agents/ (shared by several agents).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/nteract/nteract/mcp-session-lifecycle
Any agent
npx skills add nteract/nteract --skill mcp-session-lifecycle
Clone the repo
git clone --depth 1 https://github.com/nteract/nteract

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for mcp-session-lifecycle

README.md
[![agentmods](https://agentmods.dev/badge/skills/nteract/nteract/mcp-session-lifecycle.svg)](https://agentmods.dev/skills/nteract/nteract/mcp-session-lifecycle)
Your own site
<a href="https://agentmods.dev/skills/nteract/nteract/mcp-session-lifecycle"><img src="https://agentmods.dev/badge/skills/nteract/nteract/mcp-session-lifecycle.svg" alt="Measured on agentmods" height="20"></a>
Per session 71 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,994 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00071 $0.02994
Opus 5 $0.00036 $0.01497
Sonnet 5 $0.00014 $0.00599
Haiku 4.5 $0.00007 $0.00299

Measured today against content hash 30ca3e5d95d5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

mcp-session-lifecycle scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/mcp-session-lifecycle/SKILL.md · 254 lines

How it starts

The opening of the file, as written. The whole thing — 254 lines — stays where its author put it; the contents beside it link to each section on GitHub.

MCP Session Lifecycle

Use this skill when debugging session state, changing reconnection logic, working on the proxy, or reasoning about races between background rejoin and user-initiated tool calls.

Source checkpoint: 2026-09-04 at 6bff3e7b. The decision record is docs/adr/mcp-session-lifecycle.md. Read the source functions below rather than copying an abbreviated session struct or reconnect algorithm.

Three Layers

  • Process supervision: installed nteract-mcp and development mcp-supervisor use the runt-mcp-proxy library to supervise a runt mcp child. The library is not an executable entrypoint.
  • MCP session state: the child owns one active NotebookSession, a bounded map of parked sessions, explicit activation generations, and the daemon watch loop.
  • Daemon room state: runtimed owns notebook rooms, runtime state, kernels, recovery, and peer accounting. Kernel teardown and room reaping are separate.

The shipped MCP entrypoints use stdio. Multiple MCP clients can run separate children against the same daemon, including the same notebook room. Concurrent requests on one stdio connection share that child's active slot; they are not independent MCP clients. The daemon's multiplexed notebook frames are a separate protocol, not an HTTP MCP endpoint.

Entry points: crates/runt/src/main.rs:739, crates/nteract-mcp/src/main.rs:260, and crates/mcp-supervisor/src/main.rs:2910.

Proxy Layer

McpProxy::track_session and session::extract_session_id track one preferred restart target, despite the field name last_notebook_id:

  • Successful connect/create calls prefer the child's canonical file path for local file-backed notebooks, falling back to a UUID. Hosted targets retain their URL identity.
  • Successful save_notebook promotes a local UUID target to the saved path.
  • Disconnecting the active notebook clears the handoff. Disconnecting another parked notebook preserves it. Failed calls do not replace the target.
  • Restart re-resolves the child executable and seeds NTERACT_MCP_REJOIN_NOTEBOOK. It does not reconstruct the parked map.
  • Exit 75 is an intentional daemon-upgrade handoff, separate from the normal crash budget. Other restarts are subject to the proxy's restart controls.
  • Daemon-version banners compare the old and new child's reported ServerInfo.server_info.title, not binary SHA. A banner says rejoin was requested; it does not prove that notebook readiness has completed.
  • The reconnect tool restarts the child, not the daemon.

Read the full file on GitHub · 254 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today Changed · +2 lines 30ca3e5d95d5
  2. 6d ago First seen · 252 lines · 71 tokens per session scan A b95db106ea2d

Subscribe to this mod's changes

mcp-session-lifecycle is a skill published in the GitHub repository nteract/nteract (166 stars, last pushed yesterday), licensed BSD-3-Clause. It adds 71 tokens to every session and 2,994 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

local-ai-agents

Build local-first AI agents that run entirely on a developer workstation with Microsoft Foundry Local and Qwen function-calling models. Covers Small Language Models (SLMs), the OpenAI-compatible local endpoint, sandboxed local tools, local RAG with Chroma, local MCP servers, hybrid cloud/local routing, and the…

microsoft/ai-agents-for-beginners · 200 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

next-partial-prefetching-adoption

Turn on Partial Prefetching in a Next.js app and work through the insights it surfaces. Use when the user wants to enable or adopt Partial Prefetching, flip the partialPrefetching flag, opt routes in with export const prefetch = 'partial', audit Link prefetch={true} behavior, preserve existing prefetched UI with…

vercel/next.js · 103 tokens

chronicle

Analyze Copilot session history for standup reports, usage tips, session search, and session reindexing. Use when the user asks for a standup, daily summary, usage tips, workflow recommendations, wants to search or find past sessions by keyword/file/PR, wants to reindex their session store, or asks about deleting…

microsoft/vscode · 72 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens