Pi Session MCP README

The full upstream README, mirrored for reference. Install config, tool schemas, adoption signals and our own overview live on the Pi Session MCP listing page.

pi-session-mcp

CI npm Node.js License: MIT

Let Codex or Claude Code delegate work to Pi coding-agent sessions, under rules that you set.

Pi Session MCP is a local, stdio-only Model Context Protocol (MCP) server. The client never chooses a directory, a model or a permission level. It picks from workspace and execution-profile aliases that you define in a local configuration file, then starts a session, sends prompts, polls the turn and closes the session. The server embeds the Pi SDK, keeps sessions in memory and talks only over stdin and stdout.

Pi Session MCP is an independent project. It is not affiliated with or endorsed by the makers of Pi, OpenAI or Anthropic. Product names are used only to describe compatibility.

Status: pre-1.0. Version 0.23.1 is for Linux and macOS with Codex CLI or Claude Code. Each release passes the provider-free checks, except where its acceptance record names one. 0.23.1 keeps Pi SDK 1.6.0, to which 0.23.0 moved, and adds setup CLI changes: its release candidate passed the provider-free checks and the setup acceptance, and no live cycle has run on Pi SDK 1.6.0. The last full live cycle with both clients ran on the 0.22.2 release candidate with Pi SDK 1.5.2. The 0.23.1 acceptance record lists what ran and what is not established; the post-release evidence adds two read-only checks on upgraded installations, and no provider-backed check. A coding profile is not an operating-system sandbox; the threat model states the limits.

Example · Quick start · Status · Security model

mermaid
flowchart LR
  C["Codex or Claude Code<br/>(controller)"] -- "MCP over stdio" --> S["pi-session-mcp"]
  S -- "embedded Pi SDK" --> P["Pi session<br/>(in memory)"]
  P --> M[("Model provider")]
  S -. "container workspaces" .-> W["Leased writer pool<br/>(rootless Podman)"]
  S -. "opt-in" .-> H[("Session history")]
  S -. "opt-in" .-> K[("Provider store")]
  S -. "opt-in" .-> R{{"Tier routing"}}

Example: a second opinion

With the server registered, ask Codex or Claude Code in plain language:

text
Get a second opinion from a Pi worker through the pi-session-mcp tools.
List the configured aliases with pi_capabilities_get. Start a session on the
workspace alias for this repository with the default read-only execution
profile. Ask the worker to review src/parser.ts and its tests for correctness
bugs and unhandled edge cases. Poll the turn until it is finished, close the
session, and report the findings with file and line. Check each finding
against the code before you act on it.

Replace src/parser.ts with a file of yours. The prompt needs:

  • the package installed and registered with your client (Quick start);
  • a configuration that names the repository as a workspace alias and has a read-only execution profile. One read-only profile is the default, so the prompt names none;
  • authentication for that profile's provider: an account sign-in (pi-session-mcp-provider auth login) or a key in the provider store.

The prompt is a request to your client, and the client's configuration decides what happens: the model it runs, whether it loaded the orchestration skill, and which tool calls it makes without asking you. The server enforces the configured aliases, the profile's tool allowlist and the limits of a turn. It cannot make either model follow the prompt, and the worker's answer can be wrong. The built-in tools of a read-only profile read files inside the workspace and run no commands unless the profile opts into the sandboxed shell, so name files instead of asking for a git diff. Tools that you grant to a profile from extensions or external MCP servers are outside that limit and may write or run commands; for this example, use a profile without them or with grants you have vetted.

Why use it

  • A second model inside your agent. A read-only Pi session on another model reviews a change or answers a question about a codebase, and your main agent reads the answer.
  • Bulk reading stays out of the main context. Pi does the exploring; only its final answer returns, capped at 64 KiB.
  • Work goes to a model you choose. An execution profile binds a provider, a model and a thinking level, so routine work can run on a local or cheaper model.
  • Follow-ups keep their context. A session stays open across prompts.
  • You set the limits. The client selects aliases only. The default profile is read-only, and profiles grant exactly the skills and external MCP tools you list.
  • Predictable to automate. Sessions and turns have few states and stable error codes. Errors and the session, turn and capability metadata carry no paths, credentials, prompts or raw provider errors. The worker's answer, assistantText, is model output and comes back unsanitized.

