mobile-debug-mcp 0.31.0 → 0.32.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.
Files changed (66) hide show
  1. package/dist/interact/android.js +13 -8
  2. package/dist/interact/index.js +33 -22
  3. package/dist/interact/ios.js +5 -2
  4. package/dist/manage/android.js +20 -10
  5. package/dist/manage/ios.js +19 -10
  6. package/dist/observe/android.js +6 -1
  7. package/dist/observe/index.js +22 -5
  8. package/dist/observe/ios.js +7 -2
  9. package/dist/observe/snapshot-metadata.js +94 -15
  10. package/dist/server/common.js +14 -7
  11. package/dist/server/journey-schema.js +60 -0
  12. package/dist/server/tool-definitions.js +59 -6
  13. package/dist/server/tool-handlers.js +358 -55
  14. package/dist/server-core.js +1 -1
  15. package/dist/utils/exec.js +4 -2
  16. package/dist/utils/ios/utils.js +5 -2
  17. package/dist/utils/operation-budget.js +25 -0
  18. package/dist/utils/resolve-device.js +12 -1
  19. package/dist/utils/timing.js +19 -0
  20. package/dist/utils/ui/index.js +2 -0
  21. package/docs/CHANGELOG.md +3 -0
  22. package/docs/benchmarks/interaction-latency/README.md +26 -0
  23. package/docs/benchmarks/interaction-latency/final.json +1810 -0
  24. package/docs/benchmarks/interaction-latency/final.md +17 -0
  25. package/docs/benchmarks/interaction-latency/ios-validation.md +11 -0
  26. package/docs/specs-deltas/018-interaction-latency-and-batched-journeys.md +301 -0
  27. package/docs/tools/interact.md +30 -0
  28. package/package.json +1 -1
  29. package/src/interact/android.ts +13 -8
  30. package/src/interact/index.ts +32 -23
  31. package/src/interact/ios.ts +5 -2
  32. package/src/manage/android.ts +19 -10
  33. package/src/manage/ios.ts +18 -10
  34. package/src/observe/android.ts +5 -1
  35. package/src/observe/index.ts +21 -5
  36. package/src/observe/ios.ts +6 -2
  37. package/src/observe/snapshot-metadata.ts +94 -15
  38. package/src/server/common.ts +13 -6
  39. package/src/server/journey-schema.ts +63 -0
  40. package/src/server/tool-definitions.ts +60 -7
  41. package/src/server/tool-handlers.ts +324 -53
  42. package/src/server-core.ts +1 -1
  43. package/src/types.ts +31 -2
  44. package/src/utils/exec.ts +4 -2
  45. package/src/utils/ios/utils.ts +5 -2
  46. package/src/utils/operation-budget.ts +22 -0
  47. package/src/utils/resolve-device.ts +13 -1
  48. package/src/utils/timing.ts +15 -0
  49. package/src/utils/ui/index.ts +2 -0
  50. package/test/device/automated/latency/benchmark.ts +136 -0
  51. package/test/device/automated/latency/report.ts +6 -0
  52. package/test/fixtures/latency-journey-app/AndroidManifest.xml +6 -0
  53. package/test/fixtures/latency-journey-app/README.md +10 -0
  54. package/test/fixtures/latency-journey-app/build.ts +26 -0
  55. package/test/fixtures/latency-journey-app/src/MainActivity.java +48 -0
  56. package/test/unit/manage/restart_budget.test.ts +37 -0
  57. package/test/unit/observe/capture_debug_snapshot.test.ts +6 -0
  58. package/test/unit/observe/snapshot_metadata.test.ts +20 -1
  59. package/test/unit/observe/state_delta.test.ts +15 -0
  60. package/test/unit/server/benchmark_report.test.ts +4 -0
  61. package/test/unit/server/contract.test.ts +1 -1
  62. package/test/unit/server/interaction_modes.test.ts +60 -0
  63. package/test/unit/server/operation_budget.test.ts +32 -0
  64. package/test/unit/server/response_shapes.test.ts +3 -3
  65. package/test/unit/server/run_journey.test.ts +90 -0
  66. package/test/unit/server/tap_selector.test.ts +68 -0
@@ -0,0 +1,25 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ const budgets = new AsyncLocalStorage();
3
+ export function hasFiniteBudget() { return Number.isFinite(budgets.getStore()?.deadline); }
4
+ export function runWithBudget(timeoutMs, operation) {
5
+ const parent = budgets.getStore();
6
+ const budget = { deadline: Math.min(parent?.deadline ?? Infinity, performance.now() + timeoutMs), dispatchStarted: false, parent };
7
+ return budgets.run(budget, () => operation(budget));
8
+ }
9
+ export function remainingBudget(fallback = 0) {
10
+ const budget = budgets.getStore();
11
+ if (!budget || !Number.isFinite(budget.deadline))
12
+ return fallback;
13
+ const remaining = Math.floor(budget.deadline - performance.now());
14
+ if (remaining <= 0)
15
+ throw new Error('ACTION_TIMEOUT');
16
+ return fallback > 0 ? Math.min(fallback, remaining) : remaining;
17
+ }
18
+ export function markDispatchStarted() {
19
+ remainingBudget();
20
+ let budget = budgets.getStore();
21
+ while (budget) {
22
+ budget.dispatchStarted = true;
23
+ budget = budget.parent;
24
+ }
25
+ }
@@ -1,3 +1,6 @@
1
+ import { retainConnectedDeviceSnapshots } from '../observe/snapshot-metadata.js';
2
+ import { measure } from './timing.js';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
1
4
  import { listAndroidDevices } from "./android/utils.js";
