@slack/radar-mcp 1.17.1 → 1.18.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.
@@ -4,8 +4,10 @@ import os from "os";
4
4
  import path from "path";
5
5
  import { spawn } from "child_process";
6
6
  import { fileURLToPath } from "url";
7
- import { AndroidTransport, resolveAdbPath } from "../shared/android.js";
7
+ import { resolveAdbPath } from "../shared/android.js";
8
+ import { createTransport } from "../shared/platform.js";
8
9
  import { planReconnect } from "../shared/stream.js";
10
+ import { createDashboardScreenController, } from "../shared/dashboard-screen.js";
9
11
  import { RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT } from "../shared/constants.js";
10
12
  import { friendlyFeatureFlagError } from "../shared/feature-flags.js";
11
13
  import { deviceServerSilentError, readProcessState, } from "../shared/enable-diagnosis.js";
@@ -13,7 +15,7 @@ import { cleanupPulledDatabases, initializeDatabasePath, listDatabases, pullData
13
15
  import { listPrefsFiles, readPrefsFile, parsePrefsXml, searchPrefs, } from "../shared/prefs.js";
14
16
  import { LogSession } from "./log-session.js";
15
17
  import { BLANK_SPEC, coerceSpec, validateSpec } from "./spec.js";
16
- import { screenCapabilities, refreshScreenCapabilities, grantScreenConsent, hasScreenConsent, detectDisplay, displayNote, captureScreenshot, startLive, addViewer, removeViewer, reapLiveIfIdle, primeIfNeeded, startRecording, stopRecording, getLive, capturePath, saveScreenshot, screenshotSaveErrorMessage, resetScreenState, registerScreenCleanup, resolveFfmpeg, ffmpegInstallHint, SCREEN_BOUNDARY, } from "../shared/screen.js";
18
+ import { grantScreenConsent, hasScreenConsent, detectDisplay, startLive, addViewer, removeViewer, reapLiveIfIdle, primeIfNeeded, capturePath, ffmpegInstallHint, SCREEN_BOUNDARY, } from "../shared/screen.js";
17
19
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
20
  const WEB_PORT = Number(process.env.SLACK_RADAR_WEB_PORT ?? WEB_PORT_DEFAULT);
19
21
  const INDEX_PATH = path.join(__dirname, "public", "index.html");
@@ -61,7 +63,15 @@ const SPEC_PATH = path.join(SPEC_DIR, `web-spec-${WEB_PORT}.json`);
61
63
  // (JSON.stringify of the body) on every poll, and adding fields here would perturb that
62
64
  // fingerprint every launch for a reason unrelated to the actual spec.
63
65
  const SELF_HEAL_PATH = path.join(SPEC_DIR, "self-heal.json");
64
- const transport = new AndroidTransport();
66
+ const transport = createTransport();
67
+ const dashboardScreen = createDashboardScreenController(transport);
68
+ // The serial THIS route last armed, and whether it has already done a full screen teardown.
69
+ // Keyed to what this handler itself armed rather than `selection.switched`, so the decision cannot
70
+ // be perturbed by anything that clears ANDROID_SERIAL or by a reconcile change. The two also
71
+ // DIFFER on a null pin: `switched` is absent when nothing is attached, while this keeps the last
72
+ // real arm across an empty-device enable, which turns out to be the interesting case.
73
+ let screenResetThisProcess = false;
74
+ let lastArmedSerial = null;
65
75
  // The ONE ceiling for every device ping this file makes (boot-arm, /health, /enable all go
66
76
  // through pingDevice). A shorter one turns ordinary latency into a false negative: boot would
67
77
  // read a live-but-slow session as absent, and /health would flap the connection dot. Observed
@@ -82,12 +92,15 @@ function forwardForRead() {
82
92
  // log history instead of only lines that arrive after the reconnect, matching
83
93
  // how Android Studio retains logcat for the whole session. Spawn + parse are
84
94
  // injected so the capture logic is unit-testable without a real `adb logcat`.
85
- const logSession = new LogSession(() => spawn(resolveAdbPath() ?? "adb", ["logcat", "-v", "threadtime", "-T", "1"], {
86
- stdio: ["ignore", "pipe", "ignore"],
87
- }), (line) => parseLogcat(line));
95
+ // Only spawn when the transport supports local device access (i.e. Android).
96
+ const logSession = transport.supportsLocalFileAccess
97
+ ? new LogSession(() => spawn(resolveAdbPath() ?? "adb", ["logcat", "-v", "threadtime", "-T", "1"], {
98
+ stdio: ["ignore", "pipe", "ignore"],
99
+ }), (line) => parseLogcat(line))
100
+ : null;
88
101
  // Kill the persistent logcat child on process exit so it does not orphan when the
89
102
  // dashboard is spawned and later terminated by the open_radar_dashboard MCP tool.
90
- logSession.registerCleanup();
103
+ logSession?.registerCleanup();
91
104
  // By design the capture is NOT stopped when the last log stream disconnects (e.g.
92
105
  // switching to the Network tab): it keeps filling the session ring so returning to
93
106
  // a log tab — even much later — still shows the full history, the way Android
@@ -326,18 +339,16 @@ const shuttingDown = new WeakSet();
326
339
  * actually exiting the process.
327
340
  */
328
341
  export async function shutdownDashboard(server, deps = {}) {
329
- const _getLive = deps.getLive ?? getLive;
330
- const _stopRecording = deps.stopRecording ?? stopRecording;
342
+ const screen = deps.screen ?? dashboardScreen;
331
343
  const _exit = deps.exit ?? ((code) => process.exit(code));
332
344
  const _log = deps.log ?? ((msg) => console.log(msg));
333
345
  if (shuttingDown.has(server))
334
346
  return;
335
347
  shuttingDown.add(server);
336
348
  _log("\nShutting down…");
337
- const live = _getLive();
338
- if (live && live.recording) {
349
+ if (screen.isRecording()) {
339
350
  try {
340
- await _stopRecording(live);
351
+ await screen.stopRecording();
341
352
  }
342
353
  catch {
343
354
  // Best-effort finalize; proceed with shutdown even if the stop failed.
@@ -475,6 +486,8 @@ async function armDevice() {
475
486
  // answered for the user), and a device list that could not be read at all. The second is a real
476
487
  // condition, and it is not left unreported: /_control/devices polls separately and distinguishes
477
488
  // adb_error from zero devices, which the header's device chip renders as "device: adb error".
489
+ if (!transport.selectDeviceAsync)
490
+ return;
478
491
  const selection = await transport.selectDeviceAsync(null);
479
492
  if (!selection.ok)
480
493
  return;
@@ -483,6 +496,8 @@ async function armDevice() {
483
496
  // that is unauthorized or offline fails exactly here, and silence on that path is what left
484
497
  // people staring at "waiting for device" with no idea a launch had already tried and why it
485
498
  // stopped.
499
+ if (!transport.reassertForwardAsync)
500
+ return;
486
501
  if (!(await transport.reassertForwardAsync())) {
487
502
  const reason = transport.getLastForwardError?.() ?? null;
488
503
  // Only when something is on the cable: an empty desk fails the forward too ("no
@@ -509,9 +524,16 @@ async function armDevice() {
509
524
  // is bound anywhere, so a broadcast cannot take another session's window. Anything else skips,
510
525
  // because the cost of guessing wrong is another process's window while the cost of not arming
511
526
  // is one press of a button that is already on screen.
527
+ if (!transport.radarSocketPresentAsync)
528
+ return;
512
529
  if ((await transport.radarSocketPresentAsync()) !== "absent")
513
530
  return;
514
- await transport.activateAsync(transport.getTimeoutMinutes());
531
+ if (transport.activateAsync) {
532
+ await transport.activateAsync(transport.getTimeoutMinutes());
533
+ }
534
+ else {
535
+ transport.activate(transport.getTimeoutMinutes());
536
+ }
515
537
  // A device WAS reachable and the broadcast still failed, which is worth printing. Silence here is
516
538
  // what left people staring at "waiting for device" with no idea a launch had already tried.
517
539
  const error = transport.getLastActivateError?.() ?? null;
@@ -543,7 +565,7 @@ export function startAutoCloseSweep(server) {
543
565
  * exercise the route without exiting the process. bin.ts calls createServer() with no args.
544
566
  */
545
567
  export function createServer(onShutdown) {
546
- registerScreenCleanup(); // tear down any live screen cast on process exit/signals
568
+ dashboardScreen.registerCleanup();
547
569
  const server = http.createServer((req, res) => {
548
570
  // One chokepoint for every route: a request whose Host is not this loopback dashboard is a
549
571
  // rebound foreign origin, not our client (see isLocalHostHeader). Rejected before routing so
@@ -643,6 +665,15 @@ export function createServer(onShutdown) {
643
665
  handleStream(req, res);
644
666
  return;
645
667
  }
668
+ if (url.startsWith("/backfill") || url.startsWith("/detail") || url.startsWith("/api/") ||
669
+ url.startsWith("/dbs") || url.startsWith("/dbtables") || url.startsWith("/dbquery") ||
670
+ url.startsWith("/flags") || url.split("?")[0] === "/prefs" ||
671
+ url.startsWith("/prefsread") || url.startsWith("/prefssearch")) {
672
+ if (!transport.supportsLocalFileAccess) {
673
+ sendJson(res, 400, { error: `Not supported on ${transport.platform}` });
674
+ return;
675
+ }
676
+ }
646
677
  if (url.startsWith("/backfill")) {
647
678
  handleBackfill(req, res);
648
679
  return;
@@ -918,7 +949,7 @@ async function handleHealth(res) {
918
949
  const selected = transport.getSelectedDevice?.() ?? null;
919
950
  sendJson(res, 200, {
920
951
  device: ok,
921
- screen: screenCapabilities(),
952
+ screen: dashboardScreen.capabilities(),
922
953
  boundUserId: uid,
923
954
  boundProfile: profile,
924
955
  device_serial: selected?.serial ?? null,
@@ -1108,7 +1139,7 @@ async function handleEnable(res, deviceSerial, authored) {
1108
1139
  // A reconnect may be a different device / re-armed profile, so drop the cached DB user
1109
1140
  // set + sqlite path; the next /dbs re-detects the profiles fresh.
1110
1141
  resetDbState();
1111
- // Pin the target device BEFORE any adb call, including resetScreenState's pkill below --
1142
+ // Pin the target device BEFORE any platform screen reset below --
1112
1143
  // that call has no serial of its own and would otherwise target whatever `adb` defaults
1113
1144
  // to (or fail ambiguously) on a multi-device host, running one adb call outside the
1114
1145
  // "pin before any adb call" invariant every other call site in this handler honors. An
@@ -1131,7 +1162,33 @@ async function handleEnable(res, deviceSerial, authored) {
1131
1162
  // from the reply itself, instead of discovering the pin from a later health poll whose serial
1132
1163
  // edge would retire the very reason the reply carries.
1133
1164
  const pinnedSerial = () => transport.getSelectedDevice?.()?.serial ?? null;
1134
- resetScreenState(); // re-detect the active display + clear any stale cast on re-arm
1165
+ // Screen state: the SAFE SUBSET unless this is a real session boundary. The controller's full
1166
+ // reset() is destructive on every platform -- Android's kills radar's device-side screenrecord,
1167
+ // deletes the saved recordings, and tears down a live cast the user may be watching this second;
1168
+ // iOS's deletes the saved recordings on disk. Running that on every enable meant a plain re-arm
1169
+ // of the SAME device destroyed work nobody asked it to, and it made the enable route unsafe to
1170
+ // call from anything automatic. So the full teardown is now earned by one of two things:
1171
+ // - the pin moved to DIFFERENT hardware, so every piece of per-device screen state is stale, or
1172
+ // - this is the first enable in this PROCESS with a device actually attached, which is where an
1173
+ // orphaned screenrecord left by a crashed previous dashboard gets cleaned up.
1174
+ // Everything else gets the detection reset only, which is all a same-device re-arm actually needs.
1175
+ const pinned = selection && selection.ok ? (selection.serial ?? null) : null;
1176
+ // A null pin means "nothing attached", not "the hardware changed".
1177
+ const switched = pinned !== null && lastArmedSerial !== null && pinned !== lastArmedSerial;
1178
+ // The one-shot orphan reap is spent only on an enable that HAS a device; an empty-device press
1179
+ // would fire it at nothing and leave the real orphan alive for the life of the process.
1180
+ if (switched || (pinned !== null && !screenResetThisProcess)) {
1181
+ screenResetThisProcess = true;
1182
+ dashboardScreen.reset();
1183
+ }
1184
+ else {
1185
+ dashboardScreen.resetDetection();
1186
+ }
1187
+ // Only remember a serial we actually ARMED. selectDevice returns { ok: true, serial: null } when
1188
+ // nothing is attached (android.ts path d), and letting that null overwrite the memory would make a
1189
+ // later pin of DIFFERENT hardware look like a first pin, so a real swap would take the light path.
1190
+ if (pinned)
1191
+ lastArmedSerial = pinned;
1135
1192
  // On a switch to a different device, drop this device's pulled DB scratch AND the
1136
1193
  // retained logcat capture -- both are per-device state resetDbState()/resetScreenState()
1137
1194
  // above do not cover. logSession.restart() (not stop()) is deliberate here: stop() alone
@@ -1141,9 +1198,9 @@ async function handleEnable(res, deviceSerial, authored) {
1141
1198
  // which resets its own local buffers/spool/capture on the same switch signal). start() is
1142
1199
  // idempotent, so a still-open Logs tab just keeps polling and picks the new child back up
1143
1200
  // on its next /stream reconnect; nothing here needs to force-restart it eagerly.
1144
- if (selection && selection.ok && selection.switched) {
1201
+ if (switched) {
1145
1202
  cleanupPulledDatabases();
1146
- logSession.restart();
1203
+ logSession?.restart();
1147
1204
  }
1148
1205
  // Reassert the forward is pointed at the selected device before reading. On a device
1149
1206
  // switch or after a multi-process repoint (e.g., MCP server switched to a different
@@ -1170,7 +1227,12 @@ async function handleEnable(res, deviceSerial, authored) {
1170
1227
  // enabled:false after the ping probe times out. Async for the same reason as the boot chain:
1171
1228
  // the broadcast waits for ordered delivery under a 15 second ceiling, and a Reconnect press
1172
1229
  // must not hold the event loop for it.
1173
- await transport.activateAsync(transport.getTimeoutMinutes());
1230
+ if (transport.activateAsync) {
1231
+ await transport.activateAsync(transport.getTimeoutMinutes());
1232
+ }
1233
+ else {
1234
+ transport.activate(transport.getTimeoutMinutes());
1235
+ }
1174
1236
  const activateError = transport.getLastActivateError?.() ?? null;
1175
1237
  if (activateError) {
1176
1238
  sendJson(res, 200, {
@@ -1322,7 +1384,7 @@ function handleDetail(req, res) {
1322
1384
  // (no paging), so nothing to inject. Response is buffered so a device error becomes a clean 200
1323
1385
  // {error} the Feature Flags tab renders in-place rather than a half-streamed body.
1324
1386
  //
1325
- // Device list shape: { feature_flags: [{ key, enabled, is_overridden }], total }. `enabled` is
1387
+ // Device list shape: { feature_flags: [{ key, scope, org_id, type, enabled | group_name, is_overridden, timestamp }], total_captured }. `enabled` is
1326
1388
  // the effective value (override if set, else the server value). Live changes arrive separately
1327
1389
  // as `feature_flag` frames on /api/stream (the on-device observer). Builds predating the plugin
1328
1390
  // 404, surfaced as a friendly message client-side.
@@ -1567,20 +1629,26 @@ function handleScreen(req, res) {
1567
1629
  const refresh = new URL(url, "http://localhost").searchParams.get("refresh") === "1";
1568
1630
  if (refresh) {
1569
1631
  void (async () => {
1570
- // refreshScreenCapabilities cannot throw today, but a future edit that lets a rejection
1632
+ // A platform capability refresh should never leave the request hanging if it fails.
1571
1633
  // escape would leave this request hanging until the client's 3s timeout. Guard it: on a
1572
1634
  // failed re-probe, still answer with the (cached) capabilities rather than nothing.
1573
1635
  try {
1574
- await refreshScreenCapabilities();
1636
+ await dashboardScreen.refreshCapabilities();
1575
1637
  }
1576
1638
  catch {
1577
1639
  // fall through to the cached capabilities below
1578
1640
  }
1579
- sendJson(res, 200, { ...screenCapabilities(), consent: hasScreenConsent() });
1641
+ sendJson(res, 200, {
1642
+ ...dashboardScreen.capabilities(),
1643
+ consent: hasScreenConsent(),
1644
+ });
1580
1645
  })();
1581
1646
  }
1582
1647
  else {
1583
- sendJson(res, 200, { ...screenCapabilities(), consent: hasScreenConsent() });
1648
+ sendJson(res, 200, {
1649
+ ...dashboardScreen.capabilities(),
1650
+ consent: hasScreenConsent(),
1651
+ });
1584
1652
  }
1585
1653
  return;
1586
1654
  }
@@ -1605,24 +1673,35 @@ function handleScreen(req, res) {
1605
1673
  // rejection would leave this request hanging until the client times out, and a route whose
1606
1674
  // whole purpose is reporting the outcome must not have a silent way to report nothing.
1607
1675
  try {
1608
- await detectDisplay();
1609
- const shot = await saveScreenshot();
1610
- if (!shot.ok) {
1611
- // Name the half that failed. A write failure is a host problem (no space, a dir mode the
1612
- // process cannot write); calling it a capture failure would send the user to check a
1613
- // phone that answered perfectly well.
1614
- sendJson(res, 502, { ok: false, error: screenshotSaveErrorMessage(shot) });
1676
+ await dashboardScreen.refreshCapabilities();
1677
+ const png = await dashboardScreen.captureScreenshot();
1678
+ if (!png) {
1679
+ sendJson(res, 502, { ok: false, error: "screencap failed; is the device awake and connected?" });
1680
+ return;
1681
+ }
1682
+ const SC_TMP = path.join(os.homedir(), ".slack-radar", "screen");
1683
+ const safe = new Date().toISOString().replace(/[:.]/g, "-");
1684
+ const out = path.join(SC_TMP, `radar_screen_${safe}.png`);
1685
+ try {
1686
+ fs.mkdirSync(SC_TMP, { recursive: true, mode: 0o700 });
1687
+ try {
1688
+ fs.chmodSync(SC_TMP, 0o700);
1689
+ }
1690
+ catch { /* best-effort */ }
1691
+ fs.writeFileSync(out, png, { mode: 0o600 });
1692
+ }
1693
+ catch (e) {
1694
+ sendJson(res, 502, { ok: false, error: "could not write the screenshot to disk: " + e.message });
1615
1695
  return;
1616
1696
  }
1617
- const p = shot.path;
1618
1697
  let sizeBytes = 0;
1619
1698
  try {
1620
- sizeBytes = fs.statSync(p).size;
1699
+ sizeBytes = fs.statSync(out).size;
1621
1700
  }
1622
1701
  catch {
1623
1702
  sizeBytes = 0;
1624
1703
  }
1625
- const file = path.basename(p);
1704
+ const file = path.basename(out);
1626
1705
  sendJson(res, 200, {
1627
1706
  ok: true,
1628
1707
  file,
@@ -1645,15 +1724,17 @@ function handleScreen(req, res) {
1645
1724
  return;
1646
1725
  }
1647
1726
  void (async () => {
1648
- await detectDisplay();
1649
- const png = await captureScreenshot();
1727
+ const png = await dashboardScreen.captureScreenshot();
1650
1728
  if (!png) {
1651
- sendJson(res, 502, { error: "screencap failed; is the device awake and connected?" });
1729
+ sendJson(res, 502, { error: "screen capture failed; is the device running and awake?" });
1652
1730
  return;
1653
1731
  }
1732
+ const inline = new URL(url, `http://localhost:${WEB_PORT}`).searchParams.get("inline") === "1";
1654
1733
  res.writeHead(200, {
1655
1734
  "Content-Type": "image/png",
1656
- "Content-Disposition": `attachment; filename="radar-screen-${Date.now()}.png"`,
1735
+ ...(inline
1736
+ ? { "Cache-Control": "no-store" }
1737
+ : { "Content-Disposition": `attachment; filename="radar-screen-${Date.now()}.png"` }),
1657
1738
  });
1658
1739
  res.end(png);
1659
1740
  })();
@@ -1665,8 +1746,11 @@ function handleScreen(req, res) {
1665
1746
  sendJson(res, 403, { error: "screen consent required" });
1666
1747
  return;
1667
1748
  }
1668
- if (!resolveFfmpeg()) {
1669
- sendJson(res, 501, { error: "ffmpeg not installed", installHint: ffmpegInstallHint() });
1749
+ const capabilities = dashboardScreen.capabilities();
1750
+ if (!capabilities.liveCast) {
1751
+ sendJson(res, 501, capabilities.installHint
1752
+ ? { error: "ffmpeg not installed", installHint: capabilities.installHint }
1753
+ : { error: `live mirroring is not supported for ${capabilities.platform} yet` });
1670
1754
  return;
1671
1755
  }
1672
1756
  const fps = Number(new URL(url, `http://localhost:${WEB_PORT}`).searchParams.get("fps")) || 20;
@@ -1708,39 +1792,47 @@ function handleScreen(req, res) {
1708
1792
  return;
1709
1793
  }
1710
1794
  void (async () => {
1711
- await detectDisplay();
1712
- if (!startLive(20)) {
1713
- sendJson(res, 501, { error: "ffmpeg not installed", installHint: ffmpegInstallHint() });
1714
- return;
1795
+ try {
1796
+ const recording = await dashboardScreen.startRecording();
1797
+ if (!recording) {
1798
+ const capabilities = dashboardScreen.capabilities();
1799
+ sendJson(res, 501, capabilities.installHint
1800
+ ? { error: "screen recording dependency unavailable", installHint: capabilities.installHint }
1801
+ : { error: `screen recording is not supported for ${capabilities.platform}` });
1802
+ return;
1803
+ }
1804
+ sendJson(res, 200, { ok: true, file: path.basename(recording) });
1805
+ }
1806
+ catch (error) {
1807
+ sendJson(res, 502, { error: error instanceof Error ? error.message : String(error) });
1715
1808
  }
1716
- const p = startRecording();
1717
- sendJson(res, 200, { ok: p !== null, file: p ? path.basename(p) : null });
1718
1809
  })();
1719
1810
  return;
1720
1811
  }
1721
1812
  if (url === "/screen/record/stop" && req.method === "POST") {
1722
1813
  void (async () => {
1723
- const p = await stopRecording();
1724
- // If the viewer already left (the close-while-recording path drops the <img> before
1725
- // this POST lands), the recording was the only thing keeping the cast alive — reap it
1726
- // now so screenrecord + ffmpeg do not run on with no viewer.
1727
- reapLiveIfIdle();
1728
- const file = p ? path.basename(p) : null;
1729
- let sizeBytes = 0;
1730
- if (p) {
1731
- try {
1732
- sizeBytes = fs.statSync(p).size;
1733
- }
1734
- catch {
1735
- sizeBytes = 0;
1814
+ try {
1815
+ const p = await dashboardScreen.stopRecording();
1816
+ const file = p ? path.basename(p) : null;
1817
+ let sizeBytes = 0;
1818
+ if (p) {
1819
+ try {
1820
+ sizeBytes = fs.statSync(p).size;
1821
+ }
1822
+ catch {
1823
+ sizeBytes = 0;
1824
+ }
1736
1825
  }
1826
+ sendJson(res, 200, {
1827
+ ok: true,
1828
+ file,
1829
+ sizeBytes,
1830
+ download: file ? "/screen/download?f=" + encodeURIComponent(file) : null,
1831
+ });
1832
+ }
1833
+ catch (error) {
1834
+ sendJson(res, 502, { error: error instanceof Error ? error.message : String(error) });
1737
1835
  }
1738
- sendJson(res, 200, {
1739
- ok: true,
1740
- file,
1741
- sizeBytes,
1742
- download: file ? "/screen/download?f=" + encodeURIComponent(file) : null,
1743
- });
1744
1836
  })();
1745
1837
  return;
1746
1838
  }
@@ -1787,8 +1879,11 @@ function handleScreen(req, res) {
1787
1879
  return;
1788
1880
  }
1789
1881
  if (url === "/screen/redetect") {
1790
- resetScreenState();
1791
- void detectDisplay().then(() => sendJson(res, 200, { display: displayNote() }));
1882
+ void dashboardScreen.redetect()
1883
+ .then((display) => sendJson(res, 200, { display }))
1884
+ .catch((error) => sendJson(res, 502, {
1885
+ error: error instanceof Error ? error.message : String(error),
1886
+ }));
1792
1887
  return;
1793
1888
  }
1794
1889
  res.writeHead(404);
@@ -1911,7 +2006,7 @@ function handleStream(req, res) {
1911
2006
  const armLogcat = () => {
1912
2007
  if (!wantsLogs || closed)
1913
2008
  return;
1914
- const ok = logSession.start();
2009
+ const ok = logSession?.start() ?? false;
1915
2010
  if (!ok) {
1916
2011
  // Spawn failed (e.g. no adb on PATH). The capture is a named session-scoped
1917
2012
  // thing now, so surface the reason rather than showing silent emptiness.
@@ -1990,7 +2085,7 @@ function handleStream(req, res) {
1990
2085
  if (wantsLogs) {
1991
2086
  refreshPidMap(); // warm PID->package so the first log rows resolve their app
1992
2087
  armLogcat(); // idempotent start; surfaces a status frame if spawn fails
1993
- unsubscribeLogs = logSession.subscribe((ev, replay) => {
2088
+ unsubscribeLogs = logSession?.subscribe((ev, replay) => {
1994
2089
  if (closed)
1995
2090
  return;
1996
2091
  // Backpressure guard: if this client is slow or its tab is backgrounded
@@ -2036,13 +2131,13 @@ function handleStream(req, res) {
2036
2131
  });
2037
2132
  }
2038
2133
  function listProfiles(res) {
2039
- const profiles = transport.listProfiles();
2134
+ const profiles = transport.listProfiles?.() ?? [];
2040
2135
  const activeUserId = transport.getActiveUserId();
2041
2136
  sendJson(res, 200, { profiles, active_user_id: activeUserId });
2042
2137
  }
2043
2138
  // The attached-device list + the currently pinned device, for the dashboard's device picker.
2044
- // listDevices() returns null when the adb listing itself failed (not "zero attached"); surface
2045
- // that as adb_error:true with an empty list so the client can say why instead of showing "none".
2139
+ // listDevices() returns null when the platform listing itself failed (not "zero attached"). Keep
2140
+ // the legacy adb_error response for the existing client; the iOS happy path uses the same list.
2046
2141
  function listDevices(res) {
2047
2142
  // Distinguish null (adb listing failed) from [] (no devices): null means we cannot tell what
2048
2143
  // is attached, so tell the client with adb_error instead of a bare "none". A transport with no
@@ -2068,7 +2163,7 @@ function activateRadar(res, userId) {
2068
2163
  return;
2069
2164
  }
2070
2165
  try {
2071
- if (userId) {
2166
+ if (userId && transport.activateForUser) {
2072
2167
  transport.activateForUser(userId, 5);
2073
2168
  }
2074
2169
  else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slack/radar-mcp",
3
- "version": "1.17.1",
4
- "description": "MCP server and web dashboard for on-device debugging of the Slack Android app via ADB",
3
+ "version": "1.18.0",
4
+ "description": "MCP server and web dashboard for debugging Slack on Android and iOS Simulator",
5
5
  "type": "module",
6
6
  "main": "dist/mcp/index.js",
7
7
  "bin": {
@@ -32,6 +32,7 @@
32
32
  "mcp",
33
33
  "slack",
34
34
  "android",
35
+ "ios",
35
36
  "debugging",
36
37
  "adb"
37
38
  ],