@mthines/reaper-mcp 0.83.0-beta.117.1 → 0.83.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mthines/reaper-mcp",
3
- "version": "0.83.0-beta.117.1",
3
+ "version": "0.83.0",
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
@@ -90,7 +90,7 @@ def _get_audio_duration(path: str) -> float:
90
90
  info = torchaudio.info(path)
91
91
  return info.num_frames / info.sample_rate
92
92
  except Exception as exc:
93
- raise RuntimeError(f"Cannot read audio file: {path}: {exc}") from exc
93
+ raise RuntimeError(f"Audio file unreadable: {path}: {exc}") from exc
94
94
 
95
95
 
96
96
  # ---------------------------------------------------------------------------
@@ -189,13 +189,22 @@ def handle_analyze(request_id: Any, params: dict) -> str:
189
189
  return _err(request_id, -32000, f"Inference failed: {exc}")
190
190
 
191
191
 
192
- def _check_file(request_id: Any, params: dict, key: str) -> str | None:
193
- """Return an error response when params[key] is missing or not a file."""
192
+ def _check_file(request_id: Any, params: dict, key: str, readable: bool = True) -> str | None:
193
+ """Return an error response when params[key] is missing, not a file, or (readable) not audio soundfile opens."""
194
194
  path = params.get(key)
195
195
  if not path:
196
196
  return _err(request_id, -32602, f"Missing required param: {key}")
197
197
  if not os.path.exists(path):
198
198
  return _err(request_id, -32000, f"Audio file not found: {path}")
199
+ if not readable:
200
+ return None
201
+ import soundfile as sf # type: ignore
202
+ try:
203
+ sf.info(path)
204
+ except RuntimeError as exc:
205
+ # The handler reads through soundfile (analysis.load_audio), so this file would fail there too, as a
206
+ # crash-looking "… failed: Error opening …"; say it is the input (an .m4a, a text file) instead.
207
+ return _err(request_id, -32000, f"Audio file unreadable: {path}: {exc}")
199
208
  return None
200
209
 
201
210
 