2
5
  import { listIOSDevices } from "./ios/utils.js";
3
6
  function parseNumericVersion(v) {
@@ -32,9 +35,17 @@ export async function listDevices(platform, appId) {
32
35
  }
33
36
  return iosDeviceLister(appId);
34
37
  }
38
+ const deviceContext = new AsyncLocalStorage();
39
+ export function withResolvedDevice(device, operation) {
40
+ return deviceContext.run(device, operation);
41
+ }
35
42
  export async function resolveTargetDevice(opts) {
36
43
  const { platform, appId, prefer, deviceId } = opts;
37
- const devices = await listDevices(platform, appId);
44
+ const current = deviceContext.getStore();
45
+ if (current && current.platform === platform && (!deviceId || current.id === deviceId))
46
+ return current;
47
+ const devices = await measure('device_resolution_ms', () => listDevices(platform, appId));
48
+ retainConnectedDeviceSnapshots(platform, devices.map(device => device.id));
38
49
  // During unit tests (no adb/xcrun available), provide a lightweight mock device so
39
50
  // the observe/interact unit tests can run without real devices.
40
51
  if ((!devices || devices.length === 0) && (process.env.NODE_ENV === 'test' || process.env.MCP_TEST_MOCK_DEVICES === '1')) {
@@ -0,0 +1,19 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ const timings = new AsyncLocalStorage();
3
+ export function withTiming(values, operation) { return timings.run(values, operation); }
4
+ export function recordTiming(component, milliseconds) {
5
+ const values = timings.getStore();
6
+ if (values)
7
+ values[component] = (values[component] ?? 0) + milliseconds;
8
+ }
9
+ export async function measure(component, operation) {
10
+ const start = performance.now();
11
+ try {
12
+ return await operation();
13
+ }
14
+ finally {
15
+ const values = timings.getStore();
16
+ if (values)
17
+ values[component] = (values[component] ?? 0) + performance.now() - start;
18
+ }
19
+ }
@@ -1,3 +1,4 @@
1
+ import { remainingBudget } from '../operation-budget.js';
1
2
  import crypto from 'crypto';
2
3
  const ANDROID_STRUCTURAL_TYPES = ['Window', 'Application', 'View', 'ViewGroup', 'LinearLayout', 'FrameLayout', 'RelativeLayout', 'ScrollView', 'RecyclerView', 'TextView', 'ImageView'];
3
4
  const IOS_STRUCTURAL_TYPES = ['Window', 'Application', 'View', 'ViewController', 'UITableView', 'UICollectionView', 'UILabel', 'UIImageView', 'UIView', 'UIWindow', 'UIStackView', 'UITextView', 'UITableViewCell'];
@@ -140,6 +141,7 @@ export async function scrollToElementShared(opts) {
140
141
  const duration = 300;
141
142
  let scrollsPerformed = 0;
142
143
  for (let i = 0; i < maxScrolls; i++) {
144
+ remainingBudget();
143
145
  const { x1, y1, x2, y2 } = computeCoords();
144
146
  try {
145
147
  await swipe(x1, y1, x2, y2, duration, deviceId);
package/docs/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  All notable changes to the **Mobile Debug MCP** project will be documented in this file.
4
4
 
5
+ ## [0.32.0]
6
+ - Added bounded interaction verification modes, compact responses, selector-based taps, and batched journeys to reduce MCP interaction latency.
7
+
5
8
  ## [0.31.0]
6
9
  - Added tool discovery/automation
7
10
 
@@ -0,0 +1,26 @@
1
+ # Interaction latency benchmark
2
+
3
+ Run after `npm run verify`:
4
+
5
+ ```sh
6
+ MCP_ADB_TIMEOUT=30000 LATENCY_DEVICE_ID=emulator-5554 npx tsx test/device/automated/latency/benchmark.ts
7
+ ```
8
+
9
+ Use the named Pixel 9 Pro Android 16 emulator with SDK platform 36, build-tools
10
+ 36.0.0, and a Java installation capable of `javac --release 8`. Set its display
11
+ to 720x1600 at density 240 to keep repeated UI hierarchy reads responsive; the
12
+ report records the image, API, display size, density, and Android command timeout.
13
+ The harness builds and signs its own offline fixture. It resets that fixture
14
+ only; no other app data is cleared.
15
+
16
+ The sequential protocol compares the legacy handle-based public tool flow with
17
+ full/debug and light/compact journeys through a spawned stdio MCP server. Each
18
+ mode has three warm-ups and ten measured runs. Screenshot and screenshot-free
19
+ debug snapshot calls are measured separately. JSON and Markdown reports record
20
+ fixture hash, environment, request sequence, failures, and percentiles. Failed
21
+ runs do not enter percentiles. Raw observations and device serials are not saved.
22
+ See [iOS simulator validation](ios-validation.md) for the interaction checks.
23
+
24
+ The process exits unsuccessfully on >10% full p95 regression or <30% light p50
25
+ improvement. A failed run is reported and excluded from percentiles as the spec
26
+ requires; inspect its selector and tool or step before accepting the result.