Skip to main content

mcp-repl

mcp-repl is an MCP server that gives an agent a persistent Python or R session, kept alive across tool calls. The agent can load data once, inspect objects, try ideas, read help, make plots, and keep iterating — the way a person would in a REPL.

A shell tool running Rscript -e or python -c keeps forcing the agent to rebuild context. mcp-repl keeps the session open instead: variables, loaded packages, plots, and other state stay available until you or the model reset.

Features

  • Sandboxed by default. The backend runs in a sandbox enforced by OS primitives at the process level — not command-specific runtime rules. Network is disabled; writes are constrained to workspace roots and the temp paths the active session needs. On Unix, a memory guardrail kills the worker if it exceeds threshold.
  • Curated output. Smart echo (omitted when safe, elided for large multi-expression blocks) and in-band help pages. Plots are returned as inline images through MCP for vision-capable models, so the agent sees the plot directly; non-vision models still get the saved file path. When replies get too large, the tool response stays short and the full output is saved as a structured bundle (transcript + plot files) the model can explore on demand.
  • No polling. R and Python run embedded in the worker, not behind a stdio pipe driven by prompt-string heuristics. The server knows precisely when the interpreter is idle and has settled, so each repl call returns the moment the work is done — no fixed waits, no guessing whether more output is on the way.
  • Explicit session control. Interrupts and resets are first-class.

Quickstart

1. Install

Install via cargo (needs the Rust toolchain):

cargo install --git https://github.com/posit-dev/mcp-repl --locked
# pin a version with: --tag v0.1.0

Or use a prebuilt binary. Linux/macOS:

curl -fsSL https://raw.githubusercontent.com/posit-dev/mcp-repl/main/scripts/install.sh | sh

Windows PowerShell:

irm https://raw.githubusercontent.com/posit-dev/mcp-repl/main/scripts/install.ps1 | iex
Install-McpRepl

Append --dev (or -Dev) for the rolling dev prerelease. Direct downloads live on the latest release page. Linux x86_64 builds require glibc 2.35+; the glibc build produced on Ubuntu 22.04 supports Ubuntu 22.04+.

Latest release binaries:

Download prebuilt dev binaries:

Prebuilt binaries do not bundle R or Python; install those separately.

2. Wire into your MCP client

Auto-install into agent config files:

mcp-repl install                                 # all supported clients/interpreters
mcp-repl install --client codex                  # only Codex
mcp-repl install --client claude                 # only Claude (~/.claude.json)
mcp-repl install --client codex --interpreter r  # limit to one interpreter

By default this writes entries for both r and python.

install --client codex writes --sandbox inherit --oversized-output filesinherit tells mcp-repl to take sandbox policy from Codex's per-call metadata (it fails closed if the metadata is missing or malformed). install --client claude writes an explicit --sandbox workspace-write because Claude doesn't propagate that metadata. Bare mcp-repl (no install) defaults to --oversized-output pager.

Manual Codex entry:

[mcp_servers.r]
command = "/Users/alice/.cargo/bin/mcp-repl"
tool_timeout_sec = 1800   # outer guard; mcp-repl handles the primary timeout
args = ["--sandbox", "inherit", "--oversized-output", "files", "--interpreter", "r"]

Swap --interpreter r for --interpreter python (and rename the section) for the Python entry.

Manual Claude entry in ~/.claude.json:

{
  "mcpServers": {
    "r": {
      "command": "/Users/alice/.cargo/bin/mcp-repl",
      "args": [
        "--sandbox", "workspace-write",
        "--oversized-output", "files",
        "--interpreter", "r"
      ]
    }
  }
}

3. Pick interpreter (optional)

Resolution order: --interpreter <r|python>MCP_REPL_INTERPRETERr.

Runtime discovery

R. Set R_HOME to force a specific installation; otherwise it's discovered from R on PATH (via R RHOME). Verify with R.home() in the session.

