mobile-debug-mcp 0.22.0 → 0.24.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/dist/interact/classify.js +35 -0
- package/dist/interact/index.js +133 -57
- package/dist/network/index.js +232 -0
- package/dist/server/common.js +66 -0
- package/dist/server/tool-definitions.js +921 -0
- package/dist/server/tool-handlers.js +320 -0
- package/dist/server-core.js +4 -686
- package/docs/CHANGELOG.md +7 -0
- package/docs/tools/TOOLS.md +15 -7
- package/docs/tools/interact.md +270 -107
- package/docs/tools/manage.md +39 -38
- package/docs/tools/observe.md +30 -8
- package/docs/tools/system.md +1 -1
- package/package.json +1 -1
- package/src/interact/classify.ts +64 -0
- package/src/interact/index.ts +186 -58
- package/src/network/index.ts +268 -0
- package/src/server/common.ts +95 -0
- package/src/server/tool-definitions.ts +921 -0
- package/src/server/tool-handlers.ts +365 -0
- package/src/server-core.ts +4 -727
- package/src/types.ts +59 -6
- package/test/unit/interact/classify_action_outcome.test.ts +110 -0
- package/test/unit/interact/expect_tools.test.ts +77 -0
- package/test/unit/interact/tap_element.test.ts +23 -6
- package/test/unit/network/get_network_activity.test.ts +181 -0
- package/test/unit/server/contract.test.ts +26 -0
- package/test/unit/server/response_shapes.test.ts +69 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
2
|
import { handleToolCall } from '../../../src/server-core.js'
|
|
3
3
|
import { ToolsManage } from '../../../src/manage/index.js'
|
|
4
|
+
import { AndroidManage } from '../../../src/manage/index.js'
|
|
4
5
|
import { ToolsInteract } from '../../../src/interact/index.js'
|
|
5
6
|
import { ToolsObserve } from '../../../src/observe/index.js'
|
|
6
7
|
|
|
@@ -8,8 +9,13 @@ async function run() {
|
|
|
8
9
|
const originalInstallAppHandler = (ToolsManage as any).installAppHandler
|
|
9
10
|
const originalWaitForUIHandler = (ToolsInteract as any).waitForUIHandler
|
|
10
11
|
const originalTapElementHandler = (ToolsInteract as any).tapElementHandler
|
|
12
|
+
const originalTapHandler = (ToolsInteract as any).tapHandler
|
|
13
|
+
const originalExpectScreenHandler = (ToolsInteract as any).expectScreenHandler
|
|
14
|
+
const originalExpectElementVisibleHandler = (ToolsInteract as any).expectElementVisibleHandler
|
|
15
|
+
const originalStartApp = AndroidManage.prototype.startApp
|
|
11
16
|
const originalCaptureScreenshotHandler = (ToolsObserve as any).captureScreenshotHandler
|
|
12
17
|
const originalGetUITreeHandler = (ToolsObserve as any).getUITreeHandler
|
|
18
|
+
const originalGetScreenFingerprintHandler = (ToolsObserve as any).getScreenFingerprintHandler
|
|
13
19
|
|
|
14
20
|
try {
|
|
15
21
|
;(ToolsManage as any).installAppHandler = async () => ({
|
|
@@ -40,16 +46,70 @@ async function run() {
|
|
|
40
46
|
assert.strictEqual(waitForUIPayload.element.elementId, 'el_ready')
|
|
41
47
|
|
|
42
48
|
;(ToolsInteract as any).tapElementHandler = async () => ({
|
|
49
|
+
action_id: 'tap_element_1',
|
|
50
|
+
timestamp: 1234567890,
|
|
51
|
+
action_type: 'tap_element',
|
|
52
|
+
target: {
|
|
53
|
+
selector: { elementId: 'el_ready' },
|
|
54
|
+
resolved: { elementId: 'el_ready', text: 'Ready', resource_id: null, accessibility_id: null, class: 'Button', bounds: [0, 0, 10, 10], index: 0 }
|
|
55
|
+
},
|
|
43
56
|
success: true,
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
ui_fingerprint_before: 'fp_before',
|
|
58
|
+
ui_fingerprint_after: 'fp_after'
|
|
46
59
|
})
|
|
47
60
|
|
|
48
61
|
const tapElementResponse = await handleToolCall('tap_element', { elementId: 'el_ready' })
|
|
49
62
|
const tapElementPayload = JSON.parse((tapElementResponse as any).content[0].text)
|
|
50
63
|
assert.strictEqual(tapElementPayload.success, true)
|
|
51
|
-
assert.strictEqual(tapElementPayload.
|
|
52
|
-
assert.strictEqual(tapElementPayload.
|
|
64
|
+
assert.strictEqual(tapElementPayload.action_type, 'tap_element')
|
|
65
|
+
assert.strictEqual(tapElementPayload.target.resolved.elementId, 'el_ready')
|
|
66
|
+
assert.strictEqual(tapElementPayload.ui_fingerprint_before, 'fp_before')
|
|
67
|
+
|
|
68
|
+
;(ToolsObserve as any).getScreenFingerprintHandler = async () => ({ fingerprint: 'fp_mock', activity: 'MainActivity' })
|
|
69
|
+
;(ToolsInteract as any).tapHandler = async () => ({ success: true, x: 1, y: 2 })
|
|
70
|
+
const tapResponse = await handleToolCall('tap', { platform: 'android', x: 1, y: 2 })
|
|
71
|
+
const tapPayload = JSON.parse((tapResponse as any).content[0].text)
|
|
72
|
+
assert.strictEqual(tapPayload.success, true)
|
|
73
|
+
assert.strictEqual(tapPayload.action_type, 'tap')
|
|
74
|
+
assert.deepStrictEqual(tapPayload.target.selector, { x: 1, y: 2 })
|
|
75
|
+
assert.strictEqual(tapPayload.ui_fingerprint_before, 'fp_mock')
|
|
76
|
+
|
|
77
|
+
AndroidManage.prototype.startApp = async function () {
|
|
78
|
+
return {
|
|
79
|
+
device: { platform: 'android', id: 'emulator-5554', osVersion: '14', model: 'Pixel', simulator: true },
|
|
80
|
+
appStarted: true,
|
|
81
|
+
launchTimeMs: 123
|
|
82
|
+
} as any
|
|
83
|
+
}
|
|
84
|
+
const startAppResponse = await handleToolCall('start_app', { platform: 'android', appId: 'com.example.app' })
|
|
85
|
+
const startAppPayload = JSON.parse((startAppResponse as any).content[0].text)
|
|
86
|
+
assert.strictEqual(startAppPayload.success, true)
|
|
87
|
+
assert.strictEqual(startAppPayload.action_type, 'start_app')
|
|
88
|
+
assert.deepStrictEqual(startAppPayload.target.selector, { appId: 'com.example.app' })
|
|
89
|
+
|
|
90
|
+
;(ToolsInteract as any).expectScreenHandler = async () => ({
|
|
91
|
+
success: true,
|
|
92
|
+
observed_screen: { fingerprint: 'fp_after', screen: 'MainActivity' },
|
|
93
|
+
expected_screen: { fingerprint: 'fp_after', screen: null },
|
|
94
|
+
confidence: 1
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const expectScreenResponse = await handleToolCall('expect_screen', { fingerprint: 'fp_after' })
|
|
98
|
+
const expectScreenPayload = JSON.parse((expectScreenResponse as any).content[0].text)
|
|
99
|
+
assert.strictEqual(expectScreenPayload.success, true)
|
|
100
|
+
assert.strictEqual(expectScreenPayload.confidence, 1)
|
|
101
|
+
|
|
102
|
+
;(ToolsInteract as any).expectElementVisibleHandler = async () => ({
|
|
103
|
+
success: true,
|
|
104
|
+
selector: { text: 'Ready' },
|
|
105
|
+
element_id: 'el_ready',
|
|
106
|
+
element: { elementId: 'el_ready', text: 'Ready', resource_id: null, accessibility_id: null, class: 'TextView', bounds: [0, 0, 10, 10], index: 0 }
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const expectElementResponse = await handleToolCall('expect_element_visible', { selector: { text: 'Ready' } })
|
|
110
|
+
const expectElementPayload = JSON.parse((expectElementResponse as any).content[0].text)
|
|
111
|
+
assert.strictEqual(expectElementPayload.success, true)
|
|
112
|
+
assert.strictEqual(expectElementPayload.element_id, 'el_ready')
|
|
53
113
|
|
|
54
114
|
;(ToolsObserve as any).captureScreenshotHandler = async () => ({
|
|
55
115
|
device: { platform: 'ios', id: 'booted', osVersion: '18.0', model: 'Simulator', simulator: true },
|
|
@@ -82,8 +142,13 @@ async function run() {
|
|
|
82
142
|
;(ToolsManage as any).installAppHandler = originalInstallAppHandler
|
|
83
143
|
;(ToolsInteract as any).waitForUIHandler = originalWaitForUIHandler
|
|
84
144
|
;(ToolsInteract as any).tapElementHandler = originalTapElementHandler
|
|
145
|
+
;(ToolsInteract as any).tapHandler = originalTapHandler
|
|
146
|
+
;(ToolsInteract as any).expectScreenHandler = originalExpectScreenHandler
|
|
147
|
+
;(ToolsInteract as any).expectElementVisibleHandler = originalExpectElementVisibleHandler
|
|
148
|
+
AndroidManage.prototype.startApp = originalStartApp
|
|
85
149
|
;(ToolsObserve as any).captureScreenshotHandler = originalCaptureScreenshotHandler
|
|
86
150
|
;(ToolsObserve as any).getUITreeHandler = originalGetUITreeHandler
|
|
151
|
+
;(ToolsObserve as any).getScreenFingerprintHandler = originalGetScreenFingerprintHandler
|
|
87
152
|
}
|
|
88
153
|
}
|
|
89
154
|
|