damai-mcp 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.
- damai_mcp-0.2.0/CHANGELOG.md +26 -0
- damai_mcp-0.2.0/LICENSE +26 -0
- damai_mcp-0.2.0/PKG-INFO +247 -0
- damai_mcp-0.2.0/README.md +213 -0
- damai_mcp-0.2.0/pyproject.toml +75 -0
- damai_mcp-0.2.0/setup.cfg +4 -0
- damai_mcp-0.2.0/src/damai_mcp/__init__.py +6 -0
- damai_mcp-0.2.0/src/damai_mcp/__main__.py +5 -0
- damai_mcp-0.2.0/src/damai_mcp/actions/__init__.py +28 -0
- damai_mcp-0.2.0/src/damai_mcp/actions/actions.py +192 -0
- damai_mcp-0.2.0/src/damai_mcp/actions/batch.py +92 -0
- damai_mcp-0.2.0/src/damai_mcp/app/__init__.py +24 -0
- damai_mcp-0.2.0/src/damai_mcp/app/profile.py +185 -0
- damai_mcp-0.2.0/src/damai_mcp/app/profiles/__init__.py +20 -0
- damai_mcp-0.2.0/src/damai_mcp/app/profiles/damai.py +33 -0
- damai_mcp-0.2.0/src/damai_mcp/app/profiles/fliggy.py +52 -0
- damai_mcp-0.2.0/src/damai_mcp/app/profiles/maoyan.py +59 -0
- damai_mcp-0.2.0/src/damai_mcp/app/runner.py +248 -0
- damai_mcp-0.2.0/src/damai_mcp/damai/__init__.py +5 -0
- damai_mcp-0.2.0/src/damai_mcp/damai/actions.py +405 -0
- damai_mcp-0.2.0/src/damai_mcp/damai/checklist.py +308 -0
- damai_mcp-0.2.0/src/damai_mcp/damai/selectors.py +63 -0
- damai_mcp-0.2.0/src/damai_mcp/device/__init__.py +1 -0
- damai_mcp-0.2.0/src/damai_mcp/device/adb.py +150 -0
- damai_mcp-0.2.0/src/damai_mcp/device/manager.py +180 -0
- damai_mcp-0.2.0/src/damai_mcp/inspector/__init__.py +1 -0
- damai_mcp-0.2.0/src/damai_mcp/inspector/dump.py +116 -0
- damai_mcp-0.2.0/src/damai_mcp/inspector/find.py +264 -0
- damai_mcp-0.2.0/src/damai_mcp/inspector/models.py +80 -0
- damai_mcp-0.2.0/src/damai_mcp/server.py +915 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/__init__.py +26 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/errors.py +50 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/find_helpers.py +94 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/logging.py +40 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/ntp.py +156 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/retry.py +58 -0
- damai_mcp-0.2.0/src/damai_mcp/utils/ui_cache.py +104 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/PKG-INFO +247 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/SOURCES.txt +51 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/dependency_links.txt +1 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/entry_points.txt +2 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/requires.txt +13 -0
- damai_mcp-0.2.0/src/damai_mcp.egg-info/top_level.txt +1 -0
- damai_mcp-0.2.0/tests/test_actions.py +118 -0
- damai_mcp-0.2.0/tests/test_adb.py +104 -0
- damai_mcp-0.2.0/tests/test_app.py +192 -0
- damai_mcp-0.2.0/tests/test_checklist.py +191 -0
- damai_mcp-0.2.0/tests/test_damai.py +58 -0
- damai_mcp-0.2.0/tests/test_models.py +45 -0
- damai_mcp-0.2.0/tests/test_ntp.py +180 -0
- damai_mcp-0.2.0/tests/test_optimizations.py +223 -0
- damai_mcp-0.2.0/tests/test_retry.py +82 -0
- damai_mcp-0.2.0/tests/test_server.py +62 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Planned
|
|
11
|
+
- L4 业务层:猫眼/飞猪抢票
|
|
12
|
+
- 滑块验证码识别(OpenCV + ddddocr)
|
|
13
|
+
- 录制-回放工作流
|
|
14
|
+
- MCP 官方注册表提交
|
|
15
|
+
|
|
16
|
+
## [0.1.0] - 2026-07-09
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- L1 设备管理:list_devices, connect, disconnect, device_info
|
|
20
|
+
- L2 原子操作:tap, double_tap, long_press, swipe, input_text, press_key, scroll, screenshot
|
|
21
|
+
- L3 语义操作:dump_ui, find_by_text/resource_id/xpath, wait_for_text, wait_for_element
|
|
22
|
+
- L4 大麦业务:damai_login_check, damai_open_concert, damai_select_price, damai_select_viewer, damai_grab
|
|
23
|
+
- FastMCP server 注册全部工具
|
|
24
|
+
- CLI 启动脚本 `damai-mcp serve`
|
|
25
|
+
- 完整 README + 文档
|
|
26
|
+
- pytest 测试覆盖核心逻辑
|
damai_mcp-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 damai-mcp 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.
|
|
22
|
+
|
|
23
|
+
DISCLAIMER: This software is provided for educational and research purposes only.
|
|
24
|
+
The authors are not responsible for any misuse of this software. Users are solely
|
|
25
|
+
responsible for ensuring their use complies with all applicable laws and the terms
|
|
26
|
+
of service of any platforms they interact with.
|
damai_mcp-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: damai-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Android Emulator MCP for ticket-grabbing automation (大麦 / 猫眼 / 飞猪)
|
|
5
|
+
Author: damai-mcp contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-org/damai-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/your-org/damai-mcp/issues
|
|
9
|
+
Keywords: mcp,android,adb,ticket,damai,automation
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: mcp>=1.0
|
|
22
|
+
Requires-Dist: pydantic>=2.5
|
|
23
|
+
Requires-Dist: loguru>=0.7
|
|
24
|
+
Requires-Dist: Pillow>=10.0
|
|
25
|
+
Requires-Dist: lxml>=5.0
|
|
26
|
+
Requires-Dist: aiohttp>=3.9
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=4.1; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# 🎫 damai-mcp
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/damai-mcp/)
|
|
38
|
+
[]()
|
|
39
|
+
[]()
|
|
40
|
+
[](https://modelcontextprotocol.io)
|
|
41
|
+
|
|
42
|
+
> Android 设备自动化 MCP — 让你的 AI 直接操控手机/模拟器抢大麦 / 猫眼 / 飞猪门票。
|
|
43
|
+
|
|
44
|
+
大热门场次(¥921 + 0.5 秒开抢)下,**手动抢等于送人头**。本项目用 [Model Context Protocol](https://modelcontextprotocol.io) 把 ADB 操作封装成 30+ 个工具,让 Claude Code / Cursor / 自定义 Agent 都能像人一样操作大麦 APP,关键路径比手快 200~500 ms。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ✨ 核心特性
|
|
49
|
+
|
|
50
|
+
| | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| 🪜 **4 层架构** | L1 设备管理 / L2 原子操作 / L3 语义查询 / L4 业务编排 |
|
|
53
|
+
| 🚀 **零依赖额外二进制** | 复用本地 `adb`(雷电 / MuMu / SDK 都自带) |
|
|
54
|
+
| 🔌 **标准 MCP 协议** | 直接接入 Claude Code / Cursor / Cline / Continue |
|
|
55
|
+
| 🧠 **大麦专属** | `damai_grab()` 一行调用完成"等开票 → 抢档 → 选人 → 提交" |
|
|
56
|
+
| 📸 **自动截图归档** | 失败时自动存 `damai_shots/` 便于复盘 |
|
|
57
|
+
| ⏱️ **毫秒级等待** | 内部用 `asyncio` 高精度 sleep,不浪费开票瞬间 |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🚀 30 秒上手
|
|
62
|
+
|
|
63
|
+
### 1. 安装
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install damai-mcp
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. 准备设备(任选其一)
|
|
70
|
+
|
|
71
|
+
| 设备类型 | ADB 端口 | 优点 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| 雷电模拟器 9 | 127.0.0.1:5555 | 稳定、可多开、免费 |
|
|
74
|
+
| MuMu 模拟器 | 127.0.0.1:7555 | 性能好 |
|
|
75
|
+
| 真机(USB) | 自动检测 | 最真实 |
|
|
76
|
+
|
|
77
|
+
启动后确保大麦 APP 已装好并扫码登录。
|
|
78
|
+
|
|
79
|
+
### 3. 验证连接
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
damai-mcp list-devices
|
|
83
|
+
# adb: C:\Program Files\LDPlayer\adb.exe
|
|
84
|
+
# 127.0.0.1:5555 device HUAWEI Pura 70 Pro 1080x2400 EMU
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 4. 启动 MCP server(给 Claude Code / Cursor 用)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
damai-mcp serve
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
然后在 Claude Code 的 `~/.claude/settings.json` 加入:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"damai": {
|
|
99
|
+
"command": "damai-mcp",
|
|
100
|
+
"args": ["serve"]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
重启 Claude Code,对话框就能看到 30+ 个 `damai__*` 工具。
|
|
107
|
+
|
|
108
|
+
### 5. 一句话让 AI 帮你抢
|
|
109
|
+
|
|
110
|
+
> "用 127.0.0.1:5555 这台设备帮我抢 item 1063631004645,第二档,杨安琪的票,17:21 开票"
|
|
111
|
+
|
|
112
|
+
AI 会自动串联:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
list_devices → damai_check_login → damai_open_concert
|
|
116
|
+
↓ 等待开票
|
|
117
|
+
damai_grab → 失败截图存到 damai_shots/grab_fail_xxx.png
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 📐 架构(4 层工具)
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
┌─────────────────────────────────────────────────────────┐
|
|
126
|
+
│ L4 业务编排 damai_grab, damai_grab_multi, damai_pay │ ← AI 直接用
|
|
127
|
+
├─────────────────────────────────────────────────────────┤
|
|
128
|
+
│ L3 语义查询 find_text, find_resource_id, find_xpath, │ ← 用语义操作
|
|
129
|
+
│ wait_for_element, dump_ui │ UI 而不是坐标
|
|
130
|
+
├─────────────────────────────────────────────────────────┤
|
|
131
|
+
│ L2 原子操作 tap, swipe, input_text, press_key, │ ← 调试时用
|
|
132
|
+
│ screenshot, scroll, long_press │
|
|
133
|
+
├─────────────────────────────────────────────────────────┤
|
|
134
|
+
│ L1 设备管理 list_devices, connect_device, │ ← 一切的开端
|
|
135
|
+
│ device_info, disconnect_device │
|
|
136
|
+
└─────────────────────────────────────────────────────────┘
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**核心原则**:AI 应该用 L3 语义工具,而不是 L2 坐标工具。大麦改版时坐标会失效,但"立即购买"这 4 个字永远在那里。
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 🛠️ 直接调用(不用 MCP)
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
import asyncio
|
|
147
|
+
from damai_mcp.damai.actions import damai_grab
|
|
148
|
+
|
|
149
|
+
async def main():
|
|
150
|
+
result = await damai_grab(
|
|
151
|
+
device_id="127.0.0.1:5555",
|
|
152
|
+
item_id="1063631004645",
|
|
153
|
+
price_index=2,
|
|
154
|
+
viewer_names=["杨安琪"],
|
|
155
|
+
open_time="2026-07-09 17:21:00",
|
|
156
|
+
preheat_seconds=30,
|
|
157
|
+
)
|
|
158
|
+
print(result)
|
|
159
|
+
|
|
160
|
+
asyncio.run(main())
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
或者命令行:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
python examples/grab_one_ticket.py \
|
|
167
|
+
--device 127.0.0.1:5555 \
|
|
168
|
+
--item 1063631004645 \
|
|
169
|
+
--price 2 \
|
|
170
|
+
--viewer "杨安琪" \
|
|
171
|
+
--open "2026-07-09 17:21:00"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🧰 实战示例
|
|
177
|
+
|
|
178
|
+
### 抢一张票(单设备)
|
|
179
|
+
|
|
180
|
+
参见 [`examples/grab_one_ticket.py`](examples/grab_one_ticket.py)。
|
|
181
|
+
|
|
182
|
+
### 多账号并发(5 个模拟器)
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
python examples/multi_devices.py \
|
|
186
|
+
--item 1063631004645 \
|
|
187
|
+
--price 2 \
|
|
188
|
+
--devices 127.0.0.1:5555 127.0.0.1:5557 127.0.0.1:5559 \
|
|
189
|
+
--viewers 杨安琪 张三 李四 \
|
|
190
|
+
--open "2026-07-09 17:21:00"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 当大麦改版时更新选择器
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
python examples/probe_selectors.py --device 127.0.0.1:5555
|
|
197
|
+
# 输出所有可点击元素,更新 damai_mcp/damai/selectors.py
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 🧪 开发
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
git clone https://github.com/your-org/damai-mcp
|
|
206
|
+
cd damai-mcp
|
|
207
|
+
pip install -e ".[dev]"
|
|
208
|
+
|
|
209
|
+
# 测试(不需要真机/模拟器)
|
|
210
|
+
pytest
|
|
211
|
+
|
|
212
|
+
# Lint + 类型检查
|
|
213
|
+
ruff check src tests
|
|
214
|
+
mypy src
|
|
215
|
+
|
|
216
|
+
# 跑 example
|
|
217
|
+
python examples/grab_one_ticket.py --device 127.0.0.1:5555 --item TEST
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## ⚠️ 合规与免责
|
|
223
|
+
|
|
224
|
+
本项目仅供**学习与研究自动化测试技术**。请遵守:
|
|
225
|
+
|
|
226
|
+
1. 大麦 / 猫眼 / 飞猪的用户协议
|
|
227
|
+
2. 中国《反不正当竞争法》《消费者权益保护法》等法规
|
|
228
|
+
3. 抢到的票请在订单生成后 15 分钟内手动完成支付
|
|
229
|
+
|
|
230
|
+
作者不对因使用本项目造成的任何账号封禁、法律纠纷或经济损失负责。
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 🤝 贡献
|
|
235
|
+
|
|
236
|
+
欢迎 PR!特别是:
|
|
237
|
+
|
|
238
|
+
- 猫眼 / 飞猪的 L4 业务封装(目前只实现了大麦)
|
|
239
|
+
- 滑块验证码自动识别(OpenCV / ddddocr / 打码平台)
|
|
240
|
+
- 录制-回放工作流(让你能"录一遍下次自动跑")
|
|
241
|
+
- 新模拟器适配(夜神 / 逍遥 / BlueStacks)
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 📜 License
|
|
246
|
+
|
|
247
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# 🎫 damai-mcp
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/damai-mcp/)
|
|
4
|
+
[]()
|
|
5
|
+
[]()
|
|
6
|
+
[](https://modelcontextprotocol.io)
|
|
7
|
+
|
|
8
|
+
> Android 设备自动化 MCP — 让你的 AI 直接操控手机/模拟器抢大麦 / 猫眼 / 飞猪门票。
|
|
9
|
+
|
|
10
|
+
大热门场次(¥921 + 0.5 秒开抢)下,**手动抢等于送人头**。本项目用 [Model Context Protocol](https://modelcontextprotocol.io) 把 ADB 操作封装成 30+ 个工具,让 Claude Code / Cursor / 自定义 Agent 都能像人一样操作大麦 APP,关键路径比手快 200~500 ms。
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## ✨ 核心特性
|
|
15
|
+
|
|
16
|
+
| | |
|
|
17
|
+
|---|---|
|
|
18
|
+
| 🪜 **4 层架构** | L1 设备管理 / L2 原子操作 / L3 语义查询 / L4 业务编排 |
|
|
19
|
+
| 🚀 **零依赖额外二进制** | 复用本地 `adb`(雷电 / MuMu / SDK 都自带) |
|
|
20
|
+
| 🔌 **标准 MCP 协议** | 直接接入 Claude Code / Cursor / Cline / Continue |
|
|
21
|
+
| 🧠 **大麦专属** | `damai_grab()` 一行调用完成"等开票 → 抢档 → 选人 → 提交" |
|
|
22
|
+
| 📸 **自动截图归档** | 失败时自动存 `damai_shots/` 便于复盘 |
|
|
23
|
+
| ⏱️ **毫秒级等待** | 内部用 `asyncio` 高精度 sleep,不浪费开票瞬间 |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🚀 30 秒上手
|
|
28
|
+
|
|
29
|
+
### 1. 安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install damai-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. 准备设备(任选其一)
|
|
36
|
+
|
|
37
|
+
| 设备类型 | ADB 端口 | 优点 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| 雷电模拟器 9 | 127.0.0.1:5555 | 稳定、可多开、免费 |
|
|
40
|
+
| MuMu 模拟器 | 127.0.0.1:7555 | 性能好 |
|
|
41
|
+
| 真机(USB) | 自动检测 | 最真实 |
|
|
42
|
+
|
|
43
|
+
启动后确保大麦 APP 已装好并扫码登录。
|
|
44
|
+
|
|
45
|
+
### 3. 验证连接
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
damai-mcp list-devices
|
|
49
|
+
# adb: C:\Program Files\LDPlayer\adb.exe
|
|
50
|
+
# 127.0.0.1:5555 device HUAWEI Pura 70 Pro 1080x2400 EMU
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. 启动 MCP server(给 Claude Code / Cursor 用)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
damai-mcp serve
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
然后在 Claude Code 的 `~/.claude/settings.json` 加入:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"mcpServers": {
|
|
64
|
+
"damai": {
|
|
65
|
+
"command": "damai-mcp",
|
|
66
|
+
"args": ["serve"]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
重启 Claude Code,对话框就能看到 30+ 个 `damai__*` 工具。
|
|
73
|
+
|
|
74
|
+
### 5. 一句话让 AI 帮你抢
|
|
75
|
+
|
|
76
|
+
> "用 127.0.0.1:5555 这台设备帮我抢 item 1063631004645,第二档,杨安琪的票,17:21 开票"
|
|
77
|
+
|
|
78
|
+
AI 会自动串联:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
list_devices → damai_check_login → damai_open_concert
|
|
82
|
+
↓ 等待开票
|
|
83
|
+
damai_grab → 失败截图存到 damai_shots/grab_fail_xxx.png
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 📐 架构(4 层工具)
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
┌─────────────────────────────────────────────────────────┐
|
|
92
|
+
│ L4 业务编排 damai_grab, damai_grab_multi, damai_pay │ ← AI 直接用
|
|
93
|
+
├─────────────────────────────────────────────────────────┤
|
|
94
|
+
│ L3 语义查询 find_text, find_resource_id, find_xpath, │ ← 用语义操作
|
|
95
|
+
│ wait_for_element, dump_ui │ UI 而不是坐标
|
|
96
|
+
├─────────────────────────────────────────────────────────┤
|
|
97
|
+
│ L2 原子操作 tap, swipe, input_text, press_key, │ ← 调试时用
|
|
98
|
+
│ screenshot, scroll, long_press │
|
|
99
|
+
├─────────────────────────────────────────────────────────┤
|
|
100
|
+
│ L1 设备管理 list_devices, connect_device, │ ← 一切的开端
|
|
101
|
+
│ device_info, disconnect_device │
|
|
102
|
+
└─────────────────────────────────────────────────────────┘
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**核心原则**:AI 应该用 L3 语义工具,而不是 L2 坐标工具。大麦改版时坐标会失效,但"立即购买"这 4 个字永远在那里。
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 🛠️ 直接调用(不用 MCP)
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import asyncio
|
|
113
|
+
from damai_mcp.damai.actions import damai_grab
|
|
114
|
+
|
|
115
|
+
async def main():
|
|
116
|
+
result = await damai_grab(
|
|
117
|
+
device_id="127.0.0.1:5555",
|
|
118
|
+
item_id="1063631004645",
|
|
119
|
+
price_index=2,
|
|
120
|
+
viewer_names=["杨安琪"],
|
|
121
|
+
open_time="2026-07-09 17:21:00",
|
|
122
|
+
preheat_seconds=30,
|
|
123
|
+
)
|
|
124
|
+
print(result)
|
|
125
|
+
|
|
126
|
+
asyncio.run(main())
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
或者命令行:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python examples/grab_one_ticket.py \
|
|
133
|
+
--device 127.0.0.1:5555 \
|
|
134
|
+
--item 1063631004645 \
|
|
135
|
+
--price 2 \
|
|
136
|
+
--viewer "杨安琪" \
|
|
137
|
+
--open "2026-07-09 17:21:00"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🧰 实战示例
|
|
143
|
+
|
|
144
|
+
### 抢一张票(单设备)
|
|
145
|
+
|
|
146
|
+
参见 [`examples/grab_one_ticket.py`](examples/grab_one_ticket.py)。
|
|
147
|
+
|
|
148
|
+
### 多账号并发(5 个模拟器)
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
python examples/multi_devices.py \
|
|
152
|
+
--item 1063631004645 \
|
|
153
|
+
--price 2 \
|
|
154
|
+
--devices 127.0.0.1:5555 127.0.0.1:5557 127.0.0.1:5559 \
|
|
155
|
+
--viewers 杨安琪 张三 李四 \
|
|
156
|
+
--open "2026-07-09 17:21:00"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 当大麦改版时更新选择器
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python examples/probe_selectors.py --device 127.0.0.1:5555
|
|
163
|
+
# 输出所有可点击元素,更新 damai_mcp/damai/selectors.py
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 🧪 开发
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
git clone https://github.com/your-org/damai-mcp
|
|
172
|
+
cd damai-mcp
|
|
173
|
+
pip install -e ".[dev]"
|
|
174
|
+
|
|
175
|
+
# 测试(不需要真机/模拟器)
|
|
176
|
+
pytest
|
|
177
|
+
|
|
178
|
+
# Lint + 类型检查
|
|
179
|
+
ruff check src tests
|
|
180
|
+
mypy src
|
|
181
|
+
|
|
182
|
+
# 跑 example
|
|
183
|
+
python examples/grab_one_ticket.py --device 127.0.0.1:5555 --item TEST
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## ⚠️ 合规与免责
|
|
189
|
+
|
|
190
|
+
本项目仅供**学习与研究自动化测试技术**。请遵守:
|
|
191
|
+
|
|
192
|
+
1. 大麦 / 猫眼 / 飞猪的用户协议
|
|
193
|
+
2. 中国《反不正当竞争法》《消费者权益保护法》等法规
|
|
194
|
+
3. 抢到的票请在订单生成后 15 分钟内手动完成支付
|
|
195
|
+
|
|
196
|
+
作者不对因使用本项目造成的任何账号封禁、法律纠纷或经济损失负责。
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 🤝 贡献
|
|
201
|
+
|
|
202
|
+
欢迎 PR!特别是:
|
|
203
|
+
|
|
204
|
+
- 猫眼 / 飞猪的 L4 业务封装(目前只实现了大麦)
|
|
205
|
+
- 滑块验证码自动识别(OpenCV / ddddocr / 打码平台)
|
|
206
|
+
- 录制-回放工作流(让你能"录一遍下次自动跑")
|
|
207
|
+
- 新模拟器适配(夜神 / 逍遥 / BlueStacks)
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 📜 License
|
|
212
|
+
|
|
213
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "damai-mcp"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Android Emulator MCP for ticket-grabbing automation (大麦 / 猫眼 / 飞猪)"
|
|
9
|
+
readme = {file = "README.md", content-type = "text/markdown"}
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "damai-mcp contributors" }]
|
|
13
|
+
keywords = ["mcp", "android", "adb", "ticket", "damai", "automation"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Software Development :: Libraries",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"mcp>=1.0",
|
|
26
|
+
"pydantic>=2.5",
|
|
27
|
+
"loguru>=0.7",
|
|
28
|
+
"Pillow>=10.0",
|
|
29
|
+
"lxml>=5.0",
|
|
30
|
+
"aiohttp>=3.9",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8.0",
|
|
36
|
+
"pytest-asyncio>=0.23",
|
|
37
|
+
"pytest-cov>=4.1",
|
|
38
|
+
"ruff>=0.4",
|
|
39
|
+
"mypy>=1.10",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
damai-mcp = "damai_mcp.server:main"
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/your-org/damai-mcp"
|
|
47
|
+
Issues = "https://github.com/your-org/damai-mcp/issues"
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.packages.find]
|
|
50
|
+
where = ["src"]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 110
|
|
54
|
+
target-version = "py310"
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
asyncio_mode = "auto"
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
python_version = "3.10"
|
|
65
|
+
strict_optional = true
|
|
66
|
+
warn_unused_ignores = true
|
|
67
|
+
|
|
68
|
+
[tool.setuptools.package-data]
|
|
69
|
+
"damai_mcp" = ["py.typed"]
|
|
70
|
+
|
|
71
|
+
[tool.setuptools]
|
|
72
|
+
include-package-data = true
|
|
73
|
+
|
|
74
|
+
[tool.setuptools.data-files]
|
|
75
|
+
"." = ["README.md", "LICENSE", "CHANGELOG.md"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Atomic UI actions — single-shot + batch flavours."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from .actions import (
|
|
5
|
+
double_tap,
|
|
6
|
+
input_text,
|
|
7
|
+
long_press,
|
|
8
|
+
press_key,
|
|
9
|
+
screenshot,
|
|
10
|
+
scroll,
|
|
11
|
+
swipe,
|
|
12
|
+
tap,
|
|
13
|
+
)
|
|
14
|
+
from .batch import batch_send, batch_swipe, batch_tap
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"tap",
|
|
18
|
+
"double_tap",
|
|
19
|
+
"long_press",
|
|
20
|
+
"swipe",
|
|
21
|
+
"scroll",
|
|
22
|
+
"input_text",
|
|
23
|
+
"press_key",
|
|
24
|
+
"screenshot",
|
|
25
|
+
"batch_tap",
|
|
26
|
+
"batch_swipe",
|
|
27
|
+
"batch_send",
|
|
28
|
+
]
|