mobile-debug-mcp 0.32.2 → 0.32.4
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 +5 -1
- package/agent-plugin/LICENSE +201 -0
- package/agent-plugin/README.md +27 -0
- package/agent-plugin/mcp.json +11 -0
- package/agent-plugin/plugin.json +29 -0
- package/agent-plugin/skills/mobile-debug-mcp/SKILL.md +96 -0
- package/dist/observe/android.js +2 -18
- package/dist/server-core.js +1 -1
- package/docs/CHANGELOG.md +5 -2
- package/docs/benchmarks/ui-tree-performance/README.md +4 -3
- package/docs/tools/observe.md +1 -2
- package/package.json +4 -2
- package/scripts/agent-plugin.mjs +38 -0
- package/skills/mcp-builder/SKILL.md +1 -2
- package/skills/mobile-debug-tools-usage/SKILL.md +55 -33
- package/skills/spec-review/SKILL.md +1 -1
- package/skills/test-authoring/SKILL.md +1 -1
- package/src/observe/android.ts +2 -15
- package/src/server-core.ts +1 -1
- package/test/unit/observe/android_tree_acquisition.test.ts +4 -0
- package/test/unit/observe/ios-getlogs.test.ts +3 -3
- package/src/observe/android-tree-bridge.ts +0 -178
- package/test/device/automated/ui-tree-performance/bridge-probe.ts +0 -197
- package/test/fixtures/ui-tree-bridge/AndroidManifest.xml +0 -6
- package/test/fixtures/ui-tree-bridge/build.ts +0 -34
- package/test/fixtures/ui-tree-bridge/src/TreeInstrumentation.java +0 -126
- package/test/unit/observe/android_tree_bridge_cleanup.test.ts +0 -95
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process'
|
|
2
|
-
import { existsSync, mkdirSync } from 'node:fs'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
|
|
6
|
-
export function buildBridge() {
|
|
7
|
-
const root = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
const out = path.join(root, 'build')
|
|
9
|
-
const sdk = process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME ||
|
|
10
|
-
(process.platform === 'darwin' && process.env.HOME ? path.join(process.env.HOME, 'Library/Android/sdk') : '')
|
|
11
|
-
if (!sdk) throw new Error('Android SDK not found: set ANDROID_SDK_ROOT or ANDROID_HOME')
|
|
12
|
-
const buildTools = path.join(sdk, 'build-tools', '36.0.0')
|
|
13
|
-
const androidJar = path.join(sdk, 'platforms', 'android-36', 'android.jar')
|
|
14
|
-
if (!existsSync(androidJar) || !existsSync(buildTools)) {
|
|
15
|
-
throw new Error(`Android SDK 36 platform and build-tools 36.0.0 are required under ${sdk}`)
|
|
16
|
-
}
|
|
17
|
-
const java = process.env.JAVA_HOME
|
|
18
|
-
const tool = (name: string) => java ? path.join(java, 'bin', name) : name
|
|
19
|
-
const run = (cmd: string, args: string[]) => execFileSync(cmd, args, { cwd: out, stdio: 'pipe' })
|
|
20
|
-
mkdirSync(path.join(out, 'classes'), { recursive: true })
|
|
21
|
-
run(tool('javac'), ['--release', '8', '-classpath', androidJar, '-d', 'classes', path.join(root, 'src/TreeInstrumentation.java')])
|
|
22
|
-
run(tool('jar'), ['cf', 'classes.jar', '-C', 'classes', '.'])
|
|
23
|
-
run(path.join(buildTools, 'd8'), ['--lib', androidJar, '--output', out, 'classes.jar'])
|
|
24
|
-
run(path.join(buildTools, 'aapt2'), ['link', '-I', androidJar, '--manifest', path.join(root, 'AndroidManifest.xml'), '-o', 'unsigned.apk'])
|
|
25
|
-
run('zip', ['-q', 'unsigned.apk', 'classes.dex'])
|
|
26
|
-
run(path.join(buildTools, 'zipalign'), ['-f', '4', 'unsigned.apk', 'aligned.apk'])
|
|
27
|
-
try { run(tool('keytool'), ['-genkeypair', '-keystore', 'fixture.jks', '-storepass', 'android', '-keypass', 'android', '-alias', 'fixture', '-dname', 'CN=UI Tree Bridge', '-keyalg', 'RSA', '-validity', '3650']) } catch { /* Existing local fixture key. */ }
|
|
28
|
-
run(path.join(buildTools, 'apksigner'), ['sign', '--ks', 'fixture.jks', '--ks-pass', 'pass:android', '--out', 'bridge.apk', 'aligned.apk'])
|
|
29
|
-
return path.join(out, 'bridge.apk')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
33
|
-
console.log(buildBridge())
|
|
34
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
package dev.mobiledebugmcp.treebridge;
|
|
2
|
-
|
|
3
|
-
import android.app.Instrumentation;
|
|
4
|
-
import android.app.UiAutomation;
|
|
5
|
-
import android.graphics.Rect;
|
|
6
|
-
import android.os.Bundle;
|
|
7
|
-
import android.os.Build;
|
|
8
|
-
import android.util.Xml;
|
|
9
|
-
import android.util.Log;
|
|
10
|
-
import android.view.accessibility.AccessibilityNodeInfo;
|
|
11
|
-
import java.io.BufferedReader;
|
|
12
|
-
import java.io.InputStreamReader;
|
|
13
|
-
import java.io.OutputStreamWriter;
|
|
14
|
-
import java.io.StringWriter;
|
|
15
|
-
import java.net.InetAddress;
|
|
16
|
-
import java.net.ServerSocket;
|
|
17
|
-
import java.net.Socket;
|
|
18
|
-
import org.xmlpull.v1.XmlSerializer;
|
|
19
|
-
|
|
20
|
-
/** Benchmark-only bridge: one live accessibility acquisition per TREE request. */
|
|
21
|
-
public final class TreeInstrumentation extends Instrumentation {
|
|
22
|
-
private static final int PORT = 39019;
|
|
23
|
-
|
|
24
|
-
@Override public void onCreate(Bundle arguments) {
|
|
25
|
-
super.onCreate(arguments);
|
|
26
|
-
start();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Override public void onStart() {
|
|
30
|
-
try (ServerSocket server = new ServerSocket(PORT, 1, InetAddress.getByName("127.0.0.1"))) {
|
|
31
|
-
UiAutomation automation = getUiAutomation(UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES);
|
|
32
|
-
while (true) {
|
|
33
|
-
try (Socket socket = server.accept()) {
|
|
34
|
-
socket.setSoTimeout(10000);
|
|
35
|
-
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
|
|
36
|
-
OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream(), "UTF-8");
|
|
37
|
-
String command = input.readLine();
|
|
38
|
-
if ("STOP".equals(command)) {
|
|
39
|
-
output.write("OK\n");
|
|
40
|
-
output.flush();
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
if ("PING".equals(command)) {
|
|
44
|
-
output.write("OK\n");
|
|
45
|
-
output.flush();
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (!"TREE".equals(command)) {
|
|
49
|
-
output.write("ERROR invalid_command\n");
|
|
50
|
-
} else {
|
|
51
|
-
if (Build.VERSION.SDK_INT < 34) {
|
|
52
|
-
output.write("ERROR cache_clear_unavailable\n");
|
|
53
|
-
} else if (!automation.clearCache()) {
|
|
54
|
-
output.write("ERROR cache_clear_failed\n");
|
|
55
|
-
} else {
|
|
56
|
-
AccessibilityNodeInfo root = automation.getRootInActiveWindow();
|
|
57
|
-
if (root == null) {
|
|
58
|
-
output.write("ERROR null_root\n");
|
|
59
|
-
} else {
|
|
60
|
-
output.write("OK\n");
|
|
61
|
-
output.write(serialize(root));
|
|
62
|
-
root.recycle();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
output.flush();
|
|
67
|
-
} catch (Exception error) {
|
|
68
|
-
// A failed client request cannot make a later acquisition reuse its tree.
|
|
69
|
-
Log.e("TreeBridge", "request failed", error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} catch (Exception error) {
|
|
73
|
-
// The host-side probe detects failure to start or connect.
|
|
74
|
-
Log.e("TreeBridge", "bridge failed", error);
|
|
75
|
-
}
|
|
76
|
-
finish(0, new Bundle());
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private static String serialize(AccessibilityNodeInfo root) throws Exception {
|
|
80
|
-
StringWriter writer = new StringWriter();
|
|
81
|
-
XmlSerializer xml = Xml.newSerializer();
|
|
82
|
-
xml.setOutput(writer);
|
|
83
|
-
xml.startDocument("UTF-8", true);
|
|
84
|
-
xml.startTag("", "hierarchy");
|
|
85
|
-
writeNode(xml, root, 0);
|
|
86
|
-
xml.endTag("", "hierarchy");
|
|
87
|
-
xml.endDocument();
|
|
88
|
-
return writer.toString();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private static void writeNode(XmlSerializer xml, AccessibilityNodeInfo node, int index) throws Exception {
|
|
92
|
-
Rect bounds = new Rect();
|
|
93
|
-
node.getBoundsInScreen(bounds);
|
|
94
|
-
xml.startTag("", "node");
|
|
95
|
-
xml.attribute("", "index", Integer.toString(index));
|
|
96
|
-
xml.attribute("", "class", value(node.getClassName()));
|
|
97
|
-
xml.attribute("", "package", value(node.getPackageName()));
|
|
98
|
-
xml.attribute("", "text", value(node.getText()));
|
|
99
|
-
xml.attribute("", "content-desc", value(node.getContentDescription()));
|
|
100
|
-
xml.attribute("", "resource-id", value(node.getViewIdResourceName()));
|
|
101
|
-
xml.attribute("", "checkable", Boolean.toString(node.isCheckable()));
|
|
102
|
-
xml.attribute("", "checked", Boolean.toString(node.isChecked()));
|
|
103
|
-
xml.attribute("", "clickable", Boolean.toString(node.isClickable()));
|
|
104
|
-
xml.attribute("", "enabled", Boolean.toString(node.isEnabled()));
|
|
105
|
-
xml.attribute("", "focusable", Boolean.toString(node.isFocusable()));
|
|
106
|
-
xml.attribute("", "focused", Boolean.toString(node.isFocused()));
|
|
107
|
-
xml.attribute("", "scrollable", Boolean.toString(node.isScrollable()));
|
|
108
|
-
xml.attribute("", "long-clickable", Boolean.toString(node.isLongClickable()));
|
|
109
|
-
xml.attribute("", "password", Boolean.toString(node.isPassword()));
|
|
110
|
-
xml.attribute("", "selected", Boolean.toString(node.isSelected()));
|
|
111
|
-
xml.attribute("", "visible-to-user", Boolean.toString(node.isVisibleToUser()));
|
|
112
|
-
xml.attribute("", "bounds", bounds.toShortString());
|
|
113
|
-
for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
|
|
114
|
-
AccessibilityNodeInfo child = node.getChild(childIndex);
|
|
115
|
-
if (child != null && child.isVisibleToUser()) {
|
|
116
|
-
writeNode(xml, child, childIndex);
|
|
117
|
-
}
|
|
118
|
-
if (child != null) child.recycle();
|
|
119
|
-
}
|
|
120
|
-
xml.endTag("", "node");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private static String value(CharSequence input) {
|
|
124
|
-
return input == null ? "" : input.toString();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict'
|
|
2
|
-
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
-
import { createServer } from 'node:net'
|
|
4
|
-
import type { Socket } from 'node:net'
|
|
5
|
-
import { tmpdir } from 'node:os'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
import { readAndroidTreeFromBridge } from '../../../src/observe/android-tree-bridge.js'
|
|
8
|
-
|
|
9
|
-
async function run() {
|
|
10
|
-
const directory = mkdtempSync(path.join(tmpdir(), 'mcp-tree-bridge-'))
|
|
11
|
-
const adbPath = path.join(directory, 'adb')
|
|
12
|
-
const apkPath = path.join(directory, 'bridge.apk')
|
|
13
|
-
const launchesPath = path.join(directory, 'launches')
|
|
14
|
-
const getpropsPath = path.join(directory, 'getprops')
|
|
15
|
-
const previous = new Map(['ADB_PATH', 'MOBILE_DEBUG_MCP_ANDROID_TREE_BRIDGE_APK', 'MCP_FAKE_BRIDGE_PORT', 'MCP_FAKE_BRIDGE_LAUNCHES', 'MCP_FAKE_BRIDGE_GETPROPS', 'MCP_FAKE_FORCE_STOP_FAIL', 'MCP_FAKE_SDK'].map((key) => [key, process.env[key]]))
|
|
16
|
-
let invalidTree = false
|
|
17
|
-
const sockets = new Set<Socket>()
|
|
18
|
-
const server = createServer((socket) => {
|
|
19
|
-
sockets.add(socket)
|
|
20
|
-
socket.once('close', () => sockets.delete(socket))
|
|
21
|
-
socket.once('data', (chunk) => {
|
|
22
|
-
const command = chunk.toString().trim()
|
|
23
|
-
socket.end(command === 'TREE'
|
|
24
|
-
? invalidTree ? 'ERROR null_root\n' : 'OK\n<hierarchy><node class="android.view.View" /></hierarchy>'
|
|
25
|
-
: 'OK\n')
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
writeFileSync(apkPath, '')
|
|
29
|
-
writeFileSync(launchesPath, '')
|
|
30
|
-
writeFileSync(getpropsPath, '')
|
|
31
|
-
writeFileSync(adbPath, `#!/usr/bin/env node
|
|
32
|
-
const fs = require('node:fs')
|
|
33
|
-
const args = process.argv.slice(2).join(' ')
|
|
34
|
-
if (args.includes('am instrument')) {
|
|
35
|
-
fs.appendFileSync(process.env.MCP_FAKE_BRIDGE_LAUNCHES, 'launch\\n')
|
|
36
|
-
setInterval(() => {}, 1000)
|
|
37
|
-
} else if (args.includes('am force-stop') && process.env.MCP_FAKE_FORCE_STOP_FAIL === '1') {
|
|
38
|
-
process.exit(1)
|
|
39
|
-
} else if (args.includes('forward tcp:0')) {
|
|
40
|
-
console.log(process.env.MCP_FAKE_BRIDGE_PORT)
|
|
41
|
-
} else if (args.includes('getprop ro.build.version.sdk')) {
|
|
42
|
-
fs.appendFileSync(process.env.MCP_FAKE_BRIDGE_GETPROPS, 'getprop\\n')
|
|
43
|
-
console.log(process.env.MCP_FAKE_SDK || '36')
|
|
44
|
-
}
|
|
45
|
-
`)
|
|
46
|
-
chmodSync(adbPath, 0o755)
|
|
47
|
-
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve))
|
|
48
|
-
const address = server.address()
|
|
49
|
-
if (!address || typeof address === 'string') throw new Error('No test port')
|
|
50
|
-
process.env.ADB_PATH = adbPath
|
|
51
|
-
process.env.MOBILE_DEBUG_MCP_ANDROID_TREE_BRIDGE_APK = apkPath
|
|
52
|
-
process.env.MCP_FAKE_BRIDGE_PORT = String(address.port)
|
|
53
|
-
process.env.MCP_FAKE_BRIDGE_LAUNCHES = launchesPath
|
|
54
|
-
process.env.MCP_FAKE_BRIDGE_GETPROPS = getpropsPath
|
|
55
|
-
try {
|
|
56
|
-
assert.match(await readAndroidTreeFromBridge('test-device') ?? '', /<hierarchy>/)
|
|
57
|
-
invalidTree = true
|
|
58
|
-
process.env.MCP_FAKE_FORCE_STOP_FAIL = '1'
|
|
59
|
-
await assert.rejects(() => readAndroidTreeFromBridge('test-device'), /BRIDGE_CLEANUP_UNCONFIRMED/)
|
|
60
|
-
await assert.rejects(() => readAndroidTreeFromBridge('test-device'), /BRIDGE_CLEANUP_UNCONFIRMED/)
|
|
61
|
-
assert.equal(readFileSync(launchesPath, 'utf8').trim().split('\n').length, 1, 'failed cleanup must block a second launch')
|
|
62
|
-
invalidTree = false
|
|
63
|
-
delete process.env.MCP_FAKE_FORCE_STOP_FAIL
|
|
64
|
-
assert.match(await readAndroidTreeFromBridge('test-device') ?? '', /<hierarchy>/, 'successful cleanup allows relaunch')
|
|
65
|
-
for (let attempt = 0; attempt < 20 && readFileSync(launchesPath, 'utf8').trim().split('\n').length < 2; attempt++) {
|
|
66
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
67
|
-
}
|
|
68
|
-
assert.equal(readFileSync(launchesPath, 'utf8').trim().split('\n').length, 2)
|
|
69
|
-
invalidTree = true
|
|
70
|
-
assert.equal(await readAndroidTreeFromBridge('test-device'), null, 'clean shutdown permits legacy fallback')
|
|
71
|
-
process.env.MCP_FAKE_SDK = '33'
|
|
72
|
-
assert.equal(await readAndroidTreeFromBridge('old-device'), null, 'older Android versions use the legacy reader')
|
|
73
|
-
assert.equal(await readAndroidTreeFromBridge('old-device'), null)
|
|
74
|
-
assert.equal(readFileSync(getpropsPath, 'utf8').trim().split('\n').length, 3, 'unsupported devices recheck SDK support')
|
|
75
|
-
process.env.MCP_FAKE_SDK = '36'
|
|
76
|
-
invalidTree = false
|
|
77
|
-
assert.match(await readAndroidTreeFromBridge('old-device') ?? '', /<hierarchy>/, 'a newly supported device can start the bridge')
|
|
78
|
-
for (let attempt = 0; attempt < 20 && readFileSync(launchesPath, 'utf8').trim().split('\n').length < 3; attempt++) {
|
|
79
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
80
|
-
}
|
|
81
|
-
assert.equal(readFileSync(launchesPath, 'utf8').trim().split('\n').length, 3)
|
|
82
|
-
invalidTree = true
|
|
83
|
-
assert.equal(await readAndroidTreeFromBridge('old-device'), null, 'the new bridge shuts down before fallback')
|
|
84
|
-
} finally {
|
|
85
|
-
for (const [key, value] of previous) {
|
|
86
|
-
if (value === undefined) delete process.env[key]
|
|
87
|
-
else process.env[key] = value
|
|
88
|
-
}
|
|
89
|
-
for (const socket of sockets) socket.destroy()
|
|
90
|
-
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
91
|
-
rmSync(directory, { recursive: true, force: true })
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
run().catch((error) => { console.error(error); process.exitCode = 1 })
|