@slack/radar-mcp 1.11.0 → 1.13.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 +12 -2
- package/dist/mcp/api-paths.js +2 -0
- package/dist/mcp/flags-tools.d.ts +71 -0
- package/dist/mcp/flags-tools.js +158 -0
- package/dist/mcp/index.js +103 -5
- package/dist/mcp/prefs-tools.d.ts +15 -0
- package/dist/mcp/prefs-tools.js +204 -0
- package/dist/mcp/session-enable.d.ts +2 -1
- package/dist/mcp/session-enable.js +29 -2
- package/dist/mcp/snapshot.js +6 -1
- package/dist/mcp/sources-gate.d.ts +23 -0
- package/dist/mcp/sources-gate.js +63 -0
- package/dist/mcp/tools.js +102 -2
- package/dist/shared/android.d.ts +33 -1
- package/dist/shared/android.js +203 -6
- package/dist/shared/constants.d.ts +8 -0
- package/dist/shared/constants.js +13 -1
- package/dist/shared/db.d.ts +21 -3
- package/dist/shared/db.js +89 -23
- package/dist/shared/feature-flags.d.ts +6 -0
- package/dist/shared/feature-flags.js +17 -0
- package/dist/shared/prefs.d.ts +78 -0
- package/dist/shared/prefs.js +416 -0
- package/dist/shared/transport.d.ts +68 -0
- package/dist/web/log-session.d.ts +13 -0
- package/dist/web/log-session.js +16 -0
- package/dist/web/public/index.html +129 -3
- package/dist/web/public/next/app.js +82 -4
- package/dist/web/public/next/feed.js +270 -14
- package/dist/web/public/next/filter.js +200 -0
- package/dist/web/public/next/flags.js +179 -0
- package/dist/web/public/next/prefs.js +399 -0
- package/dist/web/public/next/registry.js +16 -6
- package/dist/web/public/next/store.js +250 -11
- package/dist/web/server.js +267 -7
- package/dist/web/spec.d.ts +7 -7
- package/dist/web/spec.js +15 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,9 +47,10 @@ Opens `http://localhost:8100` automatically. Set `SLACK_RADAR_WEB_PORT` to use a
|
|
|
47
47
|
* **Traces** — performance trace spans with durations, click one for its timing and tags
|
|
48
48
|
* **Logs** — device logcat, filtered to the Slack app (switch app or clear the filter)
|
|
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
|
+
* **Preferences** — read-only browser for the on-device SharedPreferences files (pick a file, browse its keys, or search across every file at once).
|
|
50
51
|
* **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
52
|
|
|
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.
|
|
53
|
+
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
54
|
|
|
54
55
|
### Screen overlay
|
|
55
56
|
|
|
@@ -81,7 +82,7 @@ Radar starts **disabled** each session. All tools except `ping` return an error
|
|
|
81
82
|
|
|
82
83
|
| Tool | Description |
|
|
83
84
|
|---|---|
|
|
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. |
|
|
85
|
+
| `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
86
|
| `get_recent_network_calls` | HTTP call summaries: method, URL, status code, duration. Filterable by URL substring and status code. |
|
|
86
87
|
| `get_network_call_detail` | Full request/response headers and bodies for a specific call (gzip/brotli decompressed). |
|
|
87
88
|
| `get_recent_rtm_events` | RTM event summaries: type, direction, channel, timestamp. Filterable by type, direction, channel. Uses subtypes (e.g. `message_changed`, not `message`). |
|
|
@@ -102,6 +103,12 @@ Radar starts **disabled** each session. All tools except `ping` return an error
|
|
|
102
103
|
| `list_databases` | List the app's on-device SQLite databases. Read-only. |
|
|
103
104
|
| `list_tables` | List the tables in a given on-device database, with row counts. Read-only. |
|
|
104
105
|
| `query_database` | Run a read-only query (SELECT, WITH, EXPLAIN, VALUES, PRAGMA) against a copy of an on-device database pulled to the host. |
|
|
106
|
+
| `list_prefs` | List the app's on-device SharedPreferences files. Read-only. |
|
|
107
|
+
| `get_prefs` | Read a preferences file's keys and values, optionally filtered to specific keys. |
|
|
108
|
+
| `search_prefs` | Search preference keys and values across every file by a substring. |
|
|
109
|
+
| `list_feature_flags` | List every feature flag with its live effective value and override status. Optionally filtered to just the overridden ones. |
|
|
110
|
+
| `search_feature_flags` | Case-insensitive substring search on feature flag names, against the same live list as `list_feature_flags`. |
|
|
111
|
+
| `get_feature_flag` | Look up one feature flag by its exact key. Returns one row per scope (authenticated/unauthenticated). |
|
|
105
112
|
| `clear_buffers` | Clear all captured buffers (network, RTM, clog, trace) on the device and locally. |
|
|
106
113
|
| `open_radar_dashboard` | Author or refine a custom live dashboard tab from a spec (source, filters, widgets, alerts). Suggested when a request is not covered by the pre-built tabs; not auto-invoked. Returns the dashboard URL; debug builds only, local only. |
|
|
107
114
|
| `_radar_session_enable` | Enable radar for the session. Called by `/radar-enable` skill. |
|
|
@@ -143,6 +150,8 @@ What gets captured depends on the in-app server implementation. The MCP server i
|
|
|
143
150
|
* **Clogs**: Analytics interceptor. Ring buffer: 1000 events. Persists across radar activation cycles.
|
|
144
151
|
* **Traces**: Performance span observer. Ring buffer: 2000 spans. Persists across radar activation cycles.
|
|
145
152
|
* **SQLite database** (Database tab, web dashboard only): when you open a database, a read-only **plaintext** copy of that on-device store (message text, request/response bodies, user/channel/team IDs) is pulled to a temp directory **on your own machine** (`os.tmpdir()/slack-radar-db-<port>`, files mode 0600). Auto-deleted when the dashboard process stops.
|
|
153
|
+
* **SharedPreferences** (`list_prefs`/`get_prefs`/`search_prefs`, and the Preferences tab): read directly off the device over `adb`, no local copy written. Files can contain feature flag overrides, cached team/org/channel IDs, and other app state.
|
|
154
|
+
* **Feature flags** (`list_feature_flags`/`search_feature_flags`/`get_feature_flag`): read directly off the device over `adb`, no local copy written. Shows every flag's live effective value and whether it is locally overridden.
|
|
146
155
|
|
|
147
156
|
The network, RTM, clog, and trace captures are in-memory ring buffers. The Database tab is the exception: it writes a plaintext copy of the selected on-device database to a temp file on your host for the duration of the session. Review before sharing anything from it.
|
|
148
157
|
|
|
@@ -158,6 +167,7 @@ This tool captures unredacted network traffic from your debug Slack build, inclu
|
|
|
158
167
|
* Analytics (clog) events serialized as JSON
|
|
159
168
|
* Screenshots and short screen recordings on demand
|
|
160
169
|
* Device logs (the app's own debug buffer, with a logcat fallback), optionally filtered by tag
|
|
170
|
+
* SharedPreferences files, including feature flag overrides and cached team/org/channel IDs
|
|
161
171
|
|
|
162
172
|
Auth tokens and session cookies will appear in captured data. Captured data flows to your MCP client (Claude Code), which may send relevant portions to the configured AI provider per its own data handling policy.
|
|
163
173
|
|
package/dist/mcp/api-paths.js
CHANGED
|
@@ -102,6 +102,8 @@ export function buildApiPath(name, args) {
|
|
|
102
102
|
params.set("limit", String(a.limit));
|
|
103
103
|
return `/api/search?${params.toString()}`;
|
|
104
104
|
}
|
|
105
|
+
// list_feature_flags/search_feature_flags/get_feature_flag are NOT here -- see
|
|
106
|
+
// flags-tools.ts's file header for why they fetch and filter host-side instead.
|
|
105
107
|
default:
|
|
106
108
|
return null;
|
|
107
109
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shares one in-flight fetch of the flag list across the three tools (a model doing "list,
|
|
3
|
+
* then search, then get" in one turn would otherwise pay a device round-trip per call).
|
|
4
|
+
* Caches the PROMISE, not the resolved value, so a concurrent burst awaits the same fetch.
|
|
5
|
+
* An error response is not kept: the next call after it settles fetches fresh.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createFeatureFlagsCache<T extends {
|
|
8
|
+
error?: string;
|
|
9
|
+
}>(fetcher: () => Promise<T>, ttlMs: number, now?: () => number): {
|
|
10
|
+
call: () => Promise<T>;
|
|
11
|
+
clear: () => void;
|
|
12
|
+
};
|
|
13
|
+
export interface FeatureFlagRow {
|
|
14
|
+
key: string;
|
|
15
|
+
scope?: string;
|
|
16
|
+
enabled?: boolean | string;
|
|
17
|
+
is_overridden?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface FeatureFlagsListResponse {
|
|
20
|
+
feature_flags?: FeatureFlagRow[];
|
|
21
|
+
total_captured?: number;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Normalize the `overridden` tool arg at the handler boundary. The SDK casts args without
|
|
26
|
+
* enforcing the schema, so a model can send the string "false"; strict comparison downstream
|
|
27
|
+
* would then match nothing and return zero flags silently, the very bug class these tools
|
|
28
|
+
* route around. Unrecognized values mean "no filter".
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeOverriddenArg(value: unknown): boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The complete flag list, optionally filtered by override status. `overridden` is applied
|
|
33
|
+
* host-side (see the file header for why): both true and false are filtered identically here,
|
|
34
|
+
* so the tool's behavior does not depend on which direction of the device's own filter
|
|
35
|
+
* currently works.
|
|
36
|
+
*/
|
|
37
|
+
export declare function listFeatureFlags(response: FeatureFlagsListResponse, overridden?: boolean): {
|
|
38
|
+
data: unknown;
|
|
39
|
+
isError: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Case-insensitive substring match on flag key against an already-fetched device list.
|
|
43
|
+
* Returns the error verbatim if the device call itself failed, so the caller does not need
|
|
44
|
+
* to duplicate that check.
|
|
45
|
+
*/
|
|
46
|
+
export declare function searchFeatureFlags(response: FeatureFlagsListResponse, query: string): {
|
|
47
|
+
data: unknown;
|
|
48
|
+
isError: boolean;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Exact-key lookup against an already-fetched device list. A miss (no row matches the key, or
|
|
52
|
+
* a scope is given but absent for this key) is reported as `isError: true` with a message
|
|
53
|
+
* naming the key or the scopes that do exist -- a model calling this tool needs to tell "your
|
|
54
|
+
* key or scope was wrong" apart from "found it, here are zero rows" (which never happens: a
|
|
55
|
+
* found key always returns at least one row), so treating a miss as an error is the correct
|
|
56
|
+
* and only outcome, not a fallback.
|
|
57
|
+
*
|
|
58
|
+
* A key is NOT unique on its own: every flag on a real device is listed once per scope
|
|
59
|
+
* (authenticated/unauthenticated), so a bare key lookup has two rows, not one (verified live,
|
|
60
|
+
* repeatedly, against a real Fold: every key duplicated exactly once, sometimes with
|
|
61
|
+
* DIFFERENT enabled/is_overridden values between the two scopes). ALWAYS returns a `rows`
|
|
62
|
+
* array on success, one element when the key is unambiguous, so the response shape never
|
|
63
|
+
* depends on how many scopes happen to exist for a given key -- a caller reads `data.rows[0]`
|
|
64
|
+
* (or filters/maps over `data.rows`) the same way regardless of count, rather than branching
|
|
65
|
+
* on whether it got a bare object or a wrapper.
|
|
66
|
+
*/
|
|
67
|
+
export declare function getFeatureFlag(response: FeatureFlagsListResponse, key: string, scope?: string): {
|
|
68
|
+
data: unknown;
|
|
69
|
+
isError: boolean;
|
|
70
|
+
};
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Handler dispatch for list_feature_flags, search_feature_flags, and get_feature_flag. None of
|
|
2
|
+
// the three trust the device's own query params: verified live against a real Fold that
|
|
3
|
+
// ?overridden=false is silently ignored (the device build truthy-checks the query string
|
|
4
|
+
// "false", which is always truthy in JS/Kotlin-string terms, so it returns the COMPLETE set
|
|
5
|
+
// instead of filtering -- ?overridden=true works correctly, which is what let this slip past
|
|
6
|
+
// review). The MCP tool cannot trust one boolean direction and not the other, so all three
|
|
7
|
+
// fetch the unfiltered route and filter/shape entirely host-side, mirroring how the Feature
|
|
8
|
+
// Flags dashboard tab filters client-side after one full fetch. A device-side fix is the real
|
|
9
|
+
// fix (tracked separately); this stays the correct behavior either way once that ships, since
|
|
10
|
+
// filtering an already-correct list is a no-op.
|
|
11
|
+
import { friendlyFeatureFlagError } from "../shared/feature-flags.js";
|
|
12
|
+
/**
|
|
13
|
+
* Shares one in-flight fetch of the flag list across the three tools (a model doing "list,
|
|
14
|
+
* then search, then get" in one turn would otherwise pay a device round-trip per call).
|
|
15
|
+
* Caches the PROMISE, not the resolved value, so a concurrent burst awaits the same fetch.
|
|
16
|
+
* An error response is not kept: the next call after it settles fetches fresh.
|
|
17
|
+
*/
|
|
18
|
+
export function createFeatureFlagsCache(fetcher, ttlMs, now = Date.now) {
|
|
19
|
+
let cached = null;
|
|
20
|
+
return {
|
|
21
|
+
call: async () => {
|
|
22
|
+
const t = now();
|
|
23
|
+
if (cached && t - cached.at < ttlMs) {
|
|
24
|
+
return cached.promise;
|
|
25
|
+
}
|
|
26
|
+
const promise = fetcher();
|
|
27
|
+
cached = { at: t, promise };
|
|
28
|
+
const response = await promise;
|
|
29
|
+
if (response.error) {
|
|
30
|
+
cached = null;
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
},
|
|
34
|
+
clear: () => {
|
|
35
|
+
cached = null;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Both tools take the already-parsed device response (the caller runs callRadar first) so
|
|
40
|
+
// neither one owns forward/retry/error-shaping -- that stays centralized in callRadar, same
|
|
41
|
+
// division of labor as every other proxied tool in index.ts. Passing the response in (not a
|
|
42
|
+
// device handle) also makes these two functions pure and unit-testable without a fake transport.
|
|
43
|
+
/**
|
|
44
|
+
* Filter response.feature_flags down to well-formed rows (a real object with a string `key`).
|
|
45
|
+
* The response comes from an already-JSON-parsed device body with a TypeScript cast, not a
|
|
46
|
+
* runtime schema check, so a version-skewed or misbehaving device build (or a `feature_flags`
|
|
47
|
+
* that is not even an array) must degrade to "zero flags" rather than throw inside a tool
|
|
48
|
+
* handler. Mirrors the same defensiveness the web dashboard's handleFlags applies
|
|
49
|
+
* (`Array.isArray(j.feature_flags)`) before trusting the device body.
|
|
50
|
+
*/
|
|
51
|
+
function wellFormedRows(response) {
|
|
52
|
+
const raw = response.feature_flags;
|
|
53
|
+
if (!Array.isArray(raw))
|
|
54
|
+
return [];
|
|
55
|
+
return raw.filter((f) => typeof f === "object" && f !== null && typeof f.key === "string");
|
|
56
|
+
}
|
|
57
|
+
// Only a real boolean `true` counts as overridden. `!!f.is_overridden` would also match a
|
|
58
|
+
// string like `"false"` (truthy in JS) -- the exact class of bug this filter exists to work
|
|
59
|
+
// around -- so this normalizes strictly instead of coercing.
|
|
60
|
+
function isOverridden(f) {
|
|
61
|
+
return f.is_overridden === true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalize the `overridden` tool arg at the handler boundary. The SDK casts args without
|
|
65
|
+
* enforcing the schema, so a model can send the string "false"; strict comparison downstream
|
|
66
|
+
* would then match nothing and return zero flags silently, the very bug class these tools
|
|
67
|
+
* route around. Unrecognized values mean "no filter".
|
|
68
|
+
*/
|
|
69
|
+
export function normalizeOverriddenArg(value) {
|
|
70
|
+
if (value === true || value === "true")
|
|
71
|
+
return true;
|
|
72
|
+
if (value === false || value === "false")
|
|
73
|
+
return false;
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The complete flag list, optionally filtered by override status. `overridden` is applied
|
|
78
|
+
* host-side (see the file header for why): both true and false are filtered identically here,
|
|
79
|
+
* so the tool's behavior does not depend on which direction of the device's own filter
|
|
80
|
+
* currently works.
|
|
81
|
+
*/
|
|
82
|
+
export function listFeatureFlags(response, overridden) {
|
|
83
|
+
if (response.error) {
|
|
84
|
+
return { data: { error: friendlyFeatureFlagError(response.error) }, isError: true };
|
|
85
|
+
}
|
|
86
|
+
const all = wellFormedRows(response);
|
|
87
|
+
const feature_flags = overridden === undefined ? all : all.filter((f) => isOverridden(f) === overridden);
|
|
88
|
+
// total_flags is always the full list size; returned_flags counts the filtered result, same
|
|
89
|
+
// split as the prefs tools' total_entries vs returned_entries.
|
|
90
|
+
return {
|
|
91
|
+
data: { feature_flags, total_flags: all.length, returned_flags: feature_flags.length },
|
|
92
|
+
isError: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Case-insensitive substring match on flag key against an already-fetched device list.
|
|
97
|
+
* Returns the error verbatim if the device call itself failed, so the caller does not need
|
|
98
|
+
* to duplicate that check.
|
|
99
|
+
*/
|
|
100
|
+
export function searchFeatureFlags(response, query) {
|
|
101
|
+
if (response.error) {
|
|
102
|
+
return { data: { error: friendlyFeatureFlagError(response.error) }, isError: true };
|
|
103
|
+
}
|
|
104
|
+
const all = wellFormedRows(response);
|
|
105
|
+
const q = query.toLowerCase();
|
|
106
|
+
const matches = all.filter((f) => f.key.toLowerCase().includes(q));
|
|
107
|
+
return {
|
|
108
|
+
data: {
|
|
109
|
+
query,
|
|
110
|
+
matches,
|
|
111
|
+
total_flags: all.length,
|
|
112
|
+
matched_flags: matches.length,
|
|
113
|
+
},
|
|
114
|
+
isError: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Exact-key lookup against an already-fetched device list. A miss (no row matches the key, or
|
|
119
|
+
* a scope is given but absent for this key) is reported as `isError: true` with a message
|
|
120
|
+
* naming the key or the scopes that do exist -- a model calling this tool needs to tell "your
|
|
121
|
+
* key or scope was wrong" apart from "found it, here are zero rows" (which never happens: a
|
|
122
|
+
* found key always returns at least one row), so treating a miss as an error is the correct
|
|
123
|
+
* and only outcome, not a fallback.
|
|
124
|
+
*
|
|
125
|
+
* A key is NOT unique on its own: every flag on a real device is listed once per scope
|
|
126
|
+
* (authenticated/unauthenticated), so a bare key lookup has two rows, not one (verified live,
|
|
127
|
+
* repeatedly, against a real Fold: every key duplicated exactly once, sometimes with
|
|
128
|
+
* DIFFERENT enabled/is_overridden values between the two scopes). ALWAYS returns a `rows`
|
|
129
|
+
* array on success, one element when the key is unambiguous, so the response shape never
|
|
130
|
+
* depends on how many scopes happen to exist for a given key -- a caller reads `data.rows[0]`
|
|
131
|
+
* (or filters/maps over `data.rows`) the same way regardless of count, rather than branching
|
|
132
|
+
* on whether it got a bare object or a wrapper.
|
|
133
|
+
*/
|
|
134
|
+
export function getFeatureFlag(response, key, scope) {
|
|
135
|
+
if (response.error) {
|
|
136
|
+
return { data: { error: friendlyFeatureFlagError(response.error) }, isError: true };
|
|
137
|
+
}
|
|
138
|
+
const all = wellFormedRows(response);
|
|
139
|
+
const byKey = all.filter((f) => f.key === key);
|
|
140
|
+
if (byKey.length === 0) {
|
|
141
|
+
return {
|
|
142
|
+
data: { error: `No flag named "${key}" (case-sensitive, exact match). Use search_feature_flags or list_feature_flags to find the right name.` },
|
|
143
|
+
isError: true,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (scope !== undefined) {
|
|
147
|
+
const exact = byKey.find((f) => f.scope === scope);
|
|
148
|
+
if (!exact) {
|
|
149
|
+
const seenScopes = byKey.map((f) => f.scope ?? "(none)").join(", ");
|
|
150
|
+
return {
|
|
151
|
+
data: { error: `Flag "${key}" exists but not with scope "${scope}". Scopes present for this key: ${seenScopes}.` },
|
|
152
|
+
isError: true,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return { data: { key, rows: [exact] }, isError: false };
|
|
156
|
+
}
|
|
157
|
+
return { data: { key, rows: byKey }, isError: false };
|
|
158
|
+
}
|
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";
|
|
@@ -17,8 +17,11 @@ import { clampLogLimit, shapeLogsResult } from "./logs-result.js";
|
|
|
17
17
|
import { querySession, clampByteCap, toNum } from "./session-query.js";
|
|
18
18
|
import { resolveDetailById } from "./session-detail.js";
|
|
19
19
|
import { runSessionEnable } from "./session-enable.js";
|
|
20
|
+
import { applyEnableOutcome, clearSources, sourceGate } from "./sources-gate.js";
|
|
20
21
|
import { backfillSpool, BACKFILL_SOURCES, makeSerializedRunner, } from "./session-backfill.js";
|
|
21
22
|
import { handleListDatabases, handleListTables, handleQueryDatabase, } from "./db-tools.js";
|
|
23
|
+
import { handleListPrefs, handleGetPrefs, handleSearchPrefs, } from "./prefs-tools.js";
|
|
24
|
+
import { listFeatureFlags, searchFeatureFlags, getFeatureFlag, normalizeOverriddenArg, createFeatureFlagsCache, } from "./flags-tools.js";
|
|
22
25
|
import { cleanupPulledDatabases, initializeDatabasePath, resetDbState, } from "../shared/db.js";
|
|
23
26
|
import { TOOL_DEFINITIONS, SERVER_INSTRUCTIONS, sessionGate } from "./tools.js";
|
|
24
27
|
import { buildApiPath } from "./api-paths.js";
|
|
@@ -330,8 +333,16 @@ async function runMcpServer() {
|
|
|
330
333
|
});
|
|
331
334
|
});
|
|
332
335
|
}
|
|
336
|
+
// Reassert the shared adb forward before every HTTP-based device read. Prefer
|
|
337
|
+
// reassertForward() (repoints the shared port at OUR pinned device even if a separate
|
|
338
|
+
// process silently moved it) over plain ensureForward() (trusts a same-process cache
|
|
339
|
+
// that cannot see another process's repoint). Platforms without a shared host-level
|
|
340
|
+
// forward may omit reassertForward, so this falls back to ensureForward.
|
|
341
|
+
function forwardForRead() {
|
|
342
|
+
return device.reassertForward?.() ?? device.ensureForward();
|
|
343
|
+
}
|
|
333
344
|
async function callRadar(requestPath) {
|
|
334
|
-
if (!
|
|
345
|
+
if (!forwardForRead()) {
|
|
335
346
|
return {
|
|
336
347
|
error: "Port forwarding failed. Ensure a device is connected and the debug build is running.",
|
|
337
348
|
};
|
|
@@ -363,6 +374,23 @@ async function runMcpServer() {
|
|
|
363
374
|
}
|
|
364
375
|
}
|
|
365
376
|
}
|
|
377
|
+
// A model exploring feature flags in one turn tends to call list, then search, then get in
|
|
378
|
+
// quick succession -- each would otherwise pay its own full device round-trip for the exact
|
|
379
|
+
// same ~500-flag x 2-scope payload. A short in-process cache collapses that burst into one
|
|
380
|
+
// fetch. 5s is long enough to cover a multi-tool-call turn but short enough that a flag flipped
|
|
381
|
+
// on-device mid-session (a manual override toggle) is visible again well within a normal pause
|
|
382
|
+
// between turns.
|
|
383
|
+
//
|
|
384
|
+
// Caches the in-flight PROMISE, not just the resolved value: if the MCP client dispatches two
|
|
385
|
+
// of the three feature-flag tools concurrently (nothing about the MCP request handler
|
|
386
|
+
// guarantees serialization), both must await the same underlying fetch instead of each firing
|
|
387
|
+
// its own -- caching only the resolved response would miss this exact burst case, which is the
|
|
388
|
+
// whole reason this cache exists.
|
|
389
|
+
const FEATURE_FLAGS_CACHE_MS = 5000;
|
|
390
|
+
// The cache mechanics live in flags-tools.ts (createFeatureFlagsCache) where they are
|
|
391
|
+
// unit-tested with a fake fetcher; this wires the real callRadar in.
|
|
392
|
+
const featureFlagsCache = createFeatureFlagsCache(() => callRadar("/api/feature_flags"), FEATURE_FLAGS_CACHE_MS);
|
|
393
|
+
const callFeatureFlags = featureFlagsCache.call;
|
|
366
394
|
function textResult(data, isError = false) {
|
|
367
395
|
return {
|
|
368
396
|
content: [
|
|
@@ -377,6 +405,7 @@ async function runMcpServer() {
|
|
|
377
405
|
// --- Tool handlers ---
|
|
378
406
|
async function handleSessionEnable(args) {
|
|
379
407
|
const timeout = args?.timeout_minutes || 5;
|
|
408
|
+
const deviceSerial = args?.device_serial ?? null;
|
|
380
409
|
// The orchestration lives in session-enable.ts (testable without the stdio
|
|
381
410
|
// server this module starts at load); this handler wires the real effects
|
|
382
411
|
// and owns the session flag. sessionEnabled goes true up front so the
|
|
@@ -386,7 +415,10 @@ async function runMcpServer() {
|
|
|
386
415
|
// while the SDK reports an opaque error.
|
|
387
416
|
try {
|
|
388
417
|
sessionEnabled = true;
|
|
389
|
-
|
|
418
|
+
// Off (not stale) during the enable: the previous session's list may not describe this
|
|
419
|
+
// build (same device, upgraded app). Repopulated from the outcome below.
|
|
420
|
+
clearSources();
|
|
421
|
+
const outcome = await runSessionEnable(timeout, deviceSerial, {
|
|
390
422
|
device,
|
|
391
423
|
destroyStream,
|
|
392
424
|
connectStream,
|
|
@@ -401,12 +433,25 @@ async function runMcpServer() {
|
|
|
401
433
|
// under that ceiling.
|
|
402
434
|
ping: () => radarRequest("/api/ping", 2000),
|
|
403
435
|
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
436
|
+
// Only fires on a switch to a different device: the prior device's buffers,
|
|
437
|
+
// spool, capture, and pulled DBs are stale for the new hardware.
|
|
438
|
+
onDeviceSwitch: () => {
|
|
439
|
+
clearLocalBuffers();
|
|
440
|
+
stopSpool();
|
|
441
|
+
stopCapture();
|
|
442
|
+
cleanupPulledDatabases();
|
|
443
|
+
// The old device's declared sources and cached flags do not describe the new one.
|
|
444
|
+
clearSources();
|
|
445
|
+
featureFlagsCache.clear();
|
|
446
|
+
},
|
|
404
447
|
});
|
|
405
448
|
sessionEnabled = outcome.enabled;
|
|
449
|
+
applyEnableOutcome(outcome);
|
|
406
450
|
return textResult(outcome.body, !outcome.enabled);
|
|
407
451
|
}
|
|
408
452
|
catch (e) {
|
|
409
453
|
sessionEnabled = false;
|
|
454
|
+
clearSources();
|
|
410
455
|
destroyStream();
|
|
411
456
|
return textResult({
|
|
412
457
|
error: `Enable failed unexpectedly: ${e.message}`,
|
|
@@ -417,8 +462,10 @@ async function runMcpServer() {
|
|
|
417
462
|
}
|
|
418
463
|
function handleSessionDisable() {
|
|
419
464
|
sessionEnabled = false;
|
|
465
|
+
clearSources();
|
|
420
466
|
destroyStream();
|
|
421
467
|
clearLocalBuffers();
|
|
468
|
+
featureFlagsCache.clear();
|
|
422
469
|
// Explicit disable stops the logcat capture immediately. Without this, the
|
|
423
470
|
// capture would linger up to the capture-idle timeout (15 min) after a
|
|
424
471
|
// deliberate user action saying "I am done", which is surprising and
|
|
@@ -436,7 +483,7 @@ async function runMcpServer() {
|
|
|
436
483
|
}
|
|
437
484
|
async function handleWaitForEvents(args) {
|
|
438
485
|
if (!isStreamConnected()) {
|
|
439
|
-
if (!
|
|
486
|
+
if (!forwardForRead()) {
|
|
440
487
|
return textResult({ error: "Not connected. Ensure device is connected and radar is enabled." }, true);
|
|
441
488
|
}
|
|
442
489
|
device.activate(device.getTimeoutMinutes());
|
|
@@ -623,6 +670,10 @@ async function runMcpServer() {
|
|
|
623
670
|
device.activate(args.timeout_minutes);
|
|
624
671
|
}
|
|
625
672
|
const result = await callRadar("/api/ping");
|
|
673
|
+
// Version is a property of this process, not the device, so it is reported
|
|
674
|
+
// even when the device probe fails — the error path is exactly when a
|
|
675
|
+
// reviewer needs to correlate a report against a known-bad release.
|
|
676
|
+
result.mcp_version = RADAR_VERSION;
|
|
626
677
|
if (!result.error) {
|
|
627
678
|
result.stream_connected = isStreamConnected();
|
|
628
679
|
result.local_network_buffer = localNetworkBuffer.length;
|
|
@@ -656,7 +707,7 @@ async function runMcpServer() {
|
|
|
656
707
|
}
|
|
657
708
|
}
|
|
658
709
|
// --- MCP Server ---
|
|
659
|
-
const server = new Server({ name: "slack-radar", version: "1.
|
|
710
|
+
const server = new Server({ name: "slack-radar", version: "1.13.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
|
|
660
711
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
661
712
|
tools: TOOL_DEFINITIONS,
|
|
662
713
|
}));
|
|
@@ -678,6 +729,12 @@ async function runMcpServer() {
|
|
|
678
729
|
if (gate) {
|
|
679
730
|
return textResult(JSON.parse(gate.content[0].text), gate.isError);
|
|
680
731
|
}
|
|
732
|
+
// Source discovery gate: on seam builds (which list their sources on ping), block a tool
|
|
733
|
+
// whose capture source this build does not serve, instead of letting it 404 at the route.
|
|
734
|
+
const missingSource = sourceGate(name);
|
|
735
|
+
if (missingSource) {
|
|
736
|
+
return textResult(missingSource, true);
|
|
737
|
+
}
|
|
681
738
|
if (name === "open_radar_dashboard") {
|
|
682
739
|
return handleOpenDashboard(toolArgs);
|
|
683
740
|
}
|
|
@@ -728,6 +785,47 @@ async function runMcpServer() {
|
|
|
728
785
|
if (name === "query_session") {
|
|
729
786
|
return await handleQuerySession(toolArgs);
|
|
730
787
|
}
|
|
788
|
+
if (name === "list_prefs") {
|
|
789
|
+
const { user } = toolArgs;
|
|
790
|
+
const { data, isError } = await handleListPrefs(user);
|
|
791
|
+
return textResult(data, isError);
|
|
792
|
+
}
|
|
793
|
+
if (name === "get_prefs") {
|
|
794
|
+
const { file, user, keys } = toolArgs;
|
|
795
|
+
const { data, isError } = await handleGetPrefs(file ?? "", user, keys);
|
|
796
|
+
return textResult(data, isError);
|
|
797
|
+
}
|
|
798
|
+
if (name === "search_prefs") {
|
|
799
|
+
const { query, user } = toolArgs;
|
|
800
|
+
const { data, isError } = await handleSearchPrefs(query ?? "", user);
|
|
801
|
+
return textResult(data, isError);
|
|
802
|
+
}
|
|
803
|
+
// None of the three feature-flag tools are pure buildApiPath device-path builders: verified
|
|
804
|
+
// live that the device's own ?overridden=false is silently ignored, so even list_feature_flags
|
|
805
|
+
// fetches the unfiltered route and filters host-side (see flags-tools.ts's file header).
|
|
806
|
+
// callFeatureFlags shares one short-lived fetch across the three tools, since a model doing
|
|
807
|
+
// "list, then search, then get" in one turn would otherwise pay a full device round-trip per
|
|
808
|
+
// call for identical data.
|
|
809
|
+
if (name === "list_feature_flags") {
|
|
810
|
+
// The SDK does not enforce the schema, so a stringized "false" must not silently filter
|
|
811
|
+
// to zero flags under the strict comparison downstream.
|
|
812
|
+
const overridden = normalizeOverriddenArg(toolArgs["overridden"]);
|
|
813
|
+
const response = await callFeatureFlags();
|
|
814
|
+
const { data, isError } = listFeatureFlags(response, overridden);
|
|
815
|
+
return textResult(data, isError);
|
|
816
|
+
}
|
|
817
|
+
if (name === "search_feature_flags") {
|
|
818
|
+
const { query } = toolArgs;
|
|
819
|
+
const response = await callFeatureFlags();
|
|
820
|
+
const { data, isError } = searchFeatureFlags(response, query ?? "");
|
|
821
|
+
return textResult(data, isError);
|
|
822
|
+
}
|
|
823
|
+
if (name === "get_feature_flag") {
|
|
824
|
+
const { key, scope } = toolArgs;
|
|
825
|
+
const response = await callFeatureFlags();
|
|
826
|
+
const { data, isError } = getFeatureFlag(response, key ?? "", scope);
|
|
827
|
+
return textResult(data, isError);
|
|
828
|
+
}
|
|
731
829
|
const apiPath = buildApiPath(name, toolArgs);
|
|
732
830
|
if (apiPath === null) {
|
|
733
831
|
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
|
+
}>;
|