Keep this file short. It is a table of contents, not the full manual.
- If you modified code, run all required checks before replying:
env RUSTFLAGS=-Dwarnings cargo checkenv RUSTFLAGS=-Dwarnings cargo buildpython3 tests/run_integration_tests.py --binary target/debug/mcp-replcargo clippy --all-targets --all-features -- -D warningsenv RUSTFLAGS=-Dwarnings cargo test --quietcargo +nightly fmtenv RUSTFLAGS=-Dwarnings cargo build --release --locked
- For docs-only changes, run the narrow docs validation that covers the edited
files, usually
cargo test --test docs_contracts. - When changing Codex backend selection or CI real-client wiring, also run:
MCP_REPL_CODEX_BACKEND=mock cargo test -j 1 --test codex_integration codex_exec_auto_backend_smoke -- --test-threads=1
- Rust compiler warnings are errors in local verification and CI.
- Treat all clippy warnings as failures. Do not leave warning cleanup for later.
- Never pass
--vanillatoRorRscriptunless the user explicitly asks for it.
docs/index.md: source-of-truth map for repository docs.docs/architecture.md: subsystem map for the CLI, server, worker, sandbox, output, and validation surfaces.docs/testing.md: public verification surface and snapshot workflow.docs/debugging.md: debug logs,--debug-repl, and stdio tracing.docs/sandbox.md: sandbox modes and writable-root policy.docs/output_timeline.md: visible output ordering across sideband and raw streams.docs/worker_sideband_protocol.md: current server/worker IPC contract.docs/plans/AGENTS.md: when to create checked-in execution plans.
- Agent: The model-facing actor using an MCP client to call
repl. - MCP client: Codex, Claude, or another app that starts
mcp-replover MCP stdio and sends tool calls. - Server: The main
mcp-replRust process in MCP server mode. It owns the MCP surface, worker lifecycle, sandbox application, timeout policy, stdout/stderr capture, sideband interpretation, and response finalization. - Worker: The child process spawned by the server to run the selected R or Python REPL. It runs inside the effective sandbox and owns the worker-side endpoint of sideband IPC.
- Worker child process: Any direct or indirect process spawned by user code or the backend under the worker. It may inherit stdout/stderr, but it must not own sideband IPC.
- Backend / interpreter:
backendis the worker-side implementation that presents a selected REPL runtime to the server and MCP client.interpreteris the user-facing selector for that presented runtime, currentlyrorpython; it does not describe the implementation language of the worker binary. - Runtime: The live R or Python execution environment inside the worker. This is where client-submitted code via
replis evaluated. - REPL session: The stateful runtime in the active worker. One session per worker process instance.
- Tool call: One MCP client invocation of
repl. - Request: The unit of input accepted by the server for the worker to execute. A request may outlive the initial tool call when it times out and later polls drain output.
- Reply: The MCP tool result returned to the client. Reply finalization is server-owned and may combine worker-originated content with server-only status notices.
- Poll: An empty
replinput used to drain pending output, wait again on a previously timed-out request, return idle status, or advance pager mode. - Host: The user's machine and OS environment outside the worker sandbox. Avoid
host-ownedunless the owner is explicitly distinguished from the MCP client, server, worker, and OS/user. - Sandbox policy: The effective OS-level permissions applied to the worker:
read-only,workspace-write,danger-full-access, orexternal-sandbox. - Sandbox metadata: Codex per-tool-call
_meta["codex/sandbox-state-meta"]used by--sandbox inheritto choose the effective worker sandbox for that call. - Writable root: An absolute path that a
workspace-writeworker may write, subject to forced read-only subpaths like.git,.codex, and.agents. - Session temp directory: The server-allocated per-session temp path exposed to the worker as
TMPDIRandMCP_REPL_R_SESSION_TMPDIR. - Sideband IPC: The JSON-lines server/worker pipe for structural facts such as
readline_start,readline_input,readline_discard,output_text,plot_image, andsession_end. - Raw output capture: The stdout/stderr pipes or PTY stream captured by the server for unowned visible text. Sideband carries worker-owned text and structural facts.
- Output timeline: The server-side reconstruction of visible output order from captured stdout/stderr plus sideband facts.
- Server-owned: State, files, or notices created and retained by the main server process, not by the runtime or the worker. Use this for output bundles, response finalization, debug logs, and server temp roots.
- Worker-originated text: Text that came from the worker REPL or worker child processes and can be written to
transcript.txt. - Server-originated text: Status text synthesized by the server, such as timeout, busy, restart, sandbox, or bundle notices. Also called server-only text when contrasting with worker-originated transcript text.
- Output bundle: A server-owned directory for oversized (potentially mixed text/image) output in files mode, with a bounded inline preview plus inspectable files.
transcript.txt: Bundle file containing worker-originated REPL text only, including echoed input, prompts, stdout, and rendered stderr text.events.log: Bundle index for mixed text/image history.Trows point intotranscript.txt,Irows point to image history, andSrows are server-originated omission notices.- Files mode / pager mode:
--oversized-output filesspills large replies into output bundles;--oversized-output pagerkeeps oversized text in an interactive pager that consumes tool-call input locally instead of forwarding it to the worker until the pager exits or reaches the end. - Debug REPL:
--debug-repl, a local interactive driver for the worker that bypasses MCP client/server traffic. - Wire trace: The external stdio proxy log of exact bytes between an MCP client and the
mcp-replserver.
- Preferred loop:
cargo insta testcargo insta pending-snapshotscargo insta revieworcargo insta accept/cargo insta reject
- CI-style validation:
cargo insta test --check - Do not add
--unreferenced=rejectto the general snapshot check; this repository keeps valid platform-specific snapshots that are unreferenced on other platforms. - For broad intentional snapshot migrations:
cargo insta test --force-update-snapshots --accept - Do not delete
tests/snapshots/*.snap.newmanually. Usecargo insta reject.
- For multi-phase refactors, redesigns, or other work that spans discovery, iteration, and implementation, keep a living plan under
docs/plans/active/until the initiative is complete. - Use the plan to capture design decisions, rejected options, phase boundaries, unresolved questions, and the next safe slice of work so a later agent does not need to rediscover them.
- Plans and future-work notes should include a motivating task, use case, or MRE-style scenario before design details. Capture what the agent, MCP client, server, worker, or user should be able to do, then list constraints and options.
- If you pause or hand off work mid-task, update the plan before stopping.
- Do not create plan files for routine, obvious, or low-risk changes. Keep the plans area useful, not noisy.
- Move completed plans to
docs/plans/completed/. - Treat
docs/notes/anddocs/futurework/as exploratory, not normative.
- Consult
~/github/wch/r-sourcefor R behavior details. - Consult
~/github/python/cpythonfor Python behavior details.