@slack/radar-mcp 1.11.0 → 1.12.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/README.md CHANGED
@@ -49,7 +49,7 @@ Opens `http://localhost:8100` automatically. Set `SLACK_RADAR_WEB_PORT` to use a
49
49
  * **Database** — read-only browser for the on-device SQLite stores (pick a database, then a table, or run a read-only query). See the data-handling note below.
50
50
  * **Custom** — a tab Claude builds on request. Ask a Claude Code session in your terminal for a view the pre-built tabs do not cover (e.g. "graph calls per second and flag the slow ones"); it authors the view via the `open_radar_dashboard` tool and it appears here. Persists until you refresh the page.
51
51
 
52
- Each tab has a rate, sparkline, graph, a filter / sort / pause feed, and a payload inspector. Switching tabs replays what you have already seen this session (the browser caches it, bounded by count and age) so the view does not reset to empty. ADB forwarding and device activation are handled for you; a reconnect control re-arms after a device sleep. The dashboard follows your system light/dark setting by default; the theme toggle in the header overrides it and is remembered.
52
+ Each tab has a rate, sparkline, graph, a filter / sort / pause feed, and a payload inspector. The filter box takes space-separated terms that must all match, `-term` to exclude, `/pattern/` for regex, and `"quoted phrases"` for spaces or a literal `-` or `/`. Committed terms turn into removable pills; a leading `-` is now the exclude operator (the old box matched it as plain text), and quoting restores the literal. Regex flags are optional and short (i/m/s/g, 1-2 letters only, so an ambiguous tail like `/api/im` reads as flags, noted in the tooltip); typos like `/error/x` become part of the pattern and match literally, and quoting any `/…/` term matches it literally. Invalid regexes and incomplete typing (e.g. `/foo(`) are ignored (the term turns amber) instead of blanking the feed. On the Live tab a kind name (`log`, `clog`, `trace`, `rtm`, `network`) also matches rows of that type, and its `-kind` form excludes by row type only, so `-log` hides logcat lines without touching a `logout` clog (quote it, `-"log"`, to exclude by text instead). Switching tabs replays what you have already seen this session (the browser caches it, bounded by count and age) so the view does not reset to empty. ADB forwarding and device activation are handled for you; a reconnect control re-arms after a device sleep. The dashboard follows your system light/dark setting by default; the theme toggle in the header overrides it and is remembered.
53
53
 
54
54
  ### Screen overlay
55
55
 
@@ -81,7 +81,7 @@ Radar starts **disabled** each session. All tools except `ping` return an error
81
81
 
82
82
  | Tool | Description |
83
83
  |---|---|
84
- | `ping` | Health check. Returns uptime, buffer sizes, remaining session time, stream status, and which app/profile is bound (`android_user_id`, `profile` personal/secondary, `package`). Use `timeout_minutes` to extend sessions. |
84
+ | `ping` | Health check. Returns uptime, buffer sizes, remaining session time, stream status, the Radar MCP version (`mcp_version`), and which app/profile is bound (`android_user_id`, `profile` personal/secondary, `package`). Use `timeout_minutes` to extend sessions. |
85
85
  | `get_recent_network_calls` | HTTP call summaries: method, URL, status code, duration. Filterable by URL substring and status code. |
86
86
  | `get_network_call_detail` | Full request/response headers and bodies for a specific call (gzip/brotli decompressed). |
87
87
  | `get_recent_rtm_events` | RTM event summaries: type, direction, channel, timestamp. Filterable by type, direction, channel. Uses subtypes (e.g. `message_changed`, not `message`). |
package/dist/mcp/index.js CHANGED
@@ -8,7 +8,7 @@ import http from "http";
8
8
  import path from "path";
9
9
  import { fileURLToPath } from "url";
10
10
  import { AndroidTransport } from "../shared/android.js";
11
- import { RADAR_HOST, RADAR_PORT, WEB_PORT_DEFAULT, MAX_RADAR_RESPONSE_BYTES } from "../shared/constants.js";
11
+ import { RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT, MAX_RADAR_RESPONSE_BYTES } from "../shared/constants.js";
12
12
  import { stopCapture } from "../shared/logcat-capture.js";
13
13
  import { getSpoolFilePath, epochFromSpoolPath, initializeSpoolDir, readSpool, startSpool, stopSpool, writeFrame, registerCleanup as registerSpoolCleanup, } from "../shared/event-spool.js";