@@ -456,7 +465,13 @@ def handle_chords(request_id: Any, params: dict) -> str:
456
465
  """
457
466
  import chords
458
467
 
459
- error = _check_file(request_id, params, "path")
468
+ # The chord model loads a whole file itself (librosa, so an .m4a works); a cut range is read through soundfile
469
+ # (the same test as chords.recognize). A startTime that is not a number is refused below, after the file check.
470
+ try:
471
+ ranged = float(params.get("startTime", 0)) > 0 or params.get("endTime") is not None
472
+ except (TypeError, ValueError):
473
+ ranged = True
474
+ error = _check_file(request_id, params, "path", readable=ranged)
460
475
  if error:
461
476
  return error
462
477
  try:
@@ -83,6 +83,35 @@ def test_a_range_is_cut_out_and_its_times_stay_in_file_seconds(wav, fake_model):
83
83
  assert result["vocabulary"] == "ismir2017"
84
84
 
85
85
 
86
+ def test_a_whole_file_soundfile_cannot_open_still_reaches_the_model(tmp_path, monkeypatch):
87
+ # The model loads the file itself, so a format soundfile does not read (an .m4a) is not refused up front.
88
+ song = tmp_path / "song.m4a"
89
+ song.write_bytes(b"not a format soundfile reads")
90
+ seen = []
91
+ monkeypatch.setattr(chords, "is_installed", lambda: True)
92
+ monkeypatch.setattr(chords, "_recognize",
93
+ lambda source, vocabulary: seen.append(source) or [{"start_time": 0, "end_time": 2, "chord": "A:min"}])
94
+
95
+ result = call("chords", path=str(song))["result"]
96
+
97
+ assert seen == [str(song)]
98
+ assert result["segments"] == [{"start": 0.0, "end": 2.0, "label": "A:min"}]
99
+
100
+
101
+ # detect_chords sends startTime only when it is above 0, so a range from the start arrives with endTime alone.
102
+ @pytest.mark.parametrize("bounds", [{"startTime": 1, "endTime": 3}, {"endTime": 3}], ids=["start-and-end", "end-only"])
103
+ def test_a_range_of_a_file_soundfile_cannot_open_is_refused_as_unreadable_input(tmp_path, fake_model, bounds):
104
+ # A range is cut out with soundfile, so the file has to open there: say it is the input, not a failure.
105
+ song = tmp_path / "song.m4a"
106
+ song.write_bytes(b"not a format soundfile reads")
107
+
108
+ error = call("chords", path=str(song), **bounds)["error"]
109
+
110
+ assert error["code"] == -32000
111
+ assert error["message"].startswith(f"Audio file unreadable: {song}")
112
+ assert fake_model == []
113
+
114
+
86
115
  def test_refuses_an_unknown_vocabulary_and_a_missing_file(wav, fake_model):
87
116
  assert call("chords", path=wav, vocabulary="jazz")["error"]["code"] == -32602
88
117
  assert "not found" in call("chords", path="/nope/missing.wav")["error"]["message"]
@@ -149,6 +149,19 @@ def test_audio_file_not_found():
149
149
  assert "not found" in resp["error"]["message"].lower()
150
150
 
151
151
 
152
+ def test_a_file_that_is_not_audio_is_refused_as_unreadable_input(tmp_path):
153
+ # The phrase is what sidecar.ts classifies as rejected input (sidecar_rejected), not a sidecar fault.
154
+ notes = tmp_path / "reference.m4a"
155
+ notes.write_text("not audio soundfile can open")
156
+
157
+ for method in ("analyze_audio", "analyze"):
158
+ error = parse_response(server.dispatch(json.dumps({
159
+ "jsonrpc": "2.0", "id": 9, "method": method, "params": {"path": str(notes)},
160
+ })))["error"]
161
+ assert error["code"] == -32000
162
+ assert error["message"].startswith(f"Audio file unreadable: {notes}")
163
+
164
+
152
165
  # ---------------------------------------------------------------------------
153
166
  # Test 4: Audio too short (<0.5s) → JSON-RPC error with duration in message
154
167
  # ---------------------------------------------------------------------------
@@ -213,7 +213,7 @@ def test_failed_soundfont_load_removes_only_the_new_output_folder(tmp_path):
213
213
  sentinel = tmp_path / "keep.txt"
214
214
  sentinel.write_text("user data")
215
215
  for _ in range(2):
216
- with pytest.raises(RuntimeError, match="SoundFont|soundfontPath"):
216
+ with pytest.raises(ValueError, match="SoundFont|soundfontPath"):
217
217
  render(params)
218
218
  assert not (tmp_path / "render").exists()
219
219
  assert sentinel.read_text() == "user data"
@@ -154,13 +154,15 @@ def _synth(lib: Any, font: Path, track: dict[str, Any]) -> Iterator[Any]:
154
154
  synth = lib.new_fluid_synth(settings)
155
155
  if not synth:
156
156
  raise RuntimeError("FluidSynth could not allocate an offline synthesizer")
157
+ # The SoundFont is the caller's file: one FluidSynth cannot use is bad input (ValueError, answered -32602
158
+ # and reported as rejected), not a sidecar fault like the allocation failures above.
157
159
  font_id = lib.fluid_synth_sfload(synth, os.fsencode(font), 1)
158
160
  if font_id < 0:
159
- raise RuntimeError("FluidSynth could not load soundfontPath as a SoundFont")
161
+ raise ValueError("FluidSynth could not load soundfontPath as a SoundFont")
160
162
  channel, program = int(track["channel"]), int(track["program"])
161
163
  bank = 128 if channel == 9 else 0
162
164
  if lib.fluid_synth_program_select(synth, channel, font_id, bank, program) != 0:
163
- raise RuntimeError(f"SoundFont has no bank {bank} program {program} for track '{track['name']}'")
165
+ raise ValueError(f"SoundFont has no bank {bank} program {program} for track '{track['name']}'")
164
166
  # No audio or MIDI driver is created. Samples only leave through write_float.
165
167
  yield synth
166
168
  finally: