Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Development

Layout

PathWhat
src/main.rsBinary: flags, then the MCP server on stdio.
src/server/The MCP tools (mod.rs). Most forward their arguments to a Lua handler; the larger bodies are in handlers.rs.
src/args/Tool arguments; their doc comments become the JSON schema descriptions.
src/bridge.rsFile-based IPC client for the Lua bridge.
src/track_templates.rsTrack template and FX chain manipulation on REAPER state chunks.
src/audio.rsWAV reading, loudness (BS.1770), spectrum and comparison.
src/reaper_host.rsWindows-only helpers that work without the bridge.
lua/reaper_mcp_bridge.luaThe loop inside REAPER: reads requests, runs handlers, writes responses and the heartbeat.
lua/reaper_mcp_handlers.lua, lua/handlers/One handler per command, grouped by area (project, tracks, items, fx, envelopes, render); shared helpers in support.lua. Reloadable with reload_bridge.
tests/lua/fake_reaper.luaIn-memory fake of the ReaScript API for tests.
docs/This book (mdBook).

Build and check

cargo build
cargo fmt --all
cargo clippy --all-targets -- -D warnings
cargo test --all-targets

CI runs the same on Linux, macOS and Windows, plus a Lua syntax check and ShellCheck. A pull request can be merged only when CI passes.

Tests

  • Unit tests next to the code: state chunk edits, argument schemas, JSON rounding.
  • tests/bridge_*.rs (bridge_ipc, bridge_tracks, bridge_items, bridge_fx, bridge_project; shared harness in tests/common/) run the real bridge and handlers in a Lua 5.4 interpreter against tests/lua/fake_reaper.lua, and talks to them through BridgeClient, the IPC the server uses. Install lua5.4 (or a lua that is 5.4) to run them; without one they are skipped locally, and CI requires them (REAPER_MCP_REQUIRE_LUA=1). The fake raises an error naming any ReaScript function it does not implement, so extend it when a test needs more.
  • tests/audio_analysis.rs and tests/audio_signals.rs check the analysis against generated signals with known levels; tests/track_templates_chunks.rs covers the FX chain chunk editing.
  • Consistency checks in src/server/mod_test.rs: every tool has a unique name, a description and an object schema; every command the server sends has a Lua handler; docs/src/reference.md matches the tool definitions.

Adding a tool

  1. Add the arguments to the matching file in src/args/ with a doc comment on every field.
  2. Add the tool to src/server/mod.rs with a description that says what it changes and what it returns.
  3. Add the handler to the matching file in lua/handlers/ as handlers.<name> = function(args). Validate arguments first, then change the project inside undo("…", function() … end).
  4. Add a test in the matching tests/bridge_*.rs and the ReaScript functions it needs to the fake.
  5. Regenerate the reference: REAPER_MCP_UPDATE_DOCS=1 cargo test.
  6. If the bridge calls new ReaScript functions, update the counts and the text in the REAPER API coverage table and its copy in README.md; python3 scripts/check-api-coverage.py prints the counts and fails in CI while they differ. Update the roadmap when a gap closes.

To try a handler change in a running REAPER without restarting it, copy the Lua files with the install script and call reload_bridge.

Documentation

cargo install mdbook
mdbook serve docs

The book is published to GitHub Pages when docs/ changes on main.

Pull request titles

Pull requests are merged with Squash and merge: the title becomes the commit message on main, so it must be a Conventional Commit. feat: and fix: appear in the changelog and choose the next version; docs:, test:, refactor:, ci: and chore: do not. See Releases.

End-to-end with real REAPER

The bridge tests use a fake ReaScript API. To check the tools against a real REAPER on Linux:

mkdir -p ~/opt/reaper-test && tar -xJf reaper*_linux_x86_64.tar.xz -C ~/opt/reaper-test
touch ~/opt/reaper-test/reaper_linux_x86_64/REAPER/reaper.ini   # portable: leaves ~/.config/REAPER alone
scripts/e2e-reaper.sh [--samples] ~/opt/reaper-test/reaper_linux_x86_64/REAPER