14
14
  import { connectStream, destroyStream, waitForEvents, clearLocalBuffers, isStreamConnected, localNetworkBuffer, localRtmBuffer, setTransport, setOnReconnect, } from "../shared/stream.js";
@@ -19,6 +19,7 @@ import { resolveDetailById } from "./session-detail.js";
19
19
  import { runSessionEnable } from "./session-enable.js";
20
20
  import { backfillSpool, BACKFILL_SOURCES, makeSerializedRunner, } from "./session-backfill.js";
21
21
  import { handleListDatabases, handleListTables, handleQueryDatabase, } from "./db-tools.js";
22
+ import { handleListPrefs, handleGetPrefs, handleSearchPrefs, } from "./prefs-tools.js";
22
23
  import { cleanupPulledDatabases, initializeDatabasePath, resetDbState, } from "../shared/db.js";
23
24
  import { TOOL_DEFINITIONS, SERVER_INSTRUCTIONS, sessionGate } from "./tools.js";
24
25
  import { buildApiPath } from "./api-paths.js";
@@ -330,8 +331,16 @@ async function runMcpServer() {
330
331
  });
331
332
  });
332
333
  }
334
+ // Reassert the shared adb forward before every HTTP-based device read. Prefer
335
+ // reassertForward() (repoints the shared port at OUR pinned device even if a separate
336
+ // process silently moved it) over plain ensureForward() (trusts a same-process cache
337
+ // that cannot see another process's repoint). Platforms without a shared host-level
338
+ // forward may omit reassertForward, so this falls back to ensureForward.
339
+ function forwardForRead() {
340
+ return device.reassertForward?.() ?? device.ensureForward();
341
+ }
333
342
  async function callRadar(requestPath) {
334
- if (!device.ensureForward()) {
343
+ if (!forwardForRead()) {
335
344
  return {
336
345
  error: "Port forwarding failed. Ensure a device is connected and the debug build is running.",
337
346
  };
@@ -377,6 +386,7 @@ async function runMcpServer() {
377
386
  // --- Tool handlers ---
378
387
  async function handleSessionEnable(args) {
379
388
  const timeout = args?.timeout_minutes || 5;
389
+ const deviceSerial = args?.device_serial ?? null;
380
390
  // The orchestration lives in session-enable.ts (testable without the stdio
381
391
  // server this module starts at load); this handler wires the real effects
382
392
  // and owns the session flag. sessionEnabled goes true up front so the
@@ -386,7 +396,7 @@ async function runMcpServer() {
386
396
  // while the SDK reports an opaque error.
387
397
  try {
388
398
  sessionEnabled = true;
389
- const outcome = await runSessionEnable(timeout, {
399
+ const outcome = await runSessionEnable(timeout, deviceSerial, {
390
400
  device,
391
401
  destroyStream,
392
402
  connectStream,
@@ -401,6 +411,14 @@ async function runMcpServer() {
401
411
  // under that ceiling.
402
412
  ping: () => radarRequest("/api/ping", 2000),
403
413
  sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
414
+ // Only fires on a switch to a different device: the prior device's buffers,
415
+ // spool, capture, and pulled DBs are stale for the new hardware.
416
+ onDeviceSwitch: () => {
417
+ clearLocalBuffers();
418
+ stopSpool();
419
+ stopCapture();
420
+ cleanupPulledDatabases();
421
+ },
404
422
  });
405
423
  sessionEnabled = outcome.enabled;
406
424
  return textResult(outcome.body, !outcome.enabled);
@@ -436,7 +454,7 @@ async function runMcpServer() {
436
454
  }
437
455
  async function handleWaitForEvents(args) {
438
456
  if (!isStreamConnected()) {
439
- if (!device.ensureForward()) {
457
+ if (!forwardForRead()) {
440
458
  return textResult({ error: "Not connected. Ensure device is connected and radar is enabled." }, true);
441
459
  }
442
460
  device.activate(device.getTimeoutMinutes());
@@ -623,6 +641,10 @@ async function runMcpServer() {
623
641
  device.activate(args.timeout_minutes);
624
642
  }
625
643
  const result = await callRadar("/api/ping");
644
+ // Version is a property of this process, not the device, so it is reported
645
+ // even when the device probe fails — the error path is exactly when a
646
+ // reviewer needs to correlate a report against a known-bad release.
647
+ result.mcp_version = RADAR_VERSION;
626
648
  if (!result.error) {
627
649
  result.stream_connected = isStreamConnected();
628
650
  result.local_network_buffer = localNetworkBuffer.length;
@@ -656,7 +678,7 @@ async function runMcpServer() {
656
678
  }
657
679
  }
658
680
  // --- MCP Server ---
659
- const server = new Server({ name: "slack-radar", version: "1.11.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
681
+ const server = new Server({ name: "slack-radar", version: "1.12.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
660
682
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
661
683
  tools: TOOL_DEFINITIONS,
662
684
  }));
@@ -728,6 +750,21 @@ async function runMcpServer() {
728
750
  if (name === "query_session") {
729
751
  return await handleQuerySession(toolArgs);
730
752
  }
753
+ if (name === "list_prefs") {
754
+ const { user } = toolArgs;
755
+ const { data, isError } = await handleListPrefs(user);
756
+ return textResult(data, isError);
757
+ }
758
+ if (name === "get_prefs") {
759
+ const { file, user, keys } = toolArgs;
760
+ const { data, isError } = await handleGetPrefs(file ?? "", user, keys);
761
+ return textResult(data, isError);
762
+ }
763
+ if (name === "search_prefs") {
764
+ const { query, user } = toolArgs;
765
+ const { data, isError } = await handleSearchPrefs(query ?? "", user);
766
+ return textResult(data, isError);
767
+ }
731
768
  const apiPath = buildApiPath(name, toolArgs);
732
769
  if (apiPath === null) {
733
770
  return textResult(`Unknown tool: ${name}`, true);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Handler dispatch for the three prefs tools: list_prefs, get_prefs, search_prefs.
3
+ */
4
+ export declare function handleListPrefs(user?: string): Promise<{
5
+ data: unknown;
6
+ isError: boolean;
7
+ }>;
8
+ export declare function handleGetPrefs(file: string, user?: string, keys?: string[]): Promise<{
9
+ data: unknown;
10
+ isError: boolean;
11
+ }>;
12
+ export declare function handleSearchPrefs(query: string, user?: string): Promise<{
13
+ data: unknown;
14
+ isError: boolean;
15
+ }>;
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Handler dispatch for the three prefs tools: list_prefs, get_prefs, search_prefs.
3
+ */
4
+ import { listPrefsFiles, readPrefsFile, parsePrefsXml, searchPrefs, } from "../shared/prefs.js";
5
+ import { resolveAdbPath } from "../shared/android.js";
6
+ import { availableUsers } from "../shared/db.js";
7
+ import { MAX_PREFS_RESPONSE_BYTES } from "../shared/constants.js";
8
+ /**
9
+ * Bound entries to the 64KB response budget with a single forward pass (the db-tools
10
+ * capQueryRows shape, see db-tools.ts:55-88, reimplemented here for the prefs entry type).
11
+ * Sizes against the WORST-CASE envelope (both truncation flags + the longest note text) so
12
+ * the fixed fields around `entries` never eat into a budget calculated for the untruncated
13
+ * case, which would either overrun MAX_PREFS_RESPONSE_BYTES or (the original bug) silently drop
14
+ * entries without setting response_truncated. Returns the entries to actually return, whether
15
+ * the cap tripped, and the keys of any entries dropped for being individually oversized (a
16
+ * single entry bigger than the WHOLE budget, e.g. one huge JSON-blob value) so the caller can
17
+ * name them rather than silently returning zero entries with no way to retrieve that key even
18
+ * via the `keys` filter, since `keys` filters BEFORE this cap runs.
19
+ */
20
+ function capPrefsEntries(entries, file, user) {
21
+ const overhead = JSON.stringify({
22
+ file,
23
+ user,
24
+ entries: [],
25
+ total_entries: entries.length,
26
+ returned_entries: 0,
27
+ device_read_truncated: true,
28
+ response_truncated: true,
29
+ note: "Device file exceeded 256KB and was truncated. Response truncated to 64KB. Use keys parameter to filter to specific entries or search_prefs to find what you need.",
30
+ dropped_keys: entries.map((e) => e.key),
31
+ privacy_note: "Preference values can include user, team, and org identifiers; review before sharing.",
32
+ }).length;
33
+ const entryBudget = MAX_PREFS_RESPONSE_BYTES - overhead;
34
+ const kept = [];
35
+ const droppedKeys = [];
36
+ let bytes = 0;
37
+ for (const entry of entries) {
38
+ // +1 for the joining comma between array elements.
39
+ const sz = Buffer.byteLength(JSON.stringify(entry), "utf8") + 1;
40
+ if (bytes + sz > entryBudget) {
41
+ // A single entry bigger than the WHOLE remaining budget can never fit by itself either
42
+ // (the budget only shrinks as more is kept, never grows), so record it as dropped and
43
+ // keep scanning for smaller entries that still fit, rather than stopping at the first
44
+ // oversized one. This is what makes an oversized key nameable instead of silently
45
+ // vanishing: `keys` filters before this cap runs, so without this the caller has no way
46
+ // to ever retrieve that key, even by asking for it directly.
47
+ if (sz > entryBudget)
48
+ droppedKeys.push(entry.key);
49
+ continue;
50
+ }
51
+ kept.push(entry);
52
+ bytes += sz;
53
+ }
54
+ return { entries: kept, truncated: kept.length < entries.length, droppedKeys };
55
+ }
56
+ export async function handleListPrefs(user) {
57
+ const adbPath = resolveAdbPath();
58
+ if (!adbPath) {
59
+ return {
60
+ data: {
61
+ error: "adb not found. Set ANDROID_HOME or install Android SDK platform-tools.",
62
+ },
63
+ isError: true,
64
+ };
65
+ }
66
+ try {
67
+ const result = listPrefsFiles(adbPath, user);
68
+ if (!result) {
69
+ const available = availableUsers();
70
+ return {
71
+ data: {
72
+ error: `Failed to list prefs files for user ${user ?? "(any)"}. Is the debug build installed and is a device connected? Available users: ${available.join(", ")}`,
73
+ },
74
+ isError: true,
75
+ };
76
+ }
77
+ return {
78
+ data: {
79
+ user: result.user,
80
+ available_users: availableUsers(),
81
+ files: result.files,
82
+ privacy_note: "Preference values can include user, team, and org identifiers; review before sharing.",
83
+ },
84
+ isError: false,
85
+ };
86
+ }
87
+ catch (e) {
88
+ return {
89
+ data: { error: e instanceof Error ? e.message : String(e) },
90
+ isError: true,
91
+ };
92
+ }
93
+ }
94
+ export async function handleGetPrefs(file, user, keys) {
95
+ if (!file) {
96
+ return {
97
+ data: { error: "file parameter is required" },
98
+ isError: true,
99
+ };
100
+ }
101
+ const adbPath = resolveAdbPath();
102
+ if (!adbPath) {
103
+ return {
104
+ data: {
105
+ error: "adb not found. Set ANDROID_HOME or install Android SDK platform-tools.",
106
+ },
107
+ isError: true,
108
+ };
109
+ }
110
+ try {
111
+ const readResult = await readPrefsFile(adbPath, file, user);
112
+ if ("error" in readResult) {
113
+ return {
114
+ data: { error: readResult.error },
115
+ isError: true,
116
+ };
117
+ }
118
+ const parseResult = parsePrefsXml(readResult.xml);
119
+ if ("parseError" in parseResult) {
120
+ return {
121
+ data: { error: parseResult.parseError },
122
+ isError: true,
123
+ };
124
+ }
125
+ let entries = parseResult.entries;
126
+ // Filter to specified keys if provided.
127
+ if (keys && keys.length > 0) {
128
+ const keySet = new Set(keys);
129
+ entries = entries.filter((e) => keySet.has(e.key));
130
+ }
131
+ // Total = entries after the keys filter (the set the user actually asked for);
132
+ // returned = what survived the 64KB byte cap below.
133
+ const totalEntries = entries.length;
134
+ const deviceTruncated = !!readResult.truncated;
135
+ const { entries: returnedEntries, truncated: responseTruncated, droppedKeys } = capPrefsEntries(entries, file, readResult.user);
136
+ return {
137
+ data: {
138
+ file,
139
+ user: readResult.user,
140
+ entries: returnedEntries,
141
+ total_entries: totalEntries,
142
+ returned_entries: returnedEntries.length,
143
+ ...(deviceTruncated ? { device_read_truncated: true } : {}),
144
+ ...(responseTruncated ? { response_truncated: true } : {}),
145
+ ...(droppedKeys.length > 0 ? { dropped_keys: droppedKeys } : {}),
146
+ ...(deviceTruncated || responseTruncated
147
+ ? {
148
+ note: `${deviceTruncated ? "Device file exceeded 256KB and was truncated. " : ""}${responseTruncated ? "Response truncated to 64KB. " : ""}${droppedKeys.length > 0 ? `${droppedKeys.length} entries were individually too large to include (see dropped_keys). ` : ""}Use keys parameter to filter to specific entries or search_prefs to find what you need.`,
149
+ }
150
+ : {}),
151
+ privacy_note: "Preference values can include user, team, and org identifiers; review before sharing.",
152
+ },
153
+ isError: false,
154
+ };
155
+ }
156
+ catch (e) {
157
+ return {
158
+ data: { error: e instanceof Error ? e.message : String(e) },
159
+ isError: true,
160
+ };
161
+ }
162
+ }
163
+ export async function handleSearchPrefs(query, user) {
164
+ if (!query) {
165
+ return {
166
+ data: { error: "query parameter is required" },
167
+ isError: true,
168
+ };
169
+ }
170
+ const adbPath = resolveAdbPath();
171
+ if (!adbPath) {
172
+ return {
173
+ data: {
174
+ error: "adb not found. Set ANDROID_HOME or install Android SDK platform-tools.",
175
+ },
176
+ isError: true,
177
+ };
178
+ }
179
+ try {
180
+ const { results, truncated, skipped, user: resolvedUser } = await searchPrefs(adbPath, query, user);
181
+ const response = {
182
+ query,
183
+ user: resolvedUser,
184
+ available_users: availableUsers(),
185
+ results,
186
+ };
187
+ if (truncated)
188
+ response.truncated = true;
189
+ if (skipped && skipped.length > 0)
190
+ response.skipped = skipped;
191
+ response.privacy_note =
192
+ "Preference values can include user, team, and org identifiers; review before sharing.";
193
+ return {
194
+ data: response,
195
+ isError: false,
196
+ };
197
+ }
198
+ catch (e) {
199
+ return {
200
+ data: { error: e instanceof Error ? e.message : String(e) },
201
+ isError: true,
202
+ };
203
+ }
204
+ }
@@ -9,9 +9,10 @@ export interface EnableDeps {
9
9
  runBackfill: () => Promise<unknown>;
10
10
  ping: () => Promise<Record<string, unknown>>;
11
11
  sleep: (ms: number) => Promise<void>;
12
+ onDeviceSwitch: () => void;
12
13
  }
13
14
  export interface EnableOutcome {
14
15
  body: Record<string, unknown>;
15
16
  enabled: boolean;
16
17
  }
17
- export declare function runSessionEnable(timeoutMinutes: number, deps: EnableDeps): Promise<EnableOutcome>;
18
+ export declare function runSessionEnable(timeoutMinutes: number, deviceSerial: string | null, deps: EnableDeps): Promise<EnableOutcome>;
@@ -2,8 +2,8 @@
2
2
  // this is the whole latency of a normal enable), then two patient retries to
3
3
  // absorb real server startup.
4
4
  const PING_WAITS_MS = [500, 1000, 1000];
5
- export async function runSessionEnable(timeoutMinutes, deps) {
6
- const { device, destroyStream, connectStream, isStreamConnected, resetDbState, startSpool, runBackfill, ping, sleep, } = deps;
5
+ export async function runSessionEnable(timeoutMinutes, deviceSerial, deps) {
6
+ const { device, destroyStream, connectStream, isStreamConnected, resetDbState, startSpool, runBackfill, ping, sleep, onDeviceSwitch, } = deps;
7
7
  // Tear down the old stream (and its reconnect loop) FIRST, then drop all cached
8
8
  // transport state so this enable starts clean. Without the reset, a stale adb
9
9
  // forward (device end dead after an idle timeout or a replug) makes ensureForward()
@@ -15,6 +15,29 @@ export async function runSessionEnable(timeoutMinutes, deps) {
15
15
  // A re-enable may be a different device or a re-armed profile, so drop the cached DB
16
16
  // user set + sqlite path; the next DB tool call re-detects the profiles fresh.
17
17
  resetDbState();
18
+ // Pin which device this session targets BEFORE any adb call. selectDevice sets
19
+ // process.env.ANDROID_SERIAL once; every later adb call site inherits it. An ambiguous
20
+ // choice (multiple devices, no serial) or an unattached explicit serial short-circuits
21
+ // here with the device list, before ensureForward touches the wrong device.
22
+ const selection = device.selectDevice?.(deviceSerial);
23
+ if (selection && !selection.ok) {
24
+ return {
25
+ enabled: false,
26
+ body: {
27
+ // The transport error is a neutral core; the MCP body appends agent-facing retry guidance.
28
+ error: `${selection.error} Retry _radar_session_enable with device_serial set to one of them. If you cannot tell which device the user wants, ask them before retrying.`,
29
+ devices: selection.devices,
30
+ enabled: false,
31
+ platform: device.platform,
32
+ },
33
+ };
34
+ }
35
+ // A switch to a different device makes the prior session's device-scoped state
36
+ // (buffers, spool, capture, pulled DBs) belong to the wrong hardware, so reset it
37
+ // before forwarding. A same-device re-enable skips this: spool continuity is intended.
38
+ if (selection && selection.ok && selection.switched) {
39
+ onDeviceSwitch();
40
+ }
18
41
  if (!device.ensureForward()) {
19
42
  const reason = device.getLastForwardError?.() ?? null;
20
43
  return {
@@ -83,12 +106,16 @@ export async function runSessionEnable(timeoutMinutes, deps) {
83
106
  },
84
107
  };
85
108
  }
109
+ const selected = device.getSelectedDevice?.() ?? null;
86
110
  return {
87
111
  enabled: true,
88
112
  body: {
89
113
  enabled: true,
90
114
  platform: device.platform,
91
115
  stream_connected: isStreamConnected(),
116
+ ...(selected
117
+ ? { device_serial: selected.serial, device_label: selected.label }
118
+ : {}),
92
119
  // The broadcast failed but the server answered (armed by a prior session).
93
120
  // activate()'s success branch never ran, so the logcat capture is not
94
121
  // armed: get_recent_logs degrades to the device ring for this session.
@@ -2,6 +2,7 @@ import { spawnSync } from "child_process";
2
2
  import fs from "fs";
3
3
  import os from "os";
4
4
  import path from "path";
5
+ import { RADAR_VERSION } from "../shared/constants.js";
5
6
  import { getCaptureFilePath, readTailBytes } from "../shared/logcat-capture.js";
6
7
  /**
7
8
  * `capture_snapshot` composer: bundles everything Radar has seen into a
@@ -34,6 +35,7 @@ This directory is a point-in-time bundle of Radar state.
34
35
 
35
36
  Files:
36
37
  - bundle.json: device-side network/RTM/clog/trace buffers, counts, and metadata.
38
+ Its mcp_version field records which @slack/radar-mcp produced this bundle.
37
39
  - logcat.tail.log (optional): last N lines of the on-device logcat capture.
38
40
  - screenshot.png (optional): current screen.
39
41
 
@@ -241,7 +243,10 @@ export async function createSnapshot(device, fetchBuffer, opts = {}, now = Date.
241
243
  screenshot: screenshotCaptured,
242
244
  };
243
245
  const bundle = {
244
- version: 2,
246
+ // Format version of this bundle's schema — not the Radar version, which
247
+ // is mcp_version below. Named to keep the two unmistakable in a shared file.
248
+ bundle_format_version: 2,
249
+ mcp_version: RADAR_VERSION,
245
250
  timestamp: now,
246
251
  platform: device.platform,
247
252
  active_user_id: device.getActiveUserId(),
package/dist/mcp/tools.js CHANGED
@@ -25,6 +25,8 @@ export const SERVER_INSTRUCTIONS = [
25
25
  '- "did I get X" / "did X happen" -> search(query="X") across ALL buffers, not just one',
26
26
  '- "everything since I enabled" / "the whole session" / "what did I miss" -> query_session',
27
27
  '- "check the debug logs" -> get_recent_logs (tag is OPTIONAL: pass tag="FKDebug" to filter, or omit it for all recent lines)',
28
+ '- "what feature-flag overrides are set?" / "check debug_features" -> search_prefs(query="X") or get_prefs(file="debug_features_...xml"). This shows MANUAL OVERRIDES only, not effective flag state: debug_features_*.xml holds only flags the debug menu overrode, and an override is deleted once it matches the server value. A flag missing from this file can still be ON server-side -- absence means "no override," never "disabled."',
29
+ '- "what did the app remember" / "what is cached in prefs" / "what team_prefs are set" -> list_prefs then get_prefs',
28
30
  '- "save this" / "file this as a bug" / "share this" / "bundle this" / "attach to ticket" / "give me a repro" / "snapshot this" / "preserve this" / "hold this state" / "save what you just saw" -> capture_snapshot',
29
31
  "",
30
32
  "Key behaviors:",
@@ -38,10 +40,17 @@ export const SERVER_INSTRUCTIONS = [
38
40
  " build can run on more than one user (personal=0, plus a work profile or secondary user),",
39
41
  " and only the first to bind the socket wins. If events seem to come from the wrong app, tell",
40
42
  " the user which profile is bound and use list_profiles + activate_for_user to switch.",
43
+ "- MULTIPLE DEVICES: with more than one device attached, enable fails and returns the list of",
44
+ " attached serials. Retry _radar_session_enable with device_serial set to one of them. When the",
45
+ " intent is unclear (you cannot tell which device the user means), ask which device before retrying;",
46
+ " do not guess. The enable success response names the bound device via device_label, so confirm it",
47
+ " matches what the user expected. The picked device applies to every tool for the whole session. Do",
48
+ " not confuse this with profiles: profiles are separate users on ONE device (personal vs work), while",
49
+ " devices are separate hardware.",
41
50
  "- Screenshots default to 720px. Use full_res=true only when detail matters.",
42
51
  "- Setup: /slack-radar-setup",
43
52
  "- Manual enable (no skill): adb shell am broadcast -a slack.debug.ENABLE_RADAR --ei timeout_minutes 5 -p com.Slack.internal.debug",
44
- " Then: adb forward tcp:8099 localabstract:slack-radar",
53
+ " Then: adb forward tcp:8099 localabstract:slack-radar (prefix adb -s <serial> when multiple devices are attached)",
45
54
  "",
46
55
  "WEB DASHBOARD (/radar-ui):",
47
56
  "A browser-based dashboard (http://localhost:8100) shows the same live device data as",
@@ -119,7 +128,7 @@ export const SERVER_INSTRUCTIONS = [
119
128
  export const TOOL_DEFINITIONS = [
120
129
  {
121
130
  name: "ping",
122
- description: "Check if Slack Radar is running. Returns uptime, buffer sizes, remaining session time, stream status, and which app/profile is bound: android_user_id (0 = personal, non-zero = a secondary user such as a work profile), profile ('personal'/'secondary'), and package.",
131
+ description: "Check if Slack Radar is running. Returns uptime, buffer sizes, remaining session time, stream status, the Radar MCP tool version (mcp_version), and which app/profile is bound: android_user_id (0 = personal, non-zero = a secondary user such as a work profile), profile ('personal'/'secondary'), and package.",
123
132
  inputSchema: {
124
133
  type: "object",
125
134
  properties: {
@@ -361,6 +370,10 @@ export const TOOL_DEFINITIONS = [
361
370
  type: "object",
362
371
  properties: {
363
372
  timeout_minutes: { type: "number", description: "Device-side auto-shutdown timeout in minutes (default: 5)" },
373
+ device_serial: {
374
+ type: "string",
375
+ description: "Target device serial from adb devices. Optional; auto-selected when exactly one device is attached. When multiple devices are attached the enable fails with the list; retry with one of the listed serials.",
376
+ },
364
377
  },
365
378
  },
366
379
  annotations: { readOnlyHint: false, idempotentHint: true },
@@ -504,6 +517,56 @@ export const TOOL_DEFINITIONS = [
504
517
  },
505
518
  annotations: { readOnlyHint: true },
506
519
  },
520
+ {
521
+ name: "list_prefs",
522
+ description: "List the app's SharedPreferences XML files (including feature-flag files like debug_features_*.xml, which holds manual overrides, and easy_features_*.xml, the persisted server snapshot), with file sizes and the Android user they were read from.",
523
+ inputSchema: {
524
+ type: "object",
525
+ properties: {
526
+ user: {
527
+ type: "string",
528
+ pattern: "^[0-9]*$",
529
+ description: "Android user ID to read (0=personal, 10+=work profile). If omitted, uses the first available user.",
530
+ },
531
+ },
532
+ },
533
+ annotations: { readOnlyHint: true },
534
+ },
535
+ {
536
+ name: "get_prefs",
537
+ description: "Read a SharedPreferences file, parse it, and return its entries (key, type, value). When keys are provided, filter to those keys only (exact match). Reads the on-disk XML, which can lag the app's live in-memory state by the async-write window, so a value may be slightly stale. debug_features_* holds manual overrides only -- a flag absent there means no override was set, not that the flag is off. easy_features_*/feature_flags_* is the persisted server snapshot, not an override list -- a hit there is the server's value, still subject to the same write-lag caveat.",
538
+ inputSchema: {
539
+ type: "object",
540
+ properties: {
541
+ file: { type: "string", description: "Filename from list_prefs, e.g. 'default_preferences.xml'" },
542
+ user: {
543
+ type: "string",
544
+ pattern: "^[0-9]*$",
545
+ description: "Android user ID (0=personal, 10+=work profile). If omitted, uses the first available user.",
546
+ },
547
+ keys: { type: "array", items: { type: "string" }, description: "If provided, filter results to only these keys (exact match). Omit to return all entries." },
548
+ },
549
+ required: ["file"],
550
+ },
551
+ annotations: { readOnlyHint: true },
552
+ },
553
+ {
554
+ name: "search_prefs",
555
+ description: "Search SharedPreferences across all files for a user. Performs case-insensitive substring search on key names and stringified values. Returns per-file match results. Reads the on-disk XML, which can lag the app's live in-memory state by the async-write window, so a value may be slightly stale. A hit in debug_features_* is a manual override -- no hit means no override, not that the flag is off. A hit in easy_features_*/feature_flags_* is the server's persisted value, not an override.",
556
+ inputSchema: {
557
+ type: "object",
558
+ properties: {
559
+ query: { type: "string", description: "Search substring (case-insensitive)" },
560
+ user: {
561
+ type: "string",
562
+ pattern: "^[0-9]*$",
563
+ description: "Android user ID (0=personal, 10+=work profile). If omitted, uses the first available user.",
564
+ },
565
+ },
566
+ required: ["query"],
567
+ },
568
+ annotations: { readOnlyHint: true },
569
+ },
507
570
  ];
508
571
  /**
509
572
  * Check whether a tool call should be blocked by the session gate.
@@ -1,4 +1,4 @@
1
- import type { DeviceTransport, LogResult } from "./transport.js";
1
+ import type { DeviceInfo, DeviceTransport, LogResult } from "./transport.js";
2
2
  /**
3
3
  * Resolve the adb binary. MCP servers spawned from GUI launchers (Spotlight,
4
4
  * Raycast, Dock) do not inherit the user's shell PATH, so a bare `adb` call
@@ -18,6 +18,19 @@ export declare function resolveAdbPath(): string | null;
18
18
  * "10", which is often a work profile, but the id alone cannot prove that).
19
19
  */
20
20
  export declare function parseUserFromPsOutput(psOutput: string): string;
21
+ /**
22
+ * Parse `adb devices -l` output into a list of attached devices. Skips the
23
+ * "List of devices attached" header and the daemon-restart preamble adb sometimes
24
+ * prints ("* daemon not running; starting now at tcp:5037", "* daemon started
25
+ * successfully"). Each real entry is "<serial> <state> [key:value ...]"; the label
26
+ * comes from the model: field with underscores turned to spaces (adb renders spaces
27
+ * in model names as underscores), falling back to the serial when no model is present.
28
+ */
29
+ export declare function parseAdbDevicesOutput(raw: string): {
30
+ serial: string;
31
+ label: string;
32
+ state: string;
33
+ }[];
21
34
  export declare class AndroidTransport implements DeviceTransport {
22
35
  readonly platform = "android";
23
36
  private portForwarded;
@@ -26,7 +39,10 @@ export declare class AndroidTransport implements DeviceTransport {
26
39
  private radarEnabled;
27
40
  private lastForwardError;
28
41
  private lastActivateError;
42
+ private selectedDevice;
29
43
  ensureForward(): boolean;
44
+ private rebuildForward;
45
+ reassertForward(): boolean;
30
46
  getLastForwardError(): string | null;
31
47
  activate(timeoutMinutes: number): void;
32
48
  getLastActivateError(): string | null;
@@ -53,5 +69,21 @@ export declare class AndroidTransport implements DeviceTransport {
53
69
  label: string;
54
70
  }[];
55
71
  activateForUser(userId: string, timeoutMinutes: number): void;
72
+ listDevices(): DeviceInfo[] | null;
73
+ private reconcileSelectedDevice;
74
+ selectDevice(serial: string | null): {
75
+ ok: true;
76
+ serial: string | null;
77
+ switched?: boolean;
78
+ } | {
79
+ ok: false;
80
+ error: string;
81
+ devices: DeviceInfo[];
82
+ };
83
+ getSelectedDevice(): {
84
+ serial: string;
85
+ label: string;
86
+ } | null;
87
+ private pin;
56
88
  private detectDebugBuildUser;
57
89
  }