It is not the right tool when you want to work with Pi yourself (run Pi directly), when you need remote access, several users or sessions that survive a restart, or when you need to contain untrusted code: a coding profile limits Pi's tools, but it is not an operating-system sandbox.

Quick start

On Linux or macOS with Node.js 22.19.0 or newer, download the installer of the latest release and check it:

sh
base=https://github.com/plagor44-ux/pi-session-mcp/releases/latest/download
curl -fsSLO "$base/install.sh" && curl -fsSLO "$base/install.sh.sha256" &&
  sha256sum -c install.sh.sha256

On macOS, use shasum -a 256 -c install.sh.sha256 instead of sha256sum -c install.sh.sha256. For a fixed version, replace latest/download with download/v<version>. This README describes v0.23.1.

The checksum comes from the same release as the script. A match shows that the two files belong together, which catches a damaged or incomplete download. It does not prove who published the script, because whoever can replace one file can replace both. Read install.sh before you run it. It is short: it checks the platform and the Node.js version, runs npm install -g pi-session-mcp@<version> with the version written in the script unless that version is installed already, and starts pi-session-mcp-setup --guided --apply. It refuses to upgrade a different installed version.

sh
sh install.sh

The script pins the package version, and the package pins its direct dependencies. npm resolves the transitive dependencies at install time within the ranges those dependencies declare. For the dependency tree the maintainers tested, install from a release tag with npm ci.

The script then runs the guided setup. The interview proposes profiles from Pi's offline model catalog and asks before it probes a provider, changes an existing configuration or allows host writes. You sign in or store keys yourself; setup does not read, print or store a credential. When you apply on an interactive terminal, the interview first offers, for each provider you name, to sign in to a provider account with pi-session-mcp-provider auth login <provider> or to store an API key with pi-session-mcp-provider auth set <provider>. A sign-in runs Pi's own dialogue on your terminal and leaves the token in Pi's credential store. The key command prompts for an API key with echo off and stores it in Pi Session MCP's own provider store. Setup receives only the command's exit status. Answer no, the default, and setup leaves every credential source as it is.

Recommended setup for coding agents

A coding agent can do two jobs here: install Pi Session MCP for its owner, and then control Pi workers through it. Each has its own guide; this section gives the order and the boundaries.

Installing on the owner's behalf. Do not run install.sh: it applies directly after installing, has no dry run and needs an interactive terminal unless you pass --answers. Instead:

  1. Check whether the package is installed already: npm ls -g pi-session-mcp --depth=0 --json. If it is not, install it from npm with an exact version, npm install -g pi-session-mcp@<version>. If the same version is there, reuse it. If another version is there, this is an upgrade: stop and take the owner-approved upgrade procedure, which starts by closing the client sessions; installing over it first can leave registrations bound to the old release. Then read the offline model catalog with pi-session-mcp-setup --list-models --json.
  2. Write an answers file and run the guided setup as a dry run: pi-session-mcp-setup --guided --answers <file> --json. Show the owner the plan and the findings.
  3. Add --apply only after the owner has approved that exact plan.
  4. Verify with pi-session-mcp-doctor --json and pi-session-mcp-setup --verify --target <client-target> (for example claude-code:user:pi-session-mcp or codex:user:pi-session-mcp).

The owner does these steps, never the agent: the provider sign-in pi-session-mcp-provider auth login <provider>, key entry with pi-session-mcp-provider auth set <provider>, any second-factor prompt of the provider, and the approvals that spend money or widen access (provider probes, changing an existing configuration, host writes). An agent never asks for, handles or stores a credential. See the agent install guide.