The script builds the server, installs the bridge from the checkout into that REAPER, starts it with an empty project on its own virtual X display (Xvnc or Xvfb) and runs the scenarios over MCP:

  • scripts/e2e/scenario.py tries the tools one area at a time on a few tracks.
  • scripts/e2e/project_scenario.py builds a realistic 17-track project the way an agent would: audio from make_audio.py (drums, bass, guitars and a vocal-like part, generated, so nothing is stored in the repository), folders under a MIX BUS, reverb and delay returns fed by sends, a ReaSynth part, song sections as regions. It then checks the structure, normalizes, renders the mix, group stems, variants and sections, compares the mix with a reference, exports and applies mix templates and FX chains, and saves and reopens the project.
  • scripts/e2e/tools_scenario.py covers the tools the others do not reach: FX parameters, choices, presets, pins and envelopes, sends, a multi-output instrument (ReaSynDr), item and track moves, media offline, project settings, actions and reloading the bridge.
  • scripts/e2e/dialogs_scenario.py writes two small projects that make REAPER open “Project Settings” (notes shown on load) and “Project Load Warning” (unknown token), opens each with and without REAPER_MCP_CLOSE_DIALOGS=1, and checks closed_dialogs, the timeout hint, show_on_load and the notes’ line ends. No download needed. Only scripts/e2e-reaper.ps1 runs it so far; on Linux the same dialogs are exercised by --samples.
  • scripts/e2e/multi_scenario.py starts a second REAPER (-newinst) on its own IPC directory, checks that each server reaches only its own instance, and runs two server processes on one REAPER at once.
  • With --samples, scripts/e2e/samples_scenario.py opens eight of the old sample projects Cockos publishes (recorded audio, REAPER 0.x to 2.x), reads every track with the read-only tools, checks the track and item counts against the .rpp files, renders and analyses each mix. The projects are downloaded once into ~/.cache/reaper-mcp-e2e/samples; they are copyrighted by their authors and never stored in this repository.

Some projects make REAPER open a modal window while loading (“Project Load Warning” for unknown project tokens, “Project Settings” for a project that shows its notes on load). The samples scenario runs the server with REAPER_MCP_CLOSE_DIALOGS=1 and checks that it closed them, so --samples needs xdotool. Each check prints one line, and the run fails when a value is wrong. It uses only REAPER’s bundled plugins and works in evaluation mode. Run it before a release and after changing a handler; extend a scenario when a tool changes.

On Windows

Copy-Item 'C:\Program Files\REAPER (x64)' C:\opt\reaper-test -Recurse
New-Item C:\opt\reaper-test\reaper.ini -ItemType File     # portable: leaves %APPDATA%\REAPER alone
scripts\e2e-reaper.ps1 [-Samples] [-KeepWork] -ReaperDir C:\opt\reaper-test

The script does the same on Windows: it builds the server, installs the bridge into the copy (install-bridge.ps1 -Startup), starts REAPER and runs the same scenarios. Needs cargo and Python 3 (python, python3 or py -3). Things it handles that a hand-made run trips over:

  • REAPER is started with -newinst -cfgfile <dir>\reaper.ini. Without -newinst a running REAPER takes over the command line (a new tab in your session); without -cfgfile a copy made by the installer falls back to %APPDATA%\REAPER and loads the bridge installed there.
  • A fresh profile opens first-run dialogs (audio device, new version, About). The script answers them with “No” (or closes them) and waits for the plug-in scan to finish; closing the scan window makes add_fx fail.
  • The work directory is %TEMP%\reaper-mcp-e2e <non-ASCII> <id>, so paths with spaces and non-ASCII characters are exercised on every run.
  • The REAPER it started is closed through its window (a “Save changes?” prompt gets “No”) and never killed; if it stays open the script says so.
  • tools_scenario.py opens a track FX window, checks inspect_reaper_windows, closes it with close_reaper_fx_windows, and runs restart_bridge when it is the only REAPER process and a bridge is installed in %APPDATA%\REAPER (the tool always restarts the first REAPER it finds and loads that install, so otherwise the step is skipped, and when it runs it writes its startup wrapper there).
  • -Samples runs the Cockos sample projects with REAPER_MCP_CLOSE_DIALOGS=1 (no xdotool needed); the zips are cached in %LOCALAPPDATA%\reaper-mcp-e2e\samples.

Every tool must run in a scenario: python3 scripts/check-e2e-coverage.py (in CI) fails when a tool is neither called by a scenario nor listed in that script with the reason it cannot be run (today none). A new tool therefore comes with its scenario steps.