@mthines/reaper-mcp 0.70.3 → 0.71.0-beta.80.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js CHANGED
@@ -136,6 +136,10 @@ var ALLOWED_SPAN_ATTRIBUTES = /* @__PURE__ */ new Set([
136
136
  "reaper.bridge.handler_ms",
137
137
  "reaper.bridge.pickup_ms",
138
138
  "reaper.bridge.poll_attempts",
139
+ // Whether the bridge answered at startup and, when not, which setup step is missing
140
+ // (a fixed set: connected, stale, never_started, not_installed, no_reaper — never a path)
141
+ "reaper.bridge.connected",
142
+ "reaper.bridge.state",
139
143
  // detect_key / detect_chords: where they read from and how sure they were, never the key or chords
140
144
  "reaper.key.source",
141
145
  "reaper.key.confidence",
@@ -607,15 +611,89 @@ async function ensureBridgeDir() {
607
611
  await mkdir(dir, { recursive: true });
608
612
  return dir;
609
613
  }
614
+ var BRIDGE_NOT_RUNNING_PREFIX = "Bridge not running:";
610
615
  function classifyBridgeError(error7) {
611
616
  if (error7?.startsWith("Timeout:")) return "timeout";
617
+ if (error7?.startsWith(BRIDGE_NOT_RUNNING_PREFIX)) return "bridge_not_running";
612
618
  if (error7?.startsWith("Handler error:")) return "handler_crash";
613
619
  if (error7?.startsWith("Unknown command type")) return "unknown_command";
614
620
  if (error7?.startsWith("Internal error:")) return "internal_error";
615
621
  return "command_failed";
616
622
  }
617
623
  function isSystemError(type) {
618
- return type !== "command_failed";
624
+ return type !== "command_failed" && type !== "bridge_not_running";
625
+ }
626
+ var HEARTBEAT_FRESH_MS = 5e3;
627
+ var BRIDGE_DOWN_AFTER_MS = 6e4;
628
+ async function heartbeatAgeMs() {
629
+ try {
630
+ const info = await stat(join3(getBridgeDir(), "heartbeat.json"));
631
+ return Math.max(0, Date.now() - info.mtimeMs);
632
+ } catch {
633
+ return void 0;
634
+ }
635
+ }
636
+ async function exists(path) {
637
+ try {
638
+ await stat(path);
639
+ return true;
640
+ } catch {
641
+ return false;
642
+ }
643
+ }
644
+ async function getBridgeState() {
645
+ const age = await heartbeatAgeMs();
646
+ if (age !== void 0) return { state: age < HEARTBEAT_FRESH_MS ? "connected" : "stale", heartbeatAgeMs: age };
647
+ const resource = getReaperResourcePath();
648
+ if (await exists(join3(resource, "Scripts", "mcp_bridge.lua"))) return { state: "never_started" };
649
+ if (await exists(join3(resource, "reaper.ini"))) return { state: "not_installed" };
650
+ return { state: "no_reaper" };
651
+ }
652
+ var START_BRIDGE = `Start the bridge: in REAPER, open Actions \u2192 Show action list, select "Script: mcp_bridge.lua" and click Run (the first time, use Load ReaScript\u2026 and pick mcp_bridge.lua from REAPER's Scripts folder). It runs until REAPER closes.`;
653
+ function formatAge(ms) {
654
+ const s = Math.round(ms / 1e3);
655
+ if (s < 120) return `${s} s`;
656
+ const min = Math.round(s / 60);
657
+ if (min < 120) return `${min} min`;
658
+ return `${Math.round(min / 60)} h`;
659
+ }
660
+ function bridgeDownMessage(status, resourcePath = getReaperResourcePath()) {
661
+ switch (status.state) {
662
+ case "connected":
663
+ return "The REAPER bridge is running.";
664
+ case "stale":
665
+ return `${BRIDGE_NOT_RUNNING_PREFIX} REAPER has not answered for ${formatAge(status.heartbeatAgeMs ?? 0)}. If REAPER is open and rendering or showing a dialog, finish or close it and try again: running mcp_bridge.lua while the bridge is only busy stops it. If REAPER is closed, start it and try again. If REAPER is open and idle, the bridge stopped. ${START_BRIDGE} Then try again.`;
666
+ case "never_started":
667
+ return `${BRIDGE_NOT_RUNNING_PREFIX} the bridge script is installed but has never run in this REAPER. ${START_BRIDGE} Then try again.`;
668
+ case "not_installed":
669
+ return `${BRIDGE_NOT_RUNNING_PREFIX} the bridge script is not installed in REAPER (no Scripts/mcp_bridge.lua in ${resourcePath}). Run in a terminal: reaper-mcp setup. ${START_BRIDGE}`;
670
+ case "no_reaper":
671
+ return `${BRIDGE_NOT_RUNNING_PREFIX} no REAPER settings in ${resourcePath}: REAPER is not installed there or has never been started. Start REAPER once (or set REAPER_RESOURCE_PATH to the folder REAPER shows under Options \u2192 Show REAPER resource path in explorer/finder), then run in a terminal: reaper-mcp setup. ${START_BRIDGE}`;
672
+ }
673
+ }
674
+ var inFlight = 0;
675
+ var lastAnswerAt = 0;
676
+ async function bridgeDown() {
677
+ if (inFlight > 0) return void 0;
678
+ if (Date.now() - lastAnswerAt < BRIDGE_DOWN_AFTER_MS) return void 0;
679
+ const status = await getBridgeState();
680
+ if (status.state === "connected") return void 0;
681
+ if (status.state === "stale" && (status.heartbeatAgeMs ?? 0) < BRIDGE_DOWN_AFTER_MS) return void 0;
682
+ if (status.state === "stale" && await otherCommandPending()) return void 0;
683
+ return status;
684
+ }
685
+ var PENDING_COMMAND_MAX_AGE_MS = 15 * 6e4;
686
+ async function otherCommandPending() {
687
+ const dir = getBridgeDir();
688
+ try {
689
+ for (const file of await readdir(dir)) {
690
+ if (!file.startsWith("command_") || !file.endsWith(".json")) continue;
691
+ const info = await stat(join3(dir, file)).catch(() => null);
692
+ if (info && Date.now() - info.mtimeMs < PENDING_COMMAND_MAX_AGE_MS) return true;
693
+ }
694
+ } catch {
695
+ }
696
+ return false;
619
697
  }
620
698
  var NOOP_TRACER = new ProxyTracerProvider().getTracer("noop");
621
699
  var UNTRACED_COMMANDS = /* @__PURE__ */ new Set(["_bridge_diagnostics", "_session", "_log_result"]);
@@ -649,8 +727,26 @@ async function sendCommand(type, params = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
649
727
  span.end();
650
728
  if (!untraced) getCommandDurationHistogram().record((Date.now() - startMs) / 1e3, attrs);
651
729
  };
730
+ let counted = false;
652
731
  try {
653
732
  if (profiling) t["spanSetup"] = now() - t0;
733
+ const down = await bridgeDown();
734
+ if (down) {
735
+ span.setAttribute("reaper.bridge.state", down.state);
736
+ const message = bridgeDownMessage(down);
737
+ if (!untraced) {
738
+ emitLog(
739
+ "warn",
740
+ `Bridge command ${type} not sent: the bridge is not running (${down.state})`,
741
+ { "rpc.method": type, "error.type": "bridge_not_running", "reaper.bridge.state": down.state },
742
+ { eventName: "reaper.bridge.command.not_sent" }
743
+ );
744
+ }
745
+ finish("bridge_not_running");
746
+ return { id: randomUUID2(), success: false, error: message, timestamp: Date.now() };
747
+ }
748
+ inFlight++;
749
+ counted = true;
654
750
  const tDir = now();
655
751
  const dir = await ensureBridgeDir();
656
752
  if (profiling) t["ensureDir"] = now() - tDir;
@@ -683,6 +779,7 @@ async function sendCommand(type, params = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
683
779
  const tRead = now();
684
780
  const data = await readFile(responsePath, "utf-8");
685
781
  const response = JSON.parse(data);
782
+ lastAnswerAt = Date.now();
686
783
  if (profiling) t["readParse"] = now() - tRead;
687
784
  if (profiling) t["pollWait"] = now() - tPoll - (t["readParse"] ?? 0);
688
785
  const tCleanup = now();
@@ -772,19 +869,15 @@ async function sendCommand(type, params = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
772
869
  });
773
870
  finish(errorType);
774
871
  throw err;
872
+ } finally {
873
+ if (counted) inFlight--;
775
874
  }
776
875
  }
777
876
  );