Recommended setup for a controlling agent (Claude Code or Codex).

  • Review on read-only profiles, and from a different model family than the author of the change. The default profile must be read-only. Tier routing can enforce the family rule for routed reviews with authorFamily (tool contracts).
  • Coding in container workspaces on Linux, where each coding session leases a rootless-Podman writer with its own full clone (execution modes). Host writes need the owner's explicit acceptance.
  • The bundled controller skills, installed into the client by setup (Pi skills): pi-session-orchestration covers choosing aliases, scoping a task, running workers in parallel, polling, verifying results independently and closing sessions; pi-session-profiles covers creating, changing and retiring profiles, a bounded provider probe, safe writer replacement and reporting.
  • Optional tier routing, to let the server pick a profile within a tier for a role (Operate routing).
  • A writer image beyond the built-in node, for example with a Go toolchain: Building a custom writer image, and for an agent that does it on the owner's behalf, the agent guide to writer images.

When to stop and ask the owner. Setup changes, provider sign-in, spending, host writes, removing or replacing a writer and anything that deletes work are the owner's decisions. The stop lists are in the agent install guide and the agent guide to writer images. Judge a guided dry run by its overall status and exitCode and by the status of each finding. A run that ends planned with exit code 0 is the plan: its planned findings (for example configuration_planned, probe_planned, mode_planned and registration_planned) and its unchanged ones (for example configuration_unchanged, or podman_unavailable and bubblewrap_unavailable for optional features the host lacks) do not block; show the plan to the owner. A blocker that the agent install guide lists, a finding with the status failed, divergent or unsupported, or a non-zero exit code means stop, and so does anything you cannot place: stop and ask. The writer image guide has its own tables of codes that continue and codes that stop.

Tools

ToolPurpose
pi_capabilities_getList the configured workspace and execution-profile aliases.
pi_session_startStart a session for one workspace alias and one execution-profile alias.
pi_session_listList the sessions of this server process.
pi_session_getRead one session.
pi_session_promptSend a prompt and get a running turn back.
pi_turn_getPoll a turn until it is completed, failed or aborted.
pi_session_abortAbort a running turn.
pi_session_closeEnd a session and release its resources.

The tool contracts define every field, state and error code. The package also ships an orchestration skill for the controlling agent, which setup installs into Claude Code and Codex.

Features

FeatureWhat it doesDocs
Execution modesEach repository is read-only, host, container or a snapshot review slot. host coding needs an explicit host-write acceptance; an alias without a mode keeps legacy host coding and Doctor warns about it.Execution modes
Leased writer poolOn Linux, each coding session on a container workspace leases a rootless-Podman full-clone writer through the one host registration. Setup collects and resets writers; no reconnect is needed after reset, finish or recreate.ADR 0012
Hardened read-only profilesRead-only sessions read only inside their workspace and selected skills. On Linux they can opt into a bubblewrap shell without network, home or host writes.ADR 0013
Pi skillsProfiles select role skills (implementation, review, your own) from a catalog in your configuration.Pi skills
External MCP toolsProfiles grant individual tools of local stdio MCP servers, and nothing else from them.Session MCP
Controller wakeContent-free turn events let a Claude Code hook wake the controller instead of polling.Wake the controller
Review snapshotsRead-only reviews on a verified, fixed commit.ADR 0015
Session historyOpt-in, redacted local SQLite record of sessions, with a CLI for listing, verdicts, queries and export.Session history
Tier routingOpt-in server-side choice of a profile within a tier (ultra, hightech, medium, low), manual or learning from history.Operate routing
Doctor and setupAn offline health check, and reproducible registration, verification and removal for each client.Client setup
Provider CLIpi-session-mcp-provider manages local provider definitions and each provider's credential source (Pi's login, a stored API key or none), and signs in to and out of provider accounts through the bundled Pi.Provider credentials

Status

The package version is 0.23.1.

