aiphone-mcp 1.0.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/LICENSE +21 -0
- package/README.md +227 -0
- package/bin/aiphone-mcp.js +2 -0
- package/package.json +33 -0
- package/src/adb.js +523 -0
- package/src/image.js +73 -0
- package/src/server.js +1163 -0
- package/src/uiparser.js +142 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mochamad Nizwar Syafuan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# aiphone-mcp
|
|
2
|
+
|
|
3
|
+
MCP server for controlling Android devices via ADB. Exposes tools for screenshots, UI interaction, app management, wireless ADB, and device diagnostics.
|
|
4
|
+
|
|
5
|
+
Works with any MCP-compatible client: LM Studio, Claude Desktop, Cursor, Windsurf.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Screenshots with automatic compression (WebP, JPEG, PNG)
|
|
12
|
+
- UI inspection — tap, swipe, type, find elements by selector
|
|
13
|
+
- App control — launch, stop, install checks, open URLs
|
|
14
|
+
- Wireless ADB over TCP/IP
|
|
15
|
+
- Device info — battery, memory, storage, network interfaces
|
|
16
|
+
- Navigation — home, back, recents, screen rotation
|
|
17
|
+
- Notifications — post and inspect system notifications
|
|
18
|
+
- Connectivity — toggle WiFi, mobile data, airplane mode
|
|
19
|
+
- Assertions — foreground app and element presence checks
|
|
20
|
+
- Escape hatch — run any arbitrary `adb shell` command
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- Node.js 18+
|
|
27
|
+
- [ADB](https://developer.android.com/studio/releases/platform-tools) in your PATH
|
|
28
|
+
- Android 8+ with USB Debugging enabled
|
|
29
|
+
|
|
30
|
+
To enable USB Debugging: Settings → About Phone → tap Build Number 7 times → Developer Options → USB Debugging.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
**npx** (no install needed):
|
|
37
|
+
```bash
|
|
38
|
+
npx aiphone-mcp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Global install**:
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g aiphone-mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Local clone**:
|
|
47
|
+
```bash
|
|
48
|
+
git clone <repository-url>
|
|
49
|
+
cd aiphone-mcp
|
|
50
|
+
npm install
|
|
51
|
+
npm link
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Client Configuration
|
|
57
|
+
|
|
58
|
+
All clients use the same config structure. The entry point is `npx aiphone-mcp`.
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"aiphone": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": ["aiphone-mcp"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
| Variable | Default | Description |
|
|
74
|
+
|----------|---------|-------------|
|
|
75
|
+
| `AIPHONE_ADB_PATH` | `adb` | Path to adb binary |
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"aiphone": {
|
|
80
|
+
"command": "npx",
|
|
81
|
+
"args": ["aiphone-mcp"],
|
|
82
|
+
"env": {
|
|
83
|
+
"AIPHONE_ADB_PATH": "/usr/local/bin/adb",
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Available Tools
|
|
92
|
+
|
|
93
|
+
### Device
|
|
94
|
+
|
|
95
|
+
| Tool | Description |
|
|
96
|
+
|------|-------------|
|
|
97
|
+
| `list_devices` | List all connected ADB device serials |
|
|
98
|
+
| `get_device_info` | Full hardware identity, battery, memory, storage, and network info |
|
|
99
|
+
| `get_screen_size` | Physical screen resolution in pixels |
|
|
100
|
+
| `get_foreground_app` | Package and window currently visible to the user |
|
|
101
|
+
|
|
102
|
+
### Screen Observation
|
|
103
|
+
|
|
104
|
+
| Tool | Description |
|
|
105
|
+
|------|-------------|
|
|
106
|
+
| `take_screenshot` | Capture the screen as an optimized image (WebP by default). Supports `max_width`, `max_height`, `format`, and `quality` parameters. |
|
|
107
|
+
| `get_ui_elements` | Parsed list of interactive UI elements from the UIAutomator hierarchy |
|
|
108
|
+
| `dump_ui_xml` | Raw UIAutomator XML hierarchy string |
|
|
109
|
+
|
|
110
|
+
### Interaction
|
|
111
|
+
|
|
112
|
+
| Tool | Description |
|
|
113
|
+
|------|-------------|
|
|
114
|
+
| `tap` | Tap at absolute screen coordinates |
|
|
115
|
+
| `double_tap` | Double-tap at absolute screen coordinates |
|
|
116
|
+
| `tap_element` | Tap the center of an element by its bounds array `[x1, y1, x2, y2]` |
|
|
117
|
+
| `tap_by_selector` | Find an element by selector and tap it |
|
|
118
|
+
| `swipe` | Swipe gesture — directional (`up`, `down`, `left`, `right`) or coordinate-based |
|
|
119
|
+
| `type_text` | Type text into the currently focused input field |
|
|
120
|
+
| `type_in_element` | Find an input field by selector, focus it, clear existing text, and type |
|
|
121
|
+
| `press_key` | Press a key by name (`back`, `home`, `enter`, `search`, `delete`, ...) or numeric keycode |
|
|
122
|
+
|
|
123
|
+
### Element Selectors
|
|
124
|
+
|
|
125
|
+
| Tool | Description |
|
|
126
|
+
|------|-------------|
|
|
127
|
+
| `find_element` | Find an element by `resourceId`, `text`, `contentDesc`, or `className` |
|
|
128
|
+
| `wait_for_element` | Poll until a matching element appears or timeout elapses |
|
|
129
|
+
| `assert_element_exists` | Assert that an element matching a selector is present — returns PASS/FAIL |
|
|
130
|
+
|
|
131
|
+
### Navigation
|
|
132
|
+
|
|
133
|
+
| Tool | Description |
|
|
134
|
+
|------|-------------|
|
|
135
|
+
| `go_home` | Press the Home button |
|
|
136
|
+
| `go_back` | Press the Back button |
|
|
137
|
+
| `open_recents` | Open the recent apps switcher |
|
|
138
|
+
| `rotate_screen` | Set device rotation: 0=portrait, 1=landscape, 2=reverse portrait, 3=reverse landscape |
|
|
139
|
+
| `delay` | Wait for a specified number of milliseconds (max 10 000) |
|
|
140
|
+
|
|
141
|
+
### App Control
|
|
142
|
+
|
|
143
|
+
| Tool | Description |
|
|
144
|
+
|------|-------------|
|
|
145
|
+
| `open_app` | Launch an app by package name using the LAUNCHER intent |
|
|
146
|
+
| `open_url` | Open a URL in the device default browser |
|
|
147
|
+
| `force_stop_app` | Force-stop an app by package name |
|
|
148
|
+
| `is_app_installed` | Check whether a package is installed on the device |
|
|
149
|
+
| `list_installed_apps` | Return all installed package names |
|
|
150
|
+
| `assert_foreground_app` | Assert a package is currently in the foreground — returns PASS/FAIL |
|
|
151
|
+
|
|
152
|
+
### Wireless ADB
|
|
153
|
+
|
|
154
|
+
| Tool | Description |
|
|
155
|
+
|------|-------------|
|
|
156
|
+
| `enable_wireless_adb` | Switch a USB-connected device to TCP/IP mode (run before disconnecting USB) |
|
|
157
|
+
| `get_device_ip` | Return all active network interfaces with IP addresses |
|
|
158
|
+
| `adb_connect` | Connect to a device over TCP/IP at a given IP and port |
|
|
159
|
+
| `adb_disconnect` | Disconnect a wireless ADB target, or all wireless devices if no target is specified |
|
|
160
|
+
|
|
161
|
+
### Notifications
|
|
162
|
+
|
|
163
|
+
| Tool | Description |
|
|
164
|
+
|------|-------------|
|
|
165
|
+
| `post_notification` | Post a system notification (`bigtext`, `inbox`, or `media` style) |
|
|
166
|
+
| `dump_notifications` | Return raw `dumpsys notification` output — active notifications and history |
|
|
167
|
+
|
|
168
|
+
### Connectivity
|
|
169
|
+
|
|
170
|
+
| Tool | Description |
|
|
171
|
+
|------|-------------|
|
|
172
|
+
| `set_wifi` | Enable or disable WiFi |
|
|
173
|
+
| `set_mobile_data` | Enable or disable mobile data |
|
|
174
|
+
| `set_airplane_mode` | Enable or disable airplane mode |
|
|
175
|
+
|
|
176
|
+
### Escape Hatch
|
|
177
|
+
|
|
178
|
+
| Tool | Description |
|
|
179
|
+
|------|-------------|
|
|
180
|
+
| `adb_shell` | Run any arbitrary `adb shell` command — use when no other tool covers the action |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Screenshot Parameters
|
|
185
|
+
|
|
186
|
+
| Parameter | Type | Default | Description |
|
|
187
|
+
|-----------|------|---------|-------------|
|
|
188
|
+
| `max_width` | integer | 1080 | Max width in pixels (downscales proportionally) |
|
|
189
|
+
| `max_height` | integer | 1920 | Max height in pixels (downscales proportionally) |
|
|
190
|
+
| `format` | string | `webp` | `webp`, `jpeg`, or `png` |
|
|
191
|
+
| `quality` | integer | 75 | Compression quality 1–100 (ignored for PNG) |
|
|
192
|
+
|
|
193
|
+
Images are never upscaled.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Selectors
|
|
198
|
+
|
|
199
|
+
Tools that locate elements accept a `selector` object with these fields:
|
|
200
|
+
|
|
201
|
+
| Field | Match | Example |
|
|
202
|
+
|-------|-------|---------|
|
|
203
|
+
| `resourceId` | Exact | `"com.example.app:id/search_bar"` |
|
|
204
|
+
| `text` | Substring | `"Sign in"` |
|
|
205
|
+
| `contentDesc` | Substring | `"Close button"` |
|
|
206
|
+
| `className` | Exact | `"android.widget.EditText"` |
|
|
207
|
+
| `clickableOnly` | Filter | `true` |
|
|
208
|
+
|
|
209
|
+
Priority: `resourceId` > `text` > `contentDesc` > `className`.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Troubleshooting
|
|
214
|
+
|
|
215
|
+
**No devices found** — check that USB Debugging is enabled and the device is authorized. Run `adb devices` to verify.
|
|
216
|
+
|
|
217
|
+
**adb not found** — make sure `adb` is in your PATH, or set `AIPHONE_ADB_PATH` to the full binary path.
|
|
218
|
+
|
|
219
|
+
**Wireless connection fails** — both machines must be on the same network. Run `enable_wireless_adb` while USB is still connected, get the IP with `get_device_ip`, then call `adb_connect`.
|
|
220
|
+
|
|
221
|
+
**Screenshot too large** — use `max_width: 720, format: "webp"` to reduce output size.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT. See [LICENSE](LICENSE) for the full text.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aiphone-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for AI-powered Android device control via ADB — aiphone project",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"aiphone-mcp": "./bin/aiphone-mcp.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"src/"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "node bin/aiphone-mcp.js"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@modelcontextprotocol/sdk": "^1.10.2",
|
|
18
|
+
"fast-xml-parser": "^5.5.9",
|
|
19
|
+
"sharp": "^0.34.5"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Mochamad Nizwar Syafuan",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"mcp",
|
|
28
|
+
"android",
|
|
29
|
+
"adb",
|
|
30
|
+
"automation",
|
|
31
|
+
"aiphone"
|
|
32
|
+
]
|
|
33
|
+
}
|