termux-adbmcp 0.2.0__tar.gz
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.
- termux_adbmcp-0.2.0/.gitignore +30 -0
- termux_adbmcp-0.2.0/LICENSE +21 -0
- termux_adbmcp-0.2.0/PKG-INFO +295 -0
- termux_adbmcp-0.2.0/README.en.md +235 -0
- termux_adbmcp-0.2.0/README.md +251 -0
- termux_adbmcp-0.2.0/docs/RikkaHub-/345/257/271/350/257/235/344/275/277/347/224/250.md +158 -0
- termux_adbmcp-0.2.0/docs/RikkaHub-/345/267/245/345/205/267/350/260/203/347/224/250/346/216/222/346/237/245.md +232 -0
- termux_adbmcp-0.2.0/docs/RikkaHub-/346/216/245/345/205/245.md +129 -0
- termux_adbmcp-0.2.0/docs//345/257/271/346/257/224-yhuangsh-adbmcp.md +111 -0
- termux_adbmcp-0.2.0/docs//345/277/253/351/200/237/345/274/200/345/247/213.md +177 -0
- termux_adbmcp-0.2.0/docs//346/216/222/351/232/234-notifications-cancelled.md +181 -0
- termux_adbmcp-0.2.0/docs//350/256/276/345/244/207/346/216/245/345/205/245.md +94 -0
- termux_adbmcp-0.2.0/docs//350/257/212/346/226/255/350/256/260/345/275/225-/345/267/245/345/205/267/344/270/215/345/217/257/347/224/250.md +145 -0
- termux_adbmcp-0.2.0/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +222 -0
- termux_adbmcp-0.2.0/examples/rikkahub-mcp-import.json +12 -0
- termux_adbmcp-0.2.0/install/bootstrap.sh +114 -0
- termux_adbmcp-0.2.0/install/install-adbmcp.sh +264 -0
- termux_adbmcp-0.2.0/pyproject.toml +64 -0
- termux_adbmcp-0.2.0/scripts/adbmcp +486 -0
- termux_adbmcp-0.2.0/scripts/boot_mcp.sh +4 -0
- termux_adbmcp-0.2.0/scripts/device_setup.sh +157 -0
- termux_adbmcp-0.2.0/scripts/device_watchdog.sh +212 -0
- termux_adbmcp-0.2.0/scripts/patch_cancelled.py +96 -0
- termux_adbmcp-0.2.0/scripts/scan_device.py +38 -0
- termux_adbmcp-0.2.0/src/adbmcp/__init__.py +14 -0
- termux_adbmcp-0.2.0/src/adbmcp/__main__.py +8 -0
- termux_adbmcp-0.2.0/src/adbmcp/cli.py +109 -0
- termux_adbmcp-0.2.0/src/adbmcp/installer.py +233 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# WorkBuddy 工作区内部数据(不发布)
|
|
2
|
+
.workbuddy/
|
|
3
|
+
|
|
4
|
+
# 打包产物
|
|
5
|
+
*.zip
|
|
6
|
+
|
|
7
|
+
# 系统与编辑器
|
|
8
|
+
.DS_Store
|
|
9
|
+
Thumbs.db
|
|
10
|
+
*.swp
|
|
11
|
+
*~
|
|
12
|
+
.idea/
|
|
13
|
+
.vscode/
|
|
14
|
+
|
|
15
|
+
# 本地敏感配置
|
|
16
|
+
.env
|
|
17
|
+
*.local
|
|
18
|
+
models.json
|
|
19
|
+
|
|
20
|
+
# 日志与临时文件
|
|
21
|
+
*.log
|
|
22
|
+
*.pid
|
|
23
|
+
|
|
24
|
+
# Python 构建产物
|
|
25
|
+
build/
|
|
26
|
+
dist/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
__pycache__/
|
|
29
|
+
*.py[cod]
|
|
30
|
+
.venv/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 adbmcp contributors
|
|
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.
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: termux-adbmcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Turn an Android phone (Termux) into an MCP server so AI clients can drive adb devices by natural language
|
|
5
|
+
Project-URL: Homepage, https://github.com/wu737/adbmcp
|
|
6
|
+
Project-URL: Repository, https://github.com/wu737/adbmcp
|
|
7
|
+
Project-URL: Issues, https://github.com/wu737/adbmcp/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/wu737/adbmcp/releases
|
|
9
|
+
Author: wu737
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 adbmcp contributors
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: adb,android,automation,device-control,iot,mcp,model-context-protocol,shell-automation,termux
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Environment :: Console
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
40
|
+
Classifier: Topic :: System :: Hardware
|
|
41
|
+
Classifier: Topic :: Utilities
|
|
42
|
+
Requires-Python: >=3.8
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
|
|
45
|
+
# adbmcp
|
|
46
|
+
|
|
47
|
+
**用手机当 AI 的设备遥控器** —— 把 Android 手机变成 MCP 服务器,让 Claude / Cursor / RikkaHub / WorkBuddy 等任意 AI 客户端通过自然语言直接操作你的设备。
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
你在 RikkaHub 里说:「现在有几台设备在线?分别什么系统?」
|
|
51
|
+
↓
|
|
52
|
+
AI 调用 MCP 工具
|
|
53
|
+
↓
|
|
54
|
+
手机 Termux (termux-native-mcp :8081)
|
|
55
|
+
↓ adb shell
|
|
56
|
+
设备 .39 / .133 (Buildroot Linux)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 为什么是手机 Termux 方案
|
|
62
|
+
|
|
63
|
+
早期方案是让 PC 跑 `mobile-mcp`(基于无障碍树的 Android 自动化)。实测发现设备是 **Buildroot Linux**(无 `getprop`、无 `wm`),无障碍树那套**完全无效**,只有纯 `adb shell` 路线能操作。
|
|
64
|
+
|
|
65
|
+
| 维度 | 手机 Termux 宿主角 | PC 端 mobile-mcp |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| 设备兼容性 | ✅ 纯 adb shell | ❌ 依赖无障碍树,非 Android 设备无效 |
|
|
68
|
+
| 设备可达性 | ✅ 手机连设备热点即可 | ❌ PC 必须与设备同网段 |
|
|
69
|
+
| 现场部署 | ✅ 手机 + 设备,无需 PC | ❌ 需 PC 参与 |
|
|
70
|
+
| 断线恢复 | ✅ 双端守护自动重连 | ❌ 仅单端 |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 特性
|
|
75
|
+
|
|
76
|
+
- **一键启动** —— Termux 里敲 `adbmcp` 即可,只启动 MCP 并输出接入信息
|
|
77
|
+
- **不打扰设备** —— 启动时不会主动连接任何设备;守护等设备接入后才开始工作
|
|
78
|
+
- **局域网直连** —— 任意 AI 客户端通过 `http://<手机IP>:8081/mcp` 接入,无需 PC 中转
|
|
79
|
+
- **固定 Token** —— 跨设备迁移时 AI 客户端配置无需改动
|
|
80
|
+
- **延后守护** —— 后台守护先等待设备接入,检测到设备后才开始维持连接
|
|
81
|
+
- **双端守护** —— 手机端守护 MCP 进程与设备连接,PC 端守护 adb 隧道,断线自动自愈
|
|
82
|
+
- **84 个工具** —— 基于 `termux-mcp` v0.15.0,含 shell 执行、文件读写、截图、通知等
|
|
83
|
+
- **危险命令拦截** —— 服务端识别高危命令并要求显式确认
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 快速开始
|
|
88
|
+
|
|
89
|
+
### 1. 手机装 Termux
|
|
90
|
+
|
|
91
|
+
从 **F-Droid** 或 GitHub 安装(**不要用 Play 商店的旧版**)。首次打开等它初始化完。
|
|
92
|
+
|
|
93
|
+
### 2. 安装
|
|
94
|
+
|
|
95
|
+
**方式 A · PyPI(推荐,无需传文件)**
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install termux-adbmcp
|
|
99
|
+
adbmcp
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
首次运行 `adbmcp` 会自动完成部署:复制脚本到 `~/bin`、安装依赖(`android-tools` +
|
|
103
|
+
`termux-mcp`)、打上游补丁。之后直接敲 `adbmcp` 即可。
|
|
104
|
+
|
|
105
|
+
**方式 B · 一行脚本**
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
curl -fsSL https://cdn.jsdelivr.net/gh/wu737/adbmcp@main/install/bootstrap.sh | bash
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**方式 C · 手动部署**
|
|
112
|
+
|
|
113
|
+
把 `install/install-adbmcp.sh` 与 `scripts/` 下的文件传到手机 Termux(`~/adbmcp/`),然后:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
cd ~/adbmcp
|
|
117
|
+
bash install/install-adbmcp.sh
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
脚本自动完成:装依赖(`android-tools` + `termux-mcp`)→ 部署脚本 → 建设备清单 → 启动自检 → 扫描网段找可连接设备。
|
|
121
|
+
|
|
122
|
+
### 3. 填设备清单
|
|
123
|
+
|
|
124
|
+
编辑 `~/mcp-servers/adbmcp/devices.txt`:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
192.168.43.1:5555 设备热点网关
|
|
128
|
+
192.168.110.39:5555 设备 - Buildroot/wise
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
adbmcp restart
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 4. 接入 AI 客户端
|
|
136
|
+
|
|
137
|
+
`adbmcp config` 直接打印可粘贴的配置:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"mcpServers": {
|
|
142
|
+
"adbmcp": {
|
|
143
|
+
"type": "streamableHttp",
|
|
144
|
+
"url": "http://192.168.110.13:8081/mcp",
|
|
145
|
+
"timeout": 120000,
|
|
146
|
+
"headers": { "Authorization": "Bearer <token>" }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
RikkaHub 专用格式见 [`examples/rikkahub-mcp-import.json`](examples/rikkahub-mcp-import.json)。
|
|
153
|
+
|
|
154
|
+
### 5. 用起来
|
|
155
|
+
|
|
156
|
+
在 AI 对话框里直接说人话,AI 会自己判断要不要调工具:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
现在 adb 里能连到哪些设备?分别是什么系统?
|
|
160
|
+
设备 192.168.110.39 上有哪些应用目录?
|
|
161
|
+
用 system_info 看一下手机 CPU 和内存
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 命令一览
|
|
167
|
+
|
|
168
|
+
| 命令 | 作用 |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `adbmcp` | 启动 + 打印接入信息(默认) |
|
|
171
|
+
| `adbmcp status` | 查看 MCP / 守护 / adb 设备状态 |
|
|
172
|
+
| `adbmcp config` | 打印可粘贴的 AI 客户端配置 |
|
|
173
|
+
| `adbmcp connect` | 手动连接设备清单里的设备 |
|
|
174
|
+
| `adbmcp token` | 显示当前固定 token |
|
|
175
|
+
| `adbmcp scan [网段]` | 扫描网段找出所有开 5555 的设备 |
|
|
176
|
+
| `adbmcp lan` / `adbmcp local` | 切换局域网模式(+token)/ 仅本机模式(免鉴权) |
|
|
177
|
+
| `adbmcp restart` / `stop` | 重启 / 停止 |
|
|
178
|
+
|
|
179
|
+
> **自动打补丁** —— `termux-mcp` v0.15.0 未实现 MCP 规范要求的 `notifications/*`
|
|
180
|
+
> 通知方法,客户端(尤其 RikkaHub)会因此报「Error while sending message」。
|
|
181
|
+
> `adbmcp` 每次启动都会自动检查并打上补丁(见
|
|
182
|
+
> [`scripts/patch_cancelled.py`](scripts/patch_cancelled.py)),pip 升级后同样自动重打。
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 依赖
|
|
187
|
+
|
|
188
|
+
| 依赖 | 版本 | 安装方式 |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| Termux | ≥ 0.118 | F-Droid / GitHub |
|
|
191
|
+
| android-tools (adb) | 37.0.0 | `pkg install android-tools` |
|
|
192
|
+
| python | 3.14.x | `pkg install python` |
|
|
193
|
+
| [termux-mcp](https://pypi.org/project/termux-mcp/) | 0.15.0 | `pip install termux-mcp==0.15.0` |
|
|
194
|
+
| Termux:Boot | — | 单独 APK(可选,用于开机自启) |
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## 目录结构
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
install/install-adbmcp.sh 一键安装
|
|
202
|
+
scripts/
|
|
203
|
+
adbmcp 主脚本(PATH 内,直接敲 adbmcp)
|
|
204
|
+
device_watchdog.sh 守护:MCP 进程 + 设备连接
|
|
205
|
+
device_setup.sh 手动连接设备
|
|
206
|
+
scan_device.py 网段扫描
|
|
207
|
+
boot_mcp.sh 开机自启入口
|
|
208
|
+
patch_cancelled.py 上游补丁(补齐 notifications/* 方法)
|
|
209
|
+
docs/ 详细文档
|
|
210
|
+
examples/ 各客户端配置示例
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
部署到手机后:
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
~/bin/adbmcp ← 主脚本
|
|
217
|
+
~/mcp-servers/adbmcp/ ← 设备清单、日志、配置
|
|
218
|
+
~/.termux/boot/boot_mcp.sh ← 开机自启
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 文档
|
|
224
|
+
|
|
225
|
+
| 文档 | 内容 |
|
|
226
|
+
|---|---|
|
|
227
|
+
| [快速开始](docs/快速开始.md) | 完整命令与机制说明 |
|
|
228
|
+
| [设备接入](docs/设备接入.md) | 设备识别、协议限制、故障排查 |
|
|
229
|
+
| [RikkaHub 接入](docs/RikkaHub-接入.md) | RikkaHub 两层配置(全局 MCP + 助手绑定)|
|
|
230
|
+
| [RikkaHub 对话使用](docs/RikkaHub-对话使用.md) | 实测可用的提问示例、路径权限边界 |
|
|
231
|
+
| [RikkaHub 工具调用排查](docs/RikkaHub-工具调用排查.md) | 「当前模型未开启工具调用」根因(源码级)|
|
|
232
|
+
| [迁移指南](docs/迁移指南.md) | 换新手机部署 |
|
|
233
|
+
| [诊断记录](docs/诊断记录-工具不可用.md) | 完整排查过程留档 |
|
|
234
|
+
| [对比 yhuangsh/adbmcp](docs/对比-yhuangsh-adbmcp.md) | 同名项目的区别(宿主位置 / 目标设备不同)|
|
|
235
|
+
| [排障 notifications/cancelled](docs/排障-notifications-cancelled.md) | RikkaHub 报「Error while sending message」的根因 |
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 关于同名项目
|
|
240
|
+
|
|
241
|
+
有一个也叫 `adbmcp` 的项目:[yhuangsh/adbmcp](https://github.com/yhuangsh/adbmcp)(npm 包 `@yhuangsh/adbmcp`)。
|
|
242
|
+
**两者不是同一个东西,名字相同纯属巧合**,可以并存:
|
|
243
|
+
|
|
244
|
+
| | yhuangsh/adbmcp | 本项目 |
|
|
245
|
+
|---|---|---|
|
|
246
|
+
| 宿主 | PC / 任意装 Node≥20 的机器 | **手机 Termux** |
|
|
247
|
+
| 目标设备 | **Android 手机** | **Buildroot Linux 设备** |
|
|
248
|
+
| 实现 | TypeScript 1300+ 行自研,37 工具 | Bash 复用 `termux-mcp`,84 工具 |
|
|
249
|
+
| 特色 | Android 深度集成(uiautomator/logcat/pm/input)、npm 分发、完整测试与 CI | 设备运维、手机即网关、零 Node 依赖、Token 固定 |
|
|
250
|
+
|
|
251
|
+
实测证据:对方的 Android 专属工具在设备上全部 `not found`(设备是 Buildroot,无 Android framework)。
|
|
252
|
+
详见 [对比文档](docs/对比-yhuangsh-adbmcp.md)。
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 安全须知
|
|
257
|
+
|
|
258
|
+
> ⚠️ **本项目默认使用固定 Token,且仓库中公开了默认值。**
|
|
259
|
+
|
|
260
|
+
- 服务绑定 `0.0.0.0` 时,**服务端强制要求 Token**(`termux-native-mcp` 的 `_check_startup_guards` 逻辑),无 Token 会直接拒绝启动
|
|
261
|
+
- 完全免鉴权只能绑 `127.0.0.1`(`adbmcp local`),那样局域网无法直连
|
|
262
|
+
- **默认 Token 是公开的**。若你的网络环境不完全可信,请改用随机值:
|
|
263
|
+
```bash
|
|
264
|
+
export ADBMCP_TOKEN=$(head -c 24 /dev/urandom | base64 | tr -d '/+=')
|
|
265
|
+
adbmcp restart
|
|
266
|
+
```
|
|
267
|
+
然后同步更新所有 AI 客户端配置
|
|
268
|
+
|
|
269
|
+
建议在 **RikkaHub / Claude 等客户端侧**给高危工具开启「需要审批」:
|
|
270
|
+
|
|
271
|
+
| 工具 | 风险 |
|
|
272
|
+
|---|---|
|
|
273
|
+
| `run` | ⚠️ 执行任意 shell —— 能操作设备、读写手机文件 |
|
|
274
|
+
| `write` / `delete` | 改 / 删文件(软删除,落在 `~/termuxGPT/trash/`)|
|
|
275
|
+
| `process_kill` | 杀进程 |
|
|
276
|
+
| `sms_send` | 发短信 |
|
|
277
|
+
| `camera_photo` | 拍照 |
|
|
278
|
+
|
|
279
|
+
只读类(`read` / `ls` / `search` / `system_info` / `battery`)无需审批。
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 已知限制
|
|
284
|
+
|
|
285
|
+
- **Termux 被杀 → MCP 进程消失。** 守护能扛住「Termux 存活但 MCP 挂掉」,Termux 整体被杀需重开 App(装 Termux:Boot 可自动拉起)
|
|
286
|
+
- **无线调试会因息屏断开。** 实测手机多次转 `offline`。对策:`termux-wake-lock`、关闭电池优化、或改用 USB
|
|
287
|
+
- **Termux 无 `ip` 命令权限**,`/proc/net/fib_trie` 也被 Android 11+ 收紧 → IP 探测改用 Python socket
|
|
288
|
+
- **Termux 版 adb 无 `adb mdns`** → 设备 IP 靠手填或 `adbmcp scan` 扫描
|
|
289
|
+
- **`run` 对含 `;` 的复合命令可能返回空** → 拆成单条分别调用
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# adbmcp
|
|
2
|
+
|
|
3
|
+
**Turn your Android phone into a remote control for your devices** — expose it as an MCP server so Claude, Cursor, RikkaHub, WorkBuddy, or any MCP-capable AI client can operate your vehicle via natural language.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
You say in RikkaHub: "Which devices are online right now? What OS do they run?"
|
|
7
|
+
↓
|
|
8
|
+
AI invokes an MCP tool
|
|
9
|
+
↓
|
|
10
|
+
Phone Termux (termux-native-mcp :8081)
|
|
11
|
+
↓ adb shell
|
|
12
|
+
Car units .39 / .133 (Buildroot Linux)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why the phone-as-host design
|
|
18
|
+
|
|
19
|
+
The first attempt ran `mobile-mcp` on the PC (accessibility-tree based Android automation). Testing showed the target devices run **Buildroot Linux** — no `getprop`, no `wm` — so the accessibility approach was **completely non-functional**. Only a pure `adb shell` route works.
|
|
20
|
+
|
|
21
|
+
| Dimension | Phone Termux host | PC-side mobile-mcp |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Car compatibility | ✅ pure adb shell | ❌ needs accessibility tree; non-Android head units fail |
|
|
24
|
+
| Reachability | ✅ phone joins the car's hotspot | ❌ PC must share the car's subnet |
|
|
25
|
+
| Field deployment | ✅ phone + car, no PC | ❌ PC required |
|
|
26
|
+
| Recovery | ✅ watchdog on both ends | ❌ single point |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **One-command launch** — type `adbmcp` in Termux; starts the MCP server and prints the connection info
|
|
33
|
+
- **Non-intrusive** — startup never connects to any device; the watchdog waits until a device appears
|
|
34
|
+
- **LAN direct access** — any AI client connects straight to `http://<phone-IP>:8081/mcp`, no PC relay
|
|
35
|
+
- **Fixed token** — AI client configs survive device migrations unchanged
|
|
36
|
+
- **Dual-end watchdog** — phone side guards the MCP process and device connections, PC side guards the adb tunnel; both self-heal
|
|
37
|
+
- **84 tools** — powered by `termux-mcp` v0.15.0: shell execution, file I/O, screenshot, notifications, and more
|
|
38
|
+
- **Dangerous-command gating** — the server flags high-risk commands and requires explicit confirmation
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
### 1. Install Termux on the phone
|
|
45
|
+
|
|
46
|
+
Use **F-Droid** or GitHub (do **not** use the outdated Play Store build). Let it finish initializing on first launch.
|
|
47
|
+
|
|
48
|
+
### 2. Deploy
|
|
49
|
+
|
|
50
|
+
Copy `install/install-adbmcp.sh` and everything under `scripts/` into `~/adbmcp/` on the phone, then:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cd ~/adbmcp
|
|
54
|
+
bash install/install-adbmcp.sh
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The script installs dependencies (`android-tools` + `termux-mcp`), deploys the scripts, creates the device manifest, starts and self-checks the server, and scans the subnet for adb devices.
|
|
58
|
+
|
|
59
|
+
### 3. Fill in the device manifest
|
|
60
|
+
|
|
61
|
+
Edit `~/mcp-servers/adbmcp/devices.txt`:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
192.168.43.1:5555 device hotspot gateway
|
|
65
|
+
192.168.110.39:5555 head unit - Buildroot/wise
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
adbmcp restart
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Connect your AI client
|
|
73
|
+
|
|
74
|
+
`adbmcp config` prints a ready-to-paste config:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"adbmcp": {
|
|
80
|
+
"type": "streamableHttp",
|
|
81
|
+
"url": "http://192.168.110.13:8081/mcp",
|
|
82
|
+
"timeout": 120000,
|
|
83
|
+
"headers": { "Authorization": "Bearer <token>" }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
See [`examples/rikkahub-mcp-import.json`](examples/rikkahub-mcp-import.json) for the RikkaHub-specific format.
|
|
90
|
+
|
|
91
|
+
### 5. Use it
|
|
92
|
+
|
|
93
|
+
Just talk to the AI in natural language — it decides when to call tools:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Which devices can adb reach right now, and what OS do they run?
|
|
97
|
+
What's in the application directory on 192.168.110.39?
|
|
98
|
+
Use system_info to check the phone's CPU and memory.
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Commands
|
|
104
|
+
|
|
105
|
+
| Command | Purpose |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `adbmcp` | Start and print connection info (default) |
|
|
108
|
+
| `adbmcp status` | MCP / watchdog / adb device status |
|
|
109
|
+
| `adbmcp config` | Print a paste-ready client config |
|
|
110
|
+
| `adbmcp connect` | Manually connect the devices in the manifest |
|
|
111
|
+
| `adbmcp token` | Show the current fixed token |
|
|
112
|
+
| `adbmcp scan [subnet]` | Find every device with port 5555 open |
|
|
113
|
+
| `adbmcp lan` / `adbmcp local` | LAN mode (with token) / localhost-only (no auth) |
|
|
114
|
+
| `adbmcp restart` / `stop` | Restart / stop |
|
|
115
|
+
|
|
116
|
+
> **Automatic patch** — `termux-mcp` v0.15.0 does not implement the `notifications/*`
|
|
117
|
+
> methods required by the MCP spec, which makes clients (RikkaHub in particular)
|
|
118
|
+
> report "Error while sending message". `adbmcp` checks and applies the patch on
|
|
119
|
+
> every start (see [`scripts/patch_cancelled.py`](scripts/patch_cancelled.py)),
|
|
120
|
+
> including after a `pip upgrade`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Dependencies
|
|
125
|
+
|
|
126
|
+
| Dependency | Version | Install |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| Termux | ≥ 0.118 | F-Droid / GitHub |
|
|
129
|
+
| android-tools (adb) | 37.0.0 | `pkg install android-tools` |
|
|
130
|
+
| python | 3.14.x | `pkg install python` |
|
|
131
|
+
| [termux-mcp](https://pypi.org/project/termux-mcp/) | 0.15.0 | `pip install termux-mcp==0.15.0` |
|
|
132
|
+
| Termux:Boot | — | separate APK (optional, enables boot autostart) |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Layout
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
install/install-adbmcp.sh one-shot installer
|
|
140
|
+
scripts/
|
|
141
|
+
adbmcp main script (on PATH, just type `adbmcp`)
|
|
142
|
+
device_watchdog.sh watchdog: MCP process + device connections
|
|
143
|
+
device_setup.sh manual device connection helper
|
|
144
|
+
scan_device.py subnet scanner
|
|
145
|
+
boot_mcp.sh boot autostart entry
|
|
146
|
+
patch_cancelled.py upstream patch (adds notifications/* handling)
|
|
147
|
+
docs/ detailed documentation
|
|
148
|
+
examples/ client config samples
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
After deployment on the phone:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
~/bin/adbmcp ← main script
|
|
155
|
+
~/mcp-servers/adbmcp/ ← manifest, logs, generated config
|
|
156
|
+
~/.termux/boot/boot_mcp.sh ← boot autostart
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Documentation
|
|
162
|
+
|
|
163
|
+
| Doc | Contents |
|
|
164
|
+
|---|---|
|
|
165
|
+
| [快速开始 (Chinese)](docs/快速开始.md) | Full command and mechanism reference |
|
|
166
|
+
| [设备接入 (Chinese)](docs/设备接入.md) | Car identification, protocol limits, troubleshooting |
|
|
167
|
+
| [迁移指南 (Chinese)](docs/迁移指南.md) | Deploying on a new phone |
|
|
168
|
+
| [RikkaHub 接入](docs/RikkaHub-接入.md) | RikkaHub's two-layer config (global MCP + assistant binding) |
|
|
169
|
+
| [RikkaHub 对话使用](docs/RikkaHub-对话使用.md) | Verified prompt examples, path permission boundaries |
|
|
170
|
+
| [RikkaHub 工具调用排查](docs/RikkaHub-工具调用排查.md) | Root cause of "model does not support tool calling" (source-level) |
|
|
171
|
+
| [诊断记录](docs/诊断记录-工具不可用.md) | Full troubleshooting log |
|
|
172
|
+
| [对比 yhuangsh/adbmcp](docs/对比-yhuangsh-adbmcp.md) | Differences from the same-named project |
|
|
173
|
+
| [Troubleshooting: notifications/cancelled](docs/排障-notifications-cancelled.md) | Root cause of RikkaHub's "Error while sending message" |
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## About the same-named project
|
|
178
|
+
|
|
179
|
+
There is another project also called `adbmcp`: [yhuangsh/adbmcp](https://github.com/yhuangsh/adbmcp)
|
|
180
|
+
(npm package `@yhuangsh/adbmcp`). **These are different projects** — the shared name is a
|
|
181
|
+
coincidence, and they coexist fine:
|
|
182
|
+
|
|
183
|
+
| | yhuangsh/adbmcp | this project |
|
|
184
|
+
|---|---|---|
|
|
185
|
+
| Host | PC / any machine with Node ≥20 | **phone running Termux** |
|
|
186
|
+
| Target device | **Android phones** | **Buildroot Linux devices** |
|
|
187
|
+
| Implementation | 1300+ lines of hand-written TypeScript, 37 tools | Bash on top of `termux-mcp`, 84 tools |
|
|
188
|
+
| Highlights | deep Android integration (uiautomator/logcat/pm/input), npm distribution, full test suite and CI | car-unit operations, phone-as-gateway, zero Node dependency, fixed token |
|
|
189
|
+
|
|
190
|
+
Measured evidence: the Android-specific tools on the other project all fail with `not found`
|
|
191
|
+
on a Buildroot device (no Android framework).
|
|
192
|
+
See the [comparison doc](docs/对比-yhuangsh-adbmcp.md).
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Security
|
|
197
|
+
|
|
198
|
+
> ⚠️ **This project ships a fixed default token, and that default is public in this repo.**
|
|
199
|
+
|
|
200
|
+
- When bound to `0.0.0.0`, the server **requires** a token — `termux-native-mcp`'s `_check_startup_guards` refuses to start without one
|
|
201
|
+
- A fully auth-free mode requires binding `127.0.0.1` (`adbmcp local`), which makes LAN access impossible
|
|
202
|
+
- **The default token is public.** If your network isn't fully trusted, generate a random one:
|
|
203
|
+
```bash
|
|
204
|
+
export ADBMCP_TOKEN=$(head -c 24 /dev/urandom | base64 | tr -d '/+=')
|
|
205
|
+
adbmcp restart
|
|
206
|
+
```
|
|
207
|
+
Then update the token in every AI client config.
|
|
208
|
+
|
|
209
|
+
On the client side (RikkaHub / Claude / …), enable "requires approval" for high-risk tools:
|
|
210
|
+
|
|
211
|
+
| Tool | Risk |
|
|
212
|
+
|---|---|
|
|
213
|
+
| `run` | ⚠️ executes arbitrary shell — can operate devices and read/write phone files |
|
|
214
|
+
| `write` / `delete` | modify / remove files (soft delete into `~/termuxGPT/trash/`) |
|
|
215
|
+
| `process_kill` | kill processes |
|
|
216
|
+
| `sms_send` | send SMS |
|
|
217
|
+
| `camera_photo` | take photos |
|
|
218
|
+
|
|
219
|
+
Read-only tools (`read` / `ls` / `search` / `system_info` / `battery`) need no approval.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Known limitations
|
|
224
|
+
|
|
225
|
+
- **Killing Termux kills the MCP process.** The watchdog handles "Termux alive but MCP dead"; a fully killed Termux needs the app reopened (Termux:Boot automates this).
|
|
226
|
+
- **Wireless debugging drops when the screen sleeps.** The phone was observed flipping to `offline` repeatedly. Workarounds: `termux-wake-lock`, disable battery optimization, or use USB.
|
|
227
|
+
- **No `ip` command permission in Termux**, and `/proc/net/fib_trie` is restricted on Android 11+ → IP detection falls back to a Python socket.
|
|
228
|
+
- **The Termux adb build has no `adb mdns`** → device IPs must be entered manually or found via `adbmcp scan`.
|
|
229
|
+
- **`run` may return empty output for compound commands containing `;`** → issue them separately.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|