StabilityPre-1.0. Tools, fields, states and error codes change only in a new minor release.
PlatformsLinux and macOS with Node.js 22.19.0 or newer. CI covers macOS 15 and 26 on Apple silicon; Intel Macs are untested. Setup refuses other platforms with platform_unsupported.
ClientsCodex CLI and Claude Code. Setup accepts a client whose public mcp command output matches the expected contract, without pinning versions.
AcceptanceEvery release passes the provider-free checks, except where its acceptance record names one; the release candidate of 0.23.1 passed them, with npm audit reporting 0 vulnerabilities on the day of the run. The last full live two-client cycle ran on the 0.22.2 release candidate with Pi SDK 1.5.2 (record): all ten tasks and every live criterion passed. The cycles before it ran on 0.16.1 (record) and on the main commit 93980d9 (record); 0.20.1 to 0.22.1 have no cycle of their own, and neither have 0.23.0, which moves to Pi SDK 1.6.0, and 0.23.1. For 0.23.1 the acceptance record names what is not established, among it any live cycle on Pi SDK 1.6.0, an abort during a coding session's read against a real provider, a profile with maxOutputTokens against a real provider, tier routing with real routed starts, and macOS outside CI. After the release, two read-only checks ran on the upgraded installations (post-release evidence): --writer <name> --inspect on every container writer of two installations, which reported writer_clean each time (the other verdicts rest on tests only), and --guided --answers with three refused answers files on the installed package, which exited with 64 each time. The levels are defined in Acceptance.
Out of scopeHTTP, a web UI, resume, remote access and multi-user behavior. One trusted local MCP peer talks to one server process.

Security model

  • Local and single-peer. No network listener and no daemon. Sessions live in memory and end with the server process; nothing restores them. The opt-in session history keeps a record of sessions for reading, redacted on a best-effort basis. The opt-in provider store keeps credential sources, API keys and custom provider definitions, and no session content.
  • Aliases instead of paths. No tool accepts a working directory, a model, a provider or a credential.
  • No credential input over MCP. By default each built-in provider uses Pi's own login (inherit); a provider you define yourself has no credential until you store a key. Pi Session MCP resolves Pi's login through the Pi SDK and does not print it or put it into errors or metadata. pi-session-mcp-provider auth set can store an API key for one provider in a local store, protected by file permissions (0700 directory, 0600 files) and not encrypted; that key then replaces Pi's login for that provider. pi-session-mcp-provider auth login runs Pi's own sign-in dialogue on your terminal and receives only Pi's exit status, never the token. The token stays in Pi's credential store, where sessions resolve it like any other Pi login. auth logout deletes Pi's local entry and revokes nothing at the provider. A container writer receives the credentials of its selected providers and no others, an OAuth entry without its refresh token, and code that runs in that writer can read them. See provider credentials and ADR 0021.
  • Explicit policy file. The configuration comes only from PI_SESSION_MCP_CONFIG, never from the client's working directory.
  • Sanitized errors and metadata. Errors are stable codes, and session, turn and capability metadata are whitelists. They carry no paths, prompts, raw provider errors, credentials or credential locations.
  • Unsanitized answers. assistantText is the worker model's output, returned as written and capped at 64 KiB. It can repeat workspace content, absolute paths and any secret the worker read. Treat it as sensitive.
  • Fail closed. Unknown fields, unknown aliases, unexpected client output and divergent registrations are rejected, not repaired.
  • Bounded waiting. Session creation, prompt acceptance, abort, close and shutdown have fixed deadlines.

The threat model states the assumptions and limits, including what a coding profile does not protect against and what code in a container writer can do with the credentials it receives.

Documentation

OperateContract and designMaintain
InstallationTool contractsAcceptance
Agent install guideArchitectureReleasing
Client setup referenceThreat modelRoadmap
Execution modesSetup lifecycle designProfile evaluation
Pi skillsDoctor contractContributing
Session MCP toolsDecision recordsSecurity policy
Session historyChangelog
Writer images

Development

Terminal
npm ci
npm run typecheck
npm run build:cli
NODE_OPTIONS=--unhandled-rejections=strict npm test
npm run build

These are the CI checks. Tests use a fake Pi adapter or a scripted model and need no provider credentials. Every direct dependency is pinned exactly. A nightly canary tests the unchanged sources against the newest Pi SDK. Rules for contributors and coding agents are in AGENTS.md; to run the server by hand or with the MCP Inspector, see client setup.

License

MIT