deep-roon-mcp 0.5.8 → 0.5.10

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/README.md CHANGED
@@ -22,7 +22,7 @@ server of its own and sends nothing anywhere else. What you ask goes to your MCP
22
22
 
23
23
  ## Status
24
24
 
25
- Version 0.5: sixty-one tools (fifty-five with a read-only library; sixty-five with playlist editing on). Qobuz, TIDAL or both — whatever is signed in on your Core.
25
+ Version 0.5: sixty-four tools (fifty-eight with a read-only library; sixty-eight with playlist editing on). Qobuz, TIDAL or both — whatever is signed in on your Core.
26
26
 
27
27
  **Reading** — changes nothing in Roon:
28
28
 
@@ -61,6 +61,7 @@ Version 0.5: sixty-one tools (fifty-five with a read-only library; sixty-five wi
61
61
  | `roon_similar` | More like this, for an album or an artist |
62
62
  | `roon_signal_path` | Roon's signal path for what plays: is it bit-perfect, what happens on the way |
63
63
  | `roon_dsp` | MUSE: the DSP set up for a zone |
64
+ | `roon_devices` | The RAAT audio devices of Settings › Audio: enabled, and whether they have a zone |
64
65
  | `roon_radio` | Live Radio: your own stations, the directory by category and genre |
65
66
 
66
67
  **Playing** — only on your request:
@@ -79,6 +80,7 @@ Version 0.5: sixty-one tools (fifty-five with a read-only library; sixty-five wi
79
80
  | `roon_group`, `roon_ungroup` | Group zones, and undo it |
80
81
  | `roon_sleep` | A sleep timer |
81
82
  | `roon_standby` | Put a device in standby, or wake it |
83
+ | `roon_device_reset` | Disable and enable a device stuck on "Enabling…" (enabled, no zone) — only those |
82
84
  | `roon_play_playlist` | A playlist on a zone (also a TIDAL one), optionally shuffled |
83
85
  | `roon_play_mix` | One of today's Daily Mixes |
84
86
  | `roon_play_radio` | A Live Radio station on a zone |
@@ -183,7 +185,7 @@ ChatGPT on the web can't run a server on your computer — use the desktop app.
183
185
  The same settings as environment variables: `ROON_HOST` (the Core's address, empty = find it), `ROON_PROFILE` (a Roon profile
184
186
  by name, empty = the first; see below), `DEEP_ROON_TOOLS=essentials`,
185
187
  `DEEP_ROON_INTERNAL=off`, `DEEP_ROON_READ_ONLY=library` (nothing changes the library; playing works) or `DEEP_ROON_READ_ONLY=all`
186
- (Deep Roon only looks: no playing, queueing or zone changes either), `DEEP_ROON_PLAYLIST_EDIT=1` (the playlist edits). Leave out what you don't need. VS Code calls the block `"servers"` instead of `"mcpServers"`.
188
+ (Deep Roon only looks: no playing, queueing or zone changes either; any other value except `off` means `library`), `DEEP_ROON_PLAYLIST_EDIT=1` (the playlist edits). Leave out what you don't need. VS Code calls the block `"servers"` instead of `"mcpServers"`.
187
189
 
188
190
  Then, once, in Roon: Settings › Extensions › **Enable** next to "Deep Roon MCP". Until then the tools say so.
189
191
 
@@ -203,7 +205,8 @@ DEEP_ROON_HTTP=127.0.0.1:9301 npx -y deep-roon-mcp
203
205
 
204
206
  `DEEP_ROON_HTTP` is `[host:]port`; the host defaults to `127.0.0.1`. There is **no authentication**: keep it on your own
205
207
  computer, or put it behind something that has one (a reverse proxy with a key, a private tunnel). Never expose it to
206
- the internet as it is.
208
+ the internet as it is. Browsers can't use it: a request that carries an `Origin` header is refused, and on a loopback
209
+ address only a loopback `Host` is accepted (so a web page can't reach it through DNS rebinding). Bodies over 4 MB are refused.
207
210
 
208
211
  ### From source
209
212
 
@@ -7813,7 +7813,11 @@ var init_connection = __esm({
7813
7813
  let pending = Buffer.alloc(0);
7814
7814
  socket.on("data", (data) => {
7815
7815
  if (this.established) {
7816
- this.dataHandler(data);
7816
+ try {
7817
+ this.dataHandler(data);
7818
+ } catch (e) {
7819
+ socket.destroy(e);
7820
+ }
7817
7821
  return;
7818
7822
  }
7819
7823
  pending = pending.length === 0 ? data : Buffer.concat([pending, data]);
@@ -7949,13 +7953,14 @@ function encodeResponse(rid, body, isFinal = true) {
7949
7953
  writeFlexInt(out, body.length);
7950
7954
  return Buffer.concat([Buffer.from(out), Buffer.from(body)]);
7951
7955
  }
7952
- var FrameParser;
7956
+ var MAX_FRAME, FrameParser;
7953
7957
  var init_frame = __esm({
7954
7958
  "src/intern/proto/frame.ts"() {
7955
7959
  "use strict";
7956
7960
  init_flex();
7957
7961
  __name(encodeRequest, "encodeRequest");
7958
7962
  __name(encodeResponse, "encodeResponse");
7963
+ MAX_FRAME = 64 * 1024 * 1024;
7959
7964
  FrameParser = class {
7960
7965
  static {
7961
7966
  __name(this, "FrameParser");
@@ -8006,6 +8011,7 @@ var init_frame = __esm({
8006
8011
  const lenR = flex(pos);
8007
8012
  if (!lenR) return null;
8008
8013
  const [bodyLen, bodyStart] = lenR;
8014
+ if (bodyLen > MAX_FRAME) throw new RangeError(`malformed frame: body of ${bodyLen} bytes`);
8009
8015
  if (u.length < bodyStart + bodyLen) return null;
8010
8016
  const frame = {
8011
8017
  isResponse,
@@ -8337,9 +8343,16 @@ var init_reader = __esm({
8337
8343
  get remaining() {
8338
8344
  return this.buf.length - this.pos;
8339
8345
  }
8346
+ /** Never past the end, never backwards (15 Nov 2026): lengths and counts come from the wire. A negative length moved
8347
+ * the cursor back (a loop that never ends), and reads past the end returned zeros (billions of empty members) — all
8348
+ * inside the socket's data handler. Now a malformed frame throws, and the connection closes and reconnects. */
8349
+ need(n) {
8350
+ if (!Number.isInteger(n) || n < 0 || this.pos + n > this.buf.length) throw new RangeError(`malformed frame: ${n} bytes at ${this.pos} of ${this.buf.length}`);
8351
+ }
8340
8352
  flexInt() {
8341
8353
  let num = 0;
8342
8354
  for (; ; ) {
8355
+ this.need(1);
8343
8356
  const b = this.buf[this.pos++];
8344
8357
  num = num << 7 | b & 127;
8345
8358
  if ((b & 128) === 0) break;
@@ -8354,6 +8367,7 @@ var init_reader = __esm({
8354
8367
  flexLong() {
8355
8368
  let num = 0n;
8356
8369
  for (; ; ) {
8370
+ this.need(1);
8357
8371
  const b = this.buf[this.pos++];
8358
8372
  num = num << 7n | BigInt(b & 127);
8359
8373
  if ((b & 128) === 0) break;
@@ -8364,9 +8378,11 @@ var init_reader = __esm({
8364
8378
  return this.flexLong();
8365
8379
  }
8366
8380
  boolean() {
8381
+ this.need(1);
8367
8382
  return this.buf[this.pos++] !== 0;
8368
8383
  }
8369
8384
  bytes(n) {
8385
+ this.need(n);
8370
8386
  const b = Buffer.from(this.buf.subarray(this.pos, this.pos + n));
8371
8387
  this.pos += n;
8372
8388
  return b;
@@ -8375,11 +8391,13 @@ var init_reader = __esm({
8375
8391
  return this.bytes(16);
8376
8392
  }
8377
8393
  double() {
8394
+ this.need(8);
8378
8395
  const v = Buffer.from(this.buf.subarray(this.pos, this.pos + 8)).readDoubleLE(0);
8379
8396
  this.pos += 8;
8380
8397
  return v;
8381
8398
  }
8382
8399
  float() {
8400
+ this.need(4);
8383
8401
  const v = Buffer.from(this.buf.subarray(this.pos, this.pos + 4)).readFloatLE(0);
8384
8402
  this.pos += 4;
8385
8403
  return v;
@@ -8399,6 +8417,7 @@ var init_reader = __esm({
8399
8417
  string() {
8400
8418
  const len = this.integer();
8401
8419
  if (len < 0) return null;
8420
+ this.need(len);
8402
8421
  const s = Buffer.from(this.buf.subarray(this.pos, this.pos + len)).toString("utf8");
8403
8422
  this.pos += len;
8404
8423
  return s;
@@ -8493,6 +8512,7 @@ var init_objects = __esm({
8493
8512
  const id = r.flexInt();
8494
8513
  const name = r.string() ?? "";
8495
8514
  const count = r.flexInt();
8515
+ if (count > r.remaining / 2) throw new RangeError(`malformed frame: type ${name} claims ${count} members, ${r.remaining} bytes left`);
8496
8516
  const members2 = [];
8497
8517
  for (let i = 0; i < count; i++) {
8498
8518
  const mname = r.string() ?? "";
@@ -15469,7 +15489,7 @@ var require_lib2 = __commonJS({
15469
15489
  var version2;
15470
15490
  var init_package = __esm({
15471
15491
  "package.json"() {
15472
- version2 = "0.5.8";
15492
+ version2 = "0.5.10";
15473
15493
  }
15474
15494
  });
15475
15495
 
@@ -15487,6 +15507,25 @@ var init_log = __esm({
15487
15507
  }
15488
15508
  });
15489
15509
 
15510
+ // src/core/namematch.ts
15511
+ function pickByName(items2, name, nameOf, what = "Roon zone") {
15512
+ const want = String(name ?? "").trim().toLowerCase();
15513
+ if (!want) throw new RoonError(`Name a ${what}; Roon has: ${items2.map(nameOf).join(", ")}`, "invalid");
15514
+ const lc = /* @__PURE__ */ __name((x) => nameOf(x).toLowerCase(), "lc");
15515
+ const exact = items2.find((x) => lc(x) === want) ?? items2.find((x) => lc(x).split(" + ").includes(want));
15516
+ if (exact) return exact;
15517
+ const part = items2.filter((x) => lc(x).includes(want));
15518
+ if (part.length > 1) throw new RoonError(`"${name}" fits more than one ${what}: ${part.map(nameOf).join(", ")} \u2014 say which`, "invalid");
15519
+ return part[0];
15520
+ }
15521
+ var init_namematch = __esm({
15522
+ "src/core/namematch.ts"() {
15523
+ "use strict";
15524
+ init_errors();
15525
+ __name(pickByName, "pickByName");
15526
+ }
15527
+ });
15528
+
15490
15529
  // src/core/official.ts
15491
15530
  function configDir() {
15492
15531
  if (process.platform === "darwin") return import_path.default.join(import_os.default.homedir(), "Library", "Application Support", "deep-roon-mcp");
@@ -15494,7 +15533,17 @@ function configDir() {
15494
15533
  return import_path.default.join(process.env.XDG_CONFIG_HOME ?? import_path.default.join(import_os.default.homedir(), ".config"), "deep-roon-mcp");
15495
15534
  }
15496
15535
  function startOfficial(target2) {
15497
- if (started) return;
15536
+ if (started) {
15537
+ if (core && (core.host !== target2.host || core.port !== target2.port)) {
15538
+ log(`the Core moved to ${target2.host}:${target2.port} \u2014 following it`);
15539
+ core = target2;
15540
+ if (!transport) {
15541
+ open2 = false;
15542
+ connect();
15543
+ }
15544
+ }
15545
+ return;
15546
+ }
15498
15547
  started = true;
15499
15548
  core = target2;
15500
15549
  roon = new import_node_roon_api.default({
@@ -15621,8 +15670,7 @@ async function officialReady(ms = 4e3) {
15621
15670
  });
15622
15671
  }
15623
15672
  function officialZone(name) {
15624
- const want = name.toLowerCase(), all = officialZones();
15625
- return all.find((z2) => z2.display_name.toLowerCase() === want) ?? all.find((z2) => z2.display_name.toLowerCase().split(" + ").includes(want)) ?? all.find((z2) => z2.display_name.toLowerCase().includes(want));
15673
+ return pickByName(officialZones(), name, (z2) => z2.display_name);
15626
15674
  }
15627
15675
  async function setVolume(name, change) {
15628
15676
  const t = await paired();
@@ -15632,18 +15680,21 @@ async function setVolume(name, change) {
15632
15680
  const outs = z2.outputs.filter((o) => o.volume);
15633
15681
  if (!outs.length) throw new RoonError(`${z2.display_name} has a fixed volume (Roon can't change it)`, "invalid");
15634
15682
  const call2 = /* @__PURE__ */ __name((fn) => new Promise((res, rej) => fn((err) => err ? rej(new RoonError(`Roon refused: ${err}`)) : res())), "call");
15683
+ if (change.value !== void 0) {
15684
+ const buiten = outs.filter((o) => o.volume.type !== "incremental" && (change.value < o.volume.min || change.value > o.volume.max));
15685
+ if (buiten.length) throw new RoonError(`${change.value} is outside the volume scale of ${buiten.map((o) => `${o.display_name} (${o.volume.min}\u2013${o.volume.max})`).join(", ")}`, "invalid");
15686
+ }
15635
15687
  for (const o of outs) {
15636
15688
  if (change.value !== void 0) {
15637
15689
  const v = o.volume;
15638
15690
  if (v.type === "incremental") throw new RoonError(`${o.display_name} only steps its volume up or down (no level)`, "invalid");
15639
- const value = Math.max(v.min, Math.min(v.max, change.value));
15640
- await call2((cb) => t.change_volume(o.output_id, "absolute", value, cb));
15691
+ await call2((cb) => t.change_volume(o.output_id, "absolute", change.value, cb));
15641
15692
  }
15642
15693
  if (change.mute !== void 0) await call2((cb) => t.mute(o.output_id, change.mute ? "mute" : "unmute", cb));
15643
15694
  }
15644
15695
  return { zone: z2.display_name, outputs: outs.map((o) => ({ output: o.display_name, scale: `${o.volume.min}\u2013${o.volume.max}` })), volume: change.value, muted: change.mute };
15645
15696
  }
15646
- var import_fs, import_net, import_os, import_path, import_node_roon_api, import_node_roon_api_transport, STATE_FILE, readState, writeState, transport, zones, started, waiting, zonesIn, zoneWaiting, roon, core, open2, retrying, officialZones, coreWeb, isPaired;
15697
+ var import_fs, import_net, import_os, import_path, import_node_roon_api, import_node_roon_api_transport, STATE_FILE, readState, writeState, transport, zones, started, waiting, zonesIn, zoneWaiting, roon, core, open2, coreReachable, retrying, officialZones, coreWeb, isPaired;
15647
15698
  var init_official = __esm({
15648
15699
  "src/core/official.ts"() {
15649
15700
  "use strict";
@@ -15656,6 +15707,7 @@ var init_official = __esm({
15656
15707
  init_package();
15657
15708
  init_log();
15658
15709
  init_errors();
15710
+ init_namematch();
15659
15711
  __name(configDir, "configDir");
15660
15712
  STATE_FILE = import_path.default.join(configDir(), "pairing.json");
15661
15713
  readState = /* @__PURE__ */ __name(() => {
@@ -15680,6 +15732,7 @@ var init_official = __esm({
15680
15732
  open2 = false;
15681
15733
  __name(startOfficial, "startOfficial");
15682
15734
  __name(connect, "connect");
15735
+ coreReachable = /* @__PURE__ */ __name((ms = 3e3) => reachable(ms), "coreReachable");
15683
15736
  __name(reachable, "reachable");
15684
15737
  retrying = false;
15685
15738
  __name(afterClose, "afterClose");
@@ -15768,7 +15821,12 @@ function close(reason) {
15768
15821
  async function open3() {
15769
15822
  if (client) return client;
15770
15823
  const t = await findTarget();
15771
- await paired();
15824
+ try {
15825
+ await paired();
15826
+ } catch (e) {
15827
+ if (!process.env.ROON_HOST?.trim() && !await coreReachable()) target = null;
15828
+ throw e;
15829
+ }
15772
15830
  const c = new RoonClient({ host: t.host, port: INTERNAL_PORT, serverBrokerId: brokerId(t.info.coreId), settleMs: 1500 });
15773
15831
  c.conn.onclosed = () => {
15774
15832
  try {
@@ -15784,6 +15842,10 @@ async function open3() {
15784
15842
  try {
15785
15843
  await c.connect();
15786
15844
  } catch (e) {
15845
+ try {
15846
+ c.close();
15847
+ } catch {
15848
+ }
15787
15849
  target = null;
15788
15850
  throw new RoonError(`Can't connect to Roon's internal protocol at ${t.host}:${INTERNAL_PORT} (${e.message})`, "unavailable");
15789
15851
  }
@@ -49575,6 +49637,7 @@ init_intern();
49575
49637
  init_session();
49576
49638
  init_official();
49577
49639
  init_graph();
49640
+ init_namematch();
49578
49641
  function currentEndpoints(c) {
49579
49642
  const score = /* @__PURE__ */ __name((e) => {
49580
49643
  const z2 = obj(c, field2(e, "Zone"));
@@ -49608,8 +49671,7 @@ function zoneNames(c) {
49608
49671
  __name(zoneNames, "zoneNames");
49609
49672
  function findZone(c, name) {
49610
49673
  const zones4 = [...zoneNames(c)].map(([oid, n]) => ({ name: n, oid: BigInt(oid) }));
49611
- const want = String(name).toLowerCase();
49612
- const z2 = zones4.find((x) => x.name.toLowerCase() === want) ?? zones4.find((x) => x.name.toLowerCase().split(" + ").includes(want)) ?? zones4.find((x) => x.name.toLowerCase().includes(want));
49674
+ const z2 = pickByName(zones4, name, (x) => x.name);
49613
49675
  if (!z2) throw new RoonError(`No Roon zone called "${name}"; Roon has: ${zones4.map((x) => x.name).join(", ")}`, "not_found");
49614
49676
  return z2;
49615
49677
  }
@@ -49772,6 +49834,7 @@ init_official();
49772
49834
  init_log();
49773
49835
  init_graph();
49774
49836
  init_library();
49837
+ init_namematch();
49775
49838
  var PRIORITY = { now: 0, next: 3, queue: 4 };
49776
49839
  function playParams(c, p, shuffle = false) {
49777
49840
  const members2 = [];
@@ -50116,7 +50179,8 @@ async function ungroup(zoneName, only) {
50116
50179
  const z2 = findZone(c, zoneName);
50117
50180
  const all = outputsOf(c, z2.oid);
50118
50181
  if (all.length < 2) throw new RoonError(`${z2.name} isn't in a group`, "invalid");
50119
- const off = only ? all.filter((e) => String(field2(e, "Name")).toLowerCase().includes(only.toLowerCase())) : all;
50182
+ const een = only ? pickByName(all, only, (e) => String(field2(e, "Name")), "output in this group") : void 0;
50183
+ const off = only ? een ? [een] : [] : all;
50120
50184
  if (!off.length) throw new RoonError(`"${only}" isn't in this group (${all.map((e) => field2(e, "Name")).join(" + ")})`, "not_found");
50121
50185
  const res = await c.call(
50122
50186
  "Transport",
@@ -50348,6 +50412,7 @@ __name(radioFavorite, "radioFavorite");
50348
50412
  // src/core/officialtools.ts
50349
50413
  init_errors();
50350
50414
  init_official();
50415
+ init_namematch();
50351
50416
  var call = /* @__PURE__ */ __name((fn) => new Promise((res, rej) => fn((err) => err ? rej(new RoonError(`Roon refused: ${err}`)) : res())), "call");
50352
50417
  var duration4 = /* @__PURE__ */ __name((s) => {
50353
50418
  const t = Math.round(s), h = Math.floor(t / 3600), m = Math.floor(t % 3600 / 60), r = t % 60;
@@ -50453,7 +50518,8 @@ __name(group2, "group");
50453
50518
  async function ungroup2(name, only) {
50454
50519
  const { t, z: z2 } = await zoneOf(name);
50455
50520
  if (z2.outputs.length < 2) throw new RoonError(`${z2.display_name} isn't in a group`, "invalid");
50456
- const off = only ? z2.outputs.filter((o) => o.display_name.toLowerCase().includes(only.toLowerCase())) : z2.outputs;
50521
+ const een = only ? pickByName(z2.outputs, only, (o) => o.display_name, "output in this group") : void 0;
50522
+ const off = only ? een ? [een] : [] : z2.outputs;
50457
50523
  if (!off.length) throw new RoonError(`"${only}" isn't in this group`, "not_found");
50458
50524
  await call((cb) => t.ungroup_outputs(off.map((o) => o.output_id), cb));
50459
50525
  return { ok: true, released: off.map((o) => o.display_name) };
@@ -51664,6 +51730,63 @@ async function dspSet(zoneName, s) {
51664
51730
  }
51665
51731
  __name(dspSet, "dspSet");
51666
51732
 
51733
+ // src/roon/devices.ts
51734
+ init_session();
51735
+ init_graph();
51736
+ async function raatDevices(c) {
51737
+ const list = await untilField(c, c.serviceOid("Transport"), "RaatServers", 4e3);
51738
+ const servers = items(c, list);
51739
+ const out = [];
51740
+ for (const s of servers) {
51741
+ const devs = field2(s, "Devices") ?? await untilField(c, s.oid, "Devices", 2e3);
51742
+ const refs = obj(c, devs)?.fields?.$items ?? [];
51743
+ await untilLoaded(c, refs, 2e3);
51744
+ for (const d of items(c, devs)) {
51745
+ const name = field2(d, "Name");
51746
+ if (typeof name !== "string") continue;
51747
+ const ep = obj(c, field2(d, "Endpoint"));
51748
+ const zone3 = !!ep && obj(c, field2(ep, "Zone")) != null;
51749
+ out.push({
51750
+ name,
51751
+ server: String(field2(s, "MachineName") ?? ""),
51752
+ ip: String(field2(s, "IPAddress") ?? ""),
51753
+ enabled: flag(field2(d, "IsEnabled")),
51754
+ zone: zone3,
51755
+ status: String(field2(d, "Status") ?? ""),
51756
+ oid: BigInt(d.oid)
51757
+ });
51758
+ }
51759
+ }
51760
+ return out;
51761
+ }
51762
+ __name(raatDevices, "raatDevices");
51763
+ var show = /* @__PURE__ */ __name((d) => ({ name: d.name, machine: d.server, ip: d.ip, enabled: d.enabled, zone: d.zone, ...d.status ? { status: d.status } : {} }), "show");
51764
+ async function devices() {
51765
+ return withCore(async (c) => ({ devices: (await raatDevices(c)).map(show) }));
51766
+ }
51767
+ __name(devices, "devices");
51768
+ async function deviceReset(opts) {
51769
+ if (!opts.name && !opts.ip) throw new RoonError("Give a device name or the address of its RAAT server", "invalid");
51770
+ return withCore(async (c) => {
51771
+ const want = opts.name?.toLowerCase();
51772
+ const all = await raatDevices(c);
51773
+ const match = all.filter((d) => (!want || d.name.toLowerCase() === want) && (!opts.ip || d.ip === opts.ip));
51774
+ if (!match.length) throw new RoonError(`No RAAT device ${opts.name ?? ""}${opts.ip ? " at " + opts.ip : ""}; Roon has: ${all.map((d) => d.name).join(", ")}`, "not_found");
51775
+ const stuck = match.filter((d) => d.enabled && !d.zone);
51776
+ const done = [];
51777
+ for (const d of stuck) {
51778
+ await short(c.call("RaatServerAudioDevice", "Disable", [{ type: "ResultCallback", name: "cb_result" }], Buffer.alloc(0), d.oid), 6e3);
51779
+ await wait(800);
51780
+ await short(c.call("RaatServerAudioDevice", "Enable", [{ type: "ResultCallback<Endpoint>", name: "cb_result" }], Buffer.alloc(0), d.oid), 8e3);
51781
+ done.push(d.name);
51782
+ }
51783
+ if (done.length) await wait(3e3);
51784
+ const after = (await raatDevices(c)).filter((d) => match.some((m) => m.oid === d.oid)).map(show);
51785
+ return { reset: done, left_alone: match.filter((d) => !stuck.includes(d)).map((d) => `${d.name} (${d.enabled ? "has a zone" : "disabled"})`), now: after };
51786
+ });
51787
+ }
51788
+ __name(deviceReset, "deviceReset");
51789
+
51667
51790
  // src/tools/library.ts
51668
51791
  init_session();
51669
51792
 
@@ -51675,6 +51798,16 @@ init_signature();
51675
51798
  init_session();
51676
51799
  init_graph();
51677
51800
  init_library();
51801
+
51802
+ // src/core/readonly.ts
51803
+ function readOnlyMode(raw = process.env.DEEP_ROON_READ_ONLY) {
51804
+ const ro = (raw ?? "").trim().toLowerCase();
51805
+ if (!ro || ["off", "0", "false", "no"].includes(ro)) return "off";
51806
+ return ro === "all" ? "all" : "library";
51807
+ }
51808
+ __name(readOnlyMode, "readOnlyMode");
51809
+
51810
+ // src/roon/playlist-edit.ts
51678
51811
  function writablePlaylist(c, p) {
51679
51812
  const ro = field2(p, "IsReadOnly");
51680
51813
  const declaredBool = c.graph.types.get(p.typeId)?.members.some((m) => m.name.endsWith("::IsReadOnly") && m.propType === 2) === true;
@@ -51692,8 +51825,7 @@ function revisionOf(key, name, entries) {
51692
51825
  __name(revisionOf, "revisionOf");
51693
51826
  var playlistEditOn = /* @__PURE__ */ __name(() => ["1", "true", "on", "yes"].includes((process.env.DEEP_ROON_PLAYLIST_EDIT ?? "").trim().toLowerCase()), "playlistEditOn");
51694
51827
  function enabled() {
51695
- const ro = (process.env.DEEP_ROON_READ_ONLY ?? "").trim().toLowerCase();
51696
- if (ro && !["off", "0", "false", "no"].includes(ro)) invalid("Playlist editing is disabled by DEEP_ROON_READ_ONLY.");
51828
+ if (readOnlyMode() !== "off") invalid("Playlist editing is disabled by DEEP_ROON_READ_ONLY.");
51697
51829
  if (!playlistEditOn()) invalid("Playlist editing is experimental and disabled; see docs/playlist-editing.md.");
51698
51830
  }
51699
51831
  __name(enabled, "enabled");
@@ -52048,9 +52180,9 @@ function registerLibraryTools(server) {
52048
52180
  server.registerTool("roon_play_mix", {
52049
52181
  title: "Play a Daily Mix",
52050
52182
  description: "Play one of today's Daily Mixes on a Roon zone (`key` from roon_mixes, or the mix's name). `mode`: now (default), next or queue. Only on an explicit request, never as a probe.",
52051
- inputSchema: { key: external_exports.string(), zone: zone2, mode: mode2 },
52183
+ inputSchema: { key: external_exports.string(), zone: zone2, mode: mode2, profile: profile2 },
52052
52184
  annotations: PLAYS2
52053
- }, ({ key, zone: zn, mode: m }) => run(() => playMix(key, zn, m ?? "now")));
52185
+ }, ({ key, zone: zn, mode: m, profile: p }) => run(() => asProfile(p, () => playMix(key, zn, m ?? "now"))));
52054
52186
  registerPlaylistEditTools(server);
52055
52187
  server.registerTool("roon_playlists", {
52056
52188
  title: "Playlists",
@@ -52103,9 +52235,9 @@ function registerLibraryTools(server) {
52103
52235
  server.registerTool("roon_favorite", {
52104
52236
  title: "Heart an album or track",
52105
52237
  description: "Put a heart on an album or a track in Roon, or take it off (`on: false`). The `key` comes from a search, shelf, album or playlist result. Changes the user's library: only on an explicit request. Reads the heart back and says if Roon didn't change it.",
52106
- inputSchema: { kind: external_exports.enum(["album", "track"]), key: external_exports.string(), on: external_exports.boolean().optional() },
52238
+ inputSchema: { kind: external_exports.enum(["album", "track"]), key: external_exports.string(), on: external_exports.boolean().optional(), profile: profile2 },
52107
52239
  annotations: CHANGES
52108
- }, ({ kind, key, on }) => run(() => favorite(kind, key, on !== false)));
52240
+ }, ({ kind, key, on, profile: p }) => run(() => asProfile(p, () => favorite(kind, key, on !== false))));
52109
52241
  server.registerTool("roon_listen_later", {
52110
52242
  title: "Listen Later",
52111
52243
  description: "The user's Listen Later list in Roon: the albums (and tracks) marked to hear later, newest first, each with a `key`. By default only what still waits; `include_played: true` adds what has been heard since.",
@@ -52115,9 +52247,9 @@ function registerLibraryTools(server) {
52115
52247
  server.registerTool("roon_listen_later_set", {
52116
52248
  title: "Listen Later: add or remove",
52117
52249
  description: "Put an album or a track on the Listen Later list in Roon, or take it off (`on: false`) \u2014 the natural thing to offer after recommending something the user can't hear right now. Changes the library: only on an explicit request. Reads it back.",
52118
- inputSchema: { kind: external_exports.enum(["album", "track"]), key: external_exports.string(), on: external_exports.boolean().optional() },
52250
+ inputSchema: { kind: external_exports.enum(["album", "track"]), key: external_exports.string(), on: external_exports.boolean().optional(), profile: profile2 },
52119
52251
  annotations: CHANGES
52120
- }, ({ kind, key, on }) => run(() => listenLaterSet(kind, key, on !== false)));
52252
+ }, ({ kind, key, on, profile: p }) => run(() => asProfile(p, () => listenLaterSet(kind, key, on !== false))));
52121
52253
  server.registerTool("roon_library_add", {
52122
52254
  title: "Add to the library",
52123
52255
  description: "Add a Qobuz or TIDAL album to the user's Roon library (the album `key` from a search, shelf or discography). Changes the library: only on an explicit request.",
@@ -52154,6 +52286,18 @@ function registerLibraryTools(server) {
52154
52286
  inputSchema: { zone: zone2, enabled: external_exports.boolean().optional(), part: external_exports.string().optional(), preset: external_exports.string().optional() },
52155
52287
  annotations: CHANGES
52156
52288
  }, ({ zone: zn, enabled: enabled2, part, preset }) => run(() => dspSet(zn, { enabled: enabled2, part, preset })));
52289
+ server.registerTool("roon_devices", {
52290
+ title: "Audio devices",
52291
+ description: `Roon's RAAT audio devices as Settings \u2192 Audio shows them: per device its name, the machine and address of its RAAT server, whether it is enabled, and whether it has a zone now. An enabled device without a zone is usually stuck on "Enabling\u2026" (see roon_device_reset).`,
52292
+ inputSchema: {},
52293
+ annotations: READ2
52294
+ }, () => run(() => devices()));
52295
+ server.registerTool("roon_device_reset", {
52296
+ title: "Reset a stuck device",
52297
+ description: 'Disable and enable a RAAT device that is enabled but has no zone \u2014 what you do by hand in Settings \u2192 Audio when a device hangs on "Enabling\u2026" (Roon backs off after failed connections, e.g. a phone that changed networks). Only devices in that state are touched; others are left alone. By `name` or by `ip`, the address of the device\'s RAAT server (from roon_devices). Reads back.',
52298
+ inputSchema: { name: external_exports.string().optional().describe("The device name, as in roon_devices."), ip: external_exports.string().optional().describe("The address of its RAAT server, as in roon_devices.") },
52299
+ annotations: CHANGES
52300
+ }, ({ name, ip }) => run(() => deviceReset({ name, ip })));
52157
52301
  }
52158
52302
  __name(registerLibraryTools, "registerLibraryTools");
52159
52303
 
@@ -52273,6 +52417,7 @@ var INSTRUCTIONS = `Deep Roon MCP connects to the user's own Roon Core (music pl
52273
52417
  - Unofficial: this uses Roon's internal protocol, which a Roon update can change; if a tool says so, tell the user to check for an update.`;
52274
52418
  var LIBRARY_WRITES = /* @__PURE__ */ new Set([...PLAYLIST_WRITES, "roon_playlist_create", "roon_favorite", "roon_radio_favorite", "roon_listen_later_set", "roon_library_add", "roon_dsp_set"]);
52275
52419
  var PLAYBACK = /* @__PURE__ */ new Set([
52420
+ "roon_device_reset",
52276
52421
  "roon_play",
52277
52422
  "roon_play_tracks",
52278
52423
  "roon_play_radio",
@@ -52333,7 +52478,9 @@ function serveHttp(spec, internal, essentials, readOnly) {
52333
52478
  process.exit(1);
52334
52479
  }
52335
52480
  const host = m[1] || "127.0.0.1", port = Number(m[2]);
52336
- const web = import_http.default.createServer(async (req, res) => {
52481
+ const loopback = ["127.0.0.1", "localhost", "::1", "[::1]"].includes(host);
52482
+ const okHost = /* @__PURE__ */ __name((h) => !loopback || /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i.test(h ?? ""), "okHost");
52483
+ const handle = /* @__PURE__ */ __name(async (req, res) => {
52337
52484
  if (req.url?.split("?")[0] !== "/mcp") {
52338
52485
  res.writeHead(404).end();
52339
52486
  return;
@@ -52342,8 +52489,22 @@ function serveHttp(spec, internal, essentials, readOnly) {
52342
52489
  res.writeHead(405, { allow: "POST" }).end();
52343
52490
  return;
52344
52491
  }
52492
+ if (req.headers.origin || !okHost(req.headers.host)) {
52493
+ res.writeHead(403).end("Forbidden");
52494
+ req.resume();
52495
+ return;
52496
+ }
52345
52497
  const chunks = [];
52346
- for await (const c of req) chunks.push(c);
52498
+ let size = 0;
52499
+ for await (const c of req) {
52500
+ size += c.length;
52501
+ if (size > 4 * 1024 * 1024) {
52502
+ res.writeHead(413).end("Too large");
52503
+ req.destroy();
52504
+ return;
52505
+ }
52506
+ chunks.push(c);
52507
+ }
52347
52508
  let body;
52348
52509
  try {
52349
52510
  body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
@@ -52359,13 +52520,19 @@ function serveHttp(spec, internal, essentials, readOnly) {
52359
52520
  server.close().catch(() => {
52360
52521
  });
52361
52522
  });
52362
- try {
52363
- await server.connect(transport2);
52364
- await transport2.handleRequest(req, res, body);
52365
- } catch (e) {
52523
+ await server.connect(transport2);
52524
+ await transport2.handleRequest(req, res, body);
52525
+ }, "handle");
52526
+ const web = import_http.default.createServer((req, res) => {
52527
+ handle(req, res).catch((e) => {
52366
52528
  log(`http: ${e.message}`);
52367
- if (!res.headersSent) res.writeHead(500).end();
52368
- }
52529
+ if (!res.headersSent) {
52530
+ try {
52531
+ res.writeHead(500).end();
52532
+ } catch {
52533
+ }
52534
+ }
52535
+ });
52369
52536
  });
52370
52537
  web.listen(port, host, () => log(`${version2} ready (http://${host}:${port}/mcp)`));
52371
52538
  }
@@ -52373,8 +52540,8 @@ __name(serveHttp, "serveHttp");
52373
52540
  async function main() {
52374
52541
  const internal = !/^(off|false|0|no)$/i.test(process.env.DEEP_ROON_INTERNAL ?? "");
52375
52542
  const essentials = /^(essentials|true|1|yes)$/i.test(process.env.DEEP_ROON_TOOLS ?? process.env.DEEP_ROON_ESSENTIALS ?? "");
52376
- const ro = (process.env.DEEP_ROON_READ_ONLY ?? "").trim().toLowerCase();
52377
- const readOnly = ro === "all" ? "all" : /^(library|true|1|yes)$/.test(ro) ? "library" : "off";
52543
+ const readOnly = readOnlyMode();
52544
+ process.on("unhandledRejection", (e) => log(`unhandled: ${e?.message ?? String(e)}`));
52378
52545
  if (internal) afterFirstConnect(() => selfTest(runSelfTest));
52379
52546
  checkForUpdate().catch(() => {
52380
52547
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deep-roon-mcp",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "An MCP server for Roon that reaches the parts the official API doesn't: reviews, biographies, Qobuz's and TIDAL's shelves, TIDAL's playlists, your history, search across your library and the streaming services",
5
5
  "license": "Apache-2.0",
6
6
  "author": "René Bouwmeester <21277119+renebouwmeester@users.noreply.github.com>",