778
877
  }
779
878
  async function isBridgeRunning() {
780
- const dir = getBridgeDir();
781
- const heartbeatPath = join3(dir, "heartbeat.json");
782
- try {
783
- const info = await stat(heartbeatPath);
784
- return Date.now() - info.mtimeMs < 5e3;
785
- } catch {
786
- return false;
787
- }
879
+ const age = await heartbeatAgeMs();
880
+ return age !== void 0 && age < HEARTBEAT_FRESH_MS;
788
881
  }
789
882
  async function cleanupStaleFiles(maxAgeMs = 3e4) {
790
883
  const dir = getBridgeDir();
@@ -4498,7 +4591,7 @@ async function checkPython(pythonBin) {
4498
4591
  } catch {
4499
4592
  const notFound = `Python interpreter not found: ${pythonBin}
4500
4593
  Install Python 3.10+ from https://python.org or set the PYTHON_BIN environment variable.
4501
- Example: PYTHON_BIN=/usr/local/bin/python3.11 node dist/apps/reaper-mcp-server/main.js setup-sidecar`;
4594
+ Example: PYTHON_BIN=/usr/local/bin/python3.11 reaper-mcp setup-sidecar`;
4502
4595
  throw new Error(notFound);
4503
4596
  }
4504
4597
  const version = parsePythonVersion(stdout);
@@ -4855,6 +4948,10 @@ Removed partial venv so the next setup-sidecar run starts clean.`);
4855
4948
  }
4856
4949
  }
4857
4950
 
4951
+ // apps/reaper-mcp-server/src/sidecar-hint.ts
4952
+ var SETUP_SIDECAR_COMMAND = "reaper-mcp setup-sidecar";
4953
+ var SETUP_SIDECAR_HINT = `Run in a terminal: ${SETUP_SIDECAR_COMMAND}`;
4954
+
4858
4955
  // apps/reaper-mcp-server/src/sidecar.ts
4859
4956
  var VENV_BIN2 = platform3() === "win32" ? "Scripts" : "bin";
4860
4957
  var VENV_PYTHON_NAME2 = platform3() === "win32" ? "python.exe" : "python";
@@ -4989,7 +5086,7 @@ var SidecarClientImpl = class {
4989
5086
  async send(method, params, timeoutMs) {
4990
5087
  if (!this.isAvailable()) {
4991
5088
  throw new Error(
4992
- "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar"
5089
+ `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`
4993
5090
  );
4994
5091
  }
4995
5092
  await this.ensureRunning();
@@ -5145,13 +5242,13 @@ var SidecarClientImpl = class {
5145
5242
  }
5146
5243
  }).catch((err) => {
5147
5244
  for (const [id, { reject }] of this.pending.entries()) {
5148
- reject(new Error(`Sidecar restart failed: ${err.message}. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar`));
5245
+ reject(new Error(`Sidecar restart failed: ${err.message}. ${SETUP_SIDECAR_HINT}`));
5149
5246
  this.pending.delete(id);
5150
5247
  }
5151
5248
  });
5152
5249
  } else {
5153
5250
  for (const [id, { reject }] of this.pending.entries()) {
5154
- reject(new Error("Python sidecar unavailable after restart attempt. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar"));
5251
+ reject(new Error(`Python sidecar unavailable after restart attempt. ${SETUP_SIDECAR_HINT}`));
5155
5252
  this.pending.delete(id);
5156
5253
  }
5157
5254
  }
@@ -5299,11 +5396,11 @@ function stemsSummary(name, data) {
5299
5396
  // apps/reaper-mcp-server/src/tools/aesthetics.ts
5300
5397
  var DEFAULT_SCORING_LUFS = -18;
5301
5398
  var DEFAULT_CLIP_SECONDS = 30;
5302
- var SIDECAR_NOT_INSTALLED_MSG = "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar";
5399
+ var SIDECAR_NOT_INSTALLED_MSG = `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`;
5303
5400
  function registerAestheticsTools(server) {
5304
5401
  server.tool(
5305
5402
  "analyze_track_aesthetics",
5306
- "Analyze the perceptual aesthetic quality of a track's audio using Meta's Audiobox Aesthetics model (CC-BY 4.0). Bounces the track to a temp WAV file (post-FX, post-fader) and runs 4-axis perceptual quality scoring: Production Quality (PQ), Production Complexity (PC), Content Enjoyment (CE), Content Usefulness (CU). Returns scores 0-10. The clip is normalized to normalizeLufs (default -18 LUFS) before scoring, so level differences between versions do not bias the scores (CE rises with level; PQ barely moves). PQ (and partly CU) judge mix changes; PC and CE mostly follow the arrangement, so only compare the same time range. Measured noise: re-rendering the same 30 s clip moves PQ by ~0.05, a 10 s clip by ~0.4; treat smaller differences as no change. Requires the Python sidecar (run: node dist/apps/reaper-mcp-server/main.js setup-sidecar).",
5403
+ "Analyze the perceptual aesthetic quality of a track's audio using Meta's Audiobox Aesthetics model (CC-BY 4.0). Bounces the track to a temp WAV file (post-FX, post-fader) and runs 4-axis perceptual quality scoring: Production Quality (PQ), Production Complexity (PC), Content Enjoyment (CE), Content Usefulness (CU). Returns scores 0-10. The clip is normalized to normalizeLufs (default -18 LUFS) before scoring, so level differences between versions do not bias the scores (CE rises with level; PQ barely moves). PQ (and partly CU) judge mix changes; PC and CE mostly follow the arrangement, so only compare the same time range. Measured noise: re-rendering the same 30 s clip moves PQ by ~0.05, a 10 s clip by ~0.4; treat smaller differences as no change. Requires the Python sidecar (run in a terminal: reaper-mcp setup-sidecar).",
5307
5404
  {
5308
5405
  trackIndex: z26.coerce.number().int().min(-1).describe("Zero-based track index (-1 = master: the whole mix)"),
5309
5406
  startTime: z26.coerce.number().min(0).optional().describe("Start time in seconds (default: 0 or use REAPER time selection)"),
@@ -5385,7 +5482,7 @@ function registerAestheticsTools(server) {
5385
5482
  // apps/reaper-mcp-server/src/tools/offline.ts
5386
5483
  import { z as z27 } from "zod/v4";
5387
5484
  import { basename } from "node:path";
5388
- var SIDECAR_NOT_INSTALLED_MSG2 = "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar";
5485
+ var SIDECAR_NOT_INSTALLED_MSG2 = `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`;
5389
5486
  var MAX_OFFLINE_SECONDS = 900;
5390
5487
  var DEFAULT_OFFLINE_SECONDS = 30;
5391
5488
  var DEFAULT_ALIGNMENT_SECONDS = 10;
@@ -5631,7 +5728,7 @@ function registerOfflineTools(server) {
5631
5728
  // apps/reaper-mcp-server/src/tools/transients.ts
5632
5729
  import { z as z28 } from "zod/v4";
5633
5730
  import { randomUUID as randomUUID5 } from "node:crypto";
5634
- var SIDECAR_NOT_INSTALLED_MSG3 = "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar";
5731
+ var SIDECAR_NOT_INSTALLED_MSG3 = `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`;
5635
5732
  var DEFAULT_TRACK_SECONDS = 60;
5636
5733
  var DEFAULT_LIMIT = 200;
5637
5734
  var MAX_AUTOMATION_POINTS = 2e4;
@@ -5927,7 +6024,7 @@ import { z as z29 } from "zod/v4";
5927
6024
  import { homedir as homedir6 } from "node:os";
5928
6025
  import { basename as basename2, extname, join as join7 } from "node:path";
5929
6026
  import { trace as trace4 } from "@opentelemetry/api";
5930
- var SIDECAR_NOT_INSTALLED_MSG4 = "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar";
6027
+ var SIDECAR_NOT_INSTALLED_MSG4 = `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`;
5931
6028
  var DEFAULT_TRACK_SECONDS2 = 180;
5932
6029
  var SEPARATION_TRACK_SECONDS = 60;
5933
6030
  var MAX_MASKING_SECONDS = 60;
@@ -6205,7 +6302,7 @@ function registerMixcheckTools(server) {
6205
6302
  // apps/reaper-mcp-server/src/tools/mixing.ts
6206
6303
  import { z as z30 } from "zod/v4";
6207
6304
  import { trace as trace5 } from "@opentelemetry/api";
6208
- var SIDECAR_NOT_INSTALLED_MSG5 = "Audio understanding sidecar not installed. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar";
6305
+ var SIDECAR_NOT_INSTALLED_MSG5 = `Audio understanding sidecar not installed. ${SETUP_SIDECAR_HINT}`;
6209
6306
  var MAX_QUANTIZE_SECONDS = 900;
6210
6307
  var error4 = (text7) => ({ content: [{ type: "text", text: `Error: ${text7}` }], isError: true });
6211
6308
  var ok = (data) => ({ content: [{ type: "text", text: JSON.stringify(data, null, 2) }] });
@@ -7422,7 +7519,7 @@ function registerCompositionTools(server) {
7422
7519
  } else {
7423
7520
  const sidecar = getSidecarClient();
7424
7521
  if (!sidecar.isAvailable()) {
7425
- return fail4("Audio key detection needs the Python sidecar. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar");
7522
+ return fail4(`Audio key detection needs the Python sidecar. ${SETUP_SIDECAR_HINT}`);
7426
7523
  }
7427
7524
  if (path != null) {
7428
7525
  const c = await sidecar.chroma({ path, ...start > 0 ? { startTime: start } : {}, ...args.endTime != null ? { endTime: args.endTime } : {} });
@@ -7519,7 +7616,7 @@ function registerCompositionTools(server) {
7519
7616
  let engine = "template";
7520
7617
  let modelMissing = false;
7521
7618
  const sidecar = getSidecarClient();
7522
- const needSidecar = () => fail4("Audio chord detection needs the Python sidecar. Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar");
7619
+ const needSidecar = () => fail4(`Audio chord detection needs the Python sidecar. ${SETUP_SIDECAR_HINT}`);
7523
7620
  const useModel = async () => {
7524
7621
  if (engineArg === "template") return false;
7525
7622
  const status = await Promise.resolve().then(() => sidecar.chordsStatus()).catch(() => ({ installed: false, message: "The chord model is not installed. Run: reaper-mcp setup-sidecar --with-chords" }));
@@ -9228,24 +9325,27 @@ async function serve() {
9228
9325
  startupSpan.setAttribute("reaper.bridge.stale_files_cleaned", cleaned);
9229
9326
  log(`Cleaned up ${cleaned} stale bridge files`);
9230
9327
  }
9231
- const bridgeRunning = await tracer.startActiveSpan("check bridge connection", { kind: SpanKind5.INTERNAL }, async (bridgeSpan) => {
9232
- const running = await isBridgeRunning();
9328
+ const bridge = await tracer.startActiveSpan("check bridge connection", { kind: SpanKind5.INTERNAL }, async (bridgeSpan) => {
9329
+ const status = await getBridgeState();
9330
+ const running = status.state === "connected";
9233
9331
  bridgeSpan.setAttribute("reaper.bridge.connected", running);
9332
+ bridgeSpan.setAttribute("reaper.bridge.state", status.state);
9234
9333
  if (!running) {
9235
- emitLog("warn", "Lua bridge not detected at startup \u2014 commands will time out until it is started", {
9236
- "reaper.bridge.connected": false
9334
+ emitLog("warn", "Lua bridge not detected at startup \u2014 commands are refused until it is started", {
9335
+ "reaper.bridge.connected": false,
9336
+ "reaper.bridge.state": status.state
9237
9337
  });
9238
- log("WARNING: Lua bridge does not appear to be running in REAPER.");
9239
- log("Commands will timeout until the bridge script is started.");
9240
- log('Run "reaper-mcp setup" for installation instructions.');
9338
+ log(`WARNING: Lua bridge does not appear to be running in REAPER (${status.state}).`);
9339
+ log(bridgeDownMessage(status));
9241
9340
  } else {
9242
9341
  bridgeSpan.setStatus({ code: SpanStatusCode4.OK });
9243
9342
  log("Lua bridge detected \u2014 connected to REAPER");
9244
9343
  }
9245
9344
  bridgeSpan.end();
9246
- return running;
9345
+ return status;
9247
9346
  });
9248
- startupSpan.setAttribute("reaper.bridge.connected", bridgeRunning);
9347
+ startupSpan.setAttribute("reaper.bridge.connected", bridge.state === "connected");
9348
+ startupSpan.setAttribute("reaper.bridge.state", bridge.state);
9249
9349
  const server = createServer();
9250
9350
  for (const ext of await loadExtensions(server)) {
9251
9351
  if (ext.status === "loaded") log(`Extension ${ext.name} ${ext.version ?? ""} loaded (${ext.tools.length} tools)`);
@@ -9316,8 +9416,10 @@ switch (command) {
9316
9416
  break;
9317
9417
  case "status": {
9318
9418
  (async () => {
9319
- const running = await isBridgeRunning();
9320
- console.log(`Bridge status: ${running ? "CONNECTED" : "NOT DETECTED"}`);
9419
+ const status = await getBridgeState();
9420
+ const running = status.state === "connected";
9421
+ console.log(`Bridge status: ${running ? "CONNECTED" : `NOT DETECTED (${status.state})`}`);
9422
+ if (!running) console.log(bridgeDownMessage(status));
9321
9423
  process.exit(running ? 0 : 1);
9322
9424
  })();
9323
9425
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mthines/reaper-mcp",
3
- "version": "0.70.3",
3
+ "version": "0.71.0-beta.80.1",
4
4
  "type": "module",
5
5
  "description": "MCP server for controlling REAPER DAW — real-time mixing, FX control, and frequency analysis for AI agents",
6
6
  "license": "MIT",
package/sidecar/server.py CHANGED
@@ -56,7 +56,7 @@ def _ensure_predictor() -> None:
56
56
  except ImportError as exc:
57
57
  _predictor_error = (
58
58
  f"audiobox-aesthetics not installed: {exc}. "
59
- f"Run: node dist/apps/reaper-mcp-server/main.js setup-sidecar"
59
+ "Run in a terminal: reaper-mcp setup-sidecar"
60
60
  )
61
61
  except Exception as exc: # noqa: BLE001
62
62
  _predictor_error = f"Failed to initialize predictor: {exc}"