Python. The interpreter resolves in this order:

  • nearest .venv/bin/python walking upward from cwd
  • nearest .venv/bin/python3 walking upward from cwd
  • first python3 on PATH
  • first python on PATH
  • fallback literal python3

.venv search stops at $HOME (inclusive), otherwise at the filesystem root. The selected Python must expose a loadable CPython library via its sysconfig metadata. Runtime-owned stdout/stderr is routed through worker IPC; raw fd writes and child-process output are still captured from the worker's stdout/stderr pipes.

Platform support

  • macOS: supported.
  • Linux: supported. Dev binaries are glibc builds produced on Ubuntu 22.04.
  • Windows: experimental for R. Python is not part of the stable Windows surface yet.

Sandbox

Default policy: workspace-write with network disabled. Write access covers the working area plus worker-required temp paths (exact roots vary by OS/policy). On Windows, the experimental R sandbox uses parent-prepared workspace ACLs plus launch-scoped session-temp ACLs; some environments reject the restricted-token setup.

See docs/sandbox.md for precise behavior.

MCP surface

  • repl{ "input": "1+1\n", "timeout_ms": 10000 }
  • repl_reset{}

The exact repl tool description depends on the interpreter and --oversized-output mode. Per-tool guides live in docs/tool-descriptions/.

Session control

  • Interrupt: prefix repl input with \u0003 (SIGINT, best-effort). Session continues.
  • Reset: call repl_reset, or prefix input with \u0004 (Ctrl-D); any remaining input runs in the fresh session. Reset attempts graceful shutdown, escalates to forceful termination, and on Unix falls back to scanning descendant processes if process-group signaling is unavailable.
  • In-band exits: EOF, quit(), etc. also work — output is returned and the next request runs in a fresh worker.

Debugging

Enable JSONL logs per startup:

  • CLI: --debug-dir /path/to/debug-root
  • Env: MCP_REPL_DEBUG_DIR=/path/to/debug-root

Each startup writes a session directory with events.jsonl, startup logs, and sandbox-state logs. See docs/debugging.md for the full guide, including the external wire-trace proxy.

Docs

  • Engineering map: docs/index.md
  • Sandbox: docs/sandbox.md
  • Worker sideband protocol: docs/worker_sideband_protocol.md
  • Tool guides: docs/tool-descriptions/

License

Apache-2.0. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

posit_mcp_repl-0.2.0-py3-none-win_amd64.whl (3.1 MB view details)

Uploaded Python 3Windows x86-64

posit_mcp_repl-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

posit_mcp_repl-0.2.0-py3-none-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file posit_mcp_repl-0.2.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for posit_mcp_repl-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f0cfaed8fa8aca056a37bf5b593ebe6318fcb9e773afaa087b9b8fbfca21ebdb
MD5 0f1803d8431c036d15f826f60f6c9682
BLAKE2b-256 faeb3987a989222e746111cb67b66f6325856185bc18c9298552dbba441d30c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for posit_mcp_repl-0.2.0-py3-none-win_amd64.whl:

Publisher: release.yml on posit-dev/mcp-repl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file posit_mcp_repl-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for posit_mcp_repl-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da6def0cb1b6f3f56e73dce0242a711477d17693558725f7902cb4caa049453d
MD5 ffe53ebfbb9f06b09245d436b860fe56
BLAKE2b-256 15945a113bbe6566641869b81d27d2fe327ac148decdc22676951973af0ee1a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for posit_mcp_repl-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on posit-dev/mcp-repl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file posit_mcp_repl-0.2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for posit_mcp_repl-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c30e2a40cdb98f1036ad5d9ecbc6ce2a5b2c257befa487b35043d11158edea1
MD5 b31e6ac229642e2a756f7dc796816983
BLAKE2b-256 a35e364524daf747be8a65ede8196e9b047f1866398144bc4d1be92c06973693

See more details on using hashes here.

Provenance

The following attestation bundles were made for posit_mcp_repl-0.2.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on posit-dev/mcp-repl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.0

3 files

This release

0.2.0 This release

3 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page