mobile-mcp-ai 2.6.10__py3-none-any.whl → 2.6.12__py3-none-any.whl
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.
- mobile_mcp/config.py +32 -0
- mobile_mcp/core/basic_tools_lite.py +801 -1823
- mobile_mcp/core/tool_selection_helper.py +168 -0
- mobile_mcp/mcp_tools/mcp_server.py +337 -455
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/METADATA +19 -12
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/RECORD +10 -9
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/WHEEL +0 -0
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/entry_points.txt +0 -0
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/licenses/LICENSE +0 -0
- {mobile_mcp_ai-2.6.10.dist-info → mobile_mcp_ai-2.6.12.dist-info}/top_level.txt +0 -0
|
@@ -102,12 +102,19 @@ class MobileMCPServer:
|
|
|
102
102
|
self.tools = None
|
|
103
103
|
self._initialized = False
|
|
104
104
|
self._last_error = None # 保存最后一次连接失败的错误
|
|
105
|
+
|
|
106
|
+
# Token 优化配置
|
|
107
|
+
try:
|
|
108
|
+
from mobile_mcp.config import Config
|
|
109
|
+
self._compact_desc = Config.COMPACT_TOOL_DESCRIPTION
|
|
110
|
+
except ImportError:
|
|
111
|
+
self._compact_desc = True # 默认开启精简模式
|
|
105
112
|
|
|
106
113
|
@staticmethod
|
|
107
114
|
def format_response(result) -> str:
|
|
108
|
-
"""
|
|
115
|
+
"""统一格式化返回值(Token 优化:无缩进)"""
|
|
109
116
|
if isinstance(result, (dict, list)):
|
|
110
|
-
return json.dumps(result, ensure_ascii=False,
|
|
117
|
+
return json.dumps(result, ensure_ascii=False, separators=(',', ':'))
|
|
111
118
|
return str(result)
|
|
112
119
|
|
|
113
120
|
async def initialize(self):
|
|
@@ -198,42 +205,83 @@ class MobileMCPServer:
|
|
|
198
205
|
return "android"
|
|
199
206
|
|
|
200
207
|
def get_tools(self):
|
|
201
|
-
"""注册 MCP
|
|
208
|
+
"""注册 MCP 工具"""
|
|
202
209
|
tools = []
|
|
203
210
|
|
|
211
|
+
# 根据配置选择精简或完整描述
|
|
212
|
+
compact = getattr(self, '_compact_desc', True)
|
|
213
|
+
|
|
204
214
|
# ==================== 元素定位(优先使用)====================
|
|
215
|
+
if compact:
|
|
216
|
+
desc_list_elements = "📋 【首选】列出页面元素(token低)。返回text/id用于点击,替代截图确认页面状态。"
|
|
217
|
+
else:
|
|
218
|
+
desc_list_elements = ("📋 【⭐首选工具】列出页面所有可交互元素\n\n"
|
|
219
|
+
"🚀 Token 优化:返回文本数据(~500 tokens),远小于截图(~2000 tokens)!\n\n"
|
|
220
|
+
"✅ 推荐使用场景:\n"
|
|
221
|
+
"- 点击前确认元素存在\n"
|
|
222
|
+
"- 点击后确认页面变化(替代截图确认)\n"
|
|
223
|
+
"- 获取 text/id 用于 click_by_text/click_by_id\n\n"
|
|
224
|
+
"❌ 不要用截图确认页面,用此工具!\n"
|
|
225
|
+
"📌 只有需要看视觉布局时才用截图")
|
|
226
|
+
|
|
205
227
|
tools.append(Tool(
|
|
206
228
|
name="mobile_list_elements",
|
|
207
|
-
description="📋
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
229
|
+
description="""📋 列出页面所有可交互元素(⭐⭐ 第一优先级!)
|
|
230
|
+
|
|
231
|
+
⚠️ 【核心原则】优先使用控件树定位,截图仅作为兜底方案
|
|
232
|
+
|
|
233
|
+
🎯 使用场景(优先使用):
|
|
234
|
+
1. ✅ 首次进入页面时:获取所有可交互元素
|
|
235
|
+
2. ✅ 查找特定元素时:检查元素是否存在
|
|
236
|
+
3. ✅ 验证操作结果时:确认元素是否出现/消失
|
|
237
|
+
4. ✅ 需要精确点击时:获取元素的 resource_id 或 text
|
|
238
|
+
|
|
239
|
+
📌 控件树定位优势:
|
|
240
|
+
- ⚡ 速度快:直接获取 XML,无需截图和图像处理(快 5-20 倍)
|
|
241
|
+
- 🎯 准确:获取完整的元素属性(resource_id、text、bounds、clickable 等)
|
|
242
|
+
- 💾 高效:不生成图片文件,节省存储和传输
|
|
243
|
+
- 🔄 可复用:一次获取的元素列表可用于多次操作
|
|
244
|
+
|
|
245
|
+
⚡ 推荐流程:
|
|
246
|
+
1. 调用 mobile_list_elements() 获取元素列表
|
|
247
|
+
2. 从元素列表中找到目标元素(通过 text 或 resource_id)
|
|
248
|
+
3. 使用 mobile_click_by_text() 或 mobile_click_by_id() 点击
|
|
249
|
+
4. 仅在控件树找不到元素时,才使用 mobile_screenshot_with_som()
|
|
250
|
+
|
|
251
|
+
❌ 错误用法:
|
|
252
|
+
- 每次都先截图,不先调用 list_elements
|
|
253
|
+
- 重复调用 list_elements,不复用已获取的元素列表
|
|
254
|
+
|
|
255
|
+
✅ 正确用法:
|
|
256
|
+
elements = mobile_list_elements() # 一次获取
|
|
257
|
+
mobile_click_by_text("设置") # 直接点击
|
|
258
|
+
mobile_click_by_text("退出登录") # 复用元素列表""",
|
|
215
259
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
216
260
|
))
|
|
217
261
|
|
|
218
262
|
# ==================== 截图(视觉兜底)====================
|
|
263
|
+
if compact:
|
|
264
|
+
desc_screenshot = "📸 截图(token高~2000)。优先用list_elements(~500)确认页面状态。"
|
|
265
|
+
else:
|
|
266
|
+
desc_screenshot = ("📸 截图查看屏幕内容(⚠️ Token 消耗高 ~2000)\n\n"
|
|
267
|
+
"❌ 【不推荐】确认页面状态请用 list_elements(Token 仅 ~500)!\n\n"
|
|
268
|
+
"✅ 仅在以下场景使用:\n"
|
|
269
|
+
"- 需要看视觉布局/图片内容\n"
|
|
270
|
+
"- 元素无 text/id,只能靠位置点击\n"
|
|
271
|
+
"- 调试问题需要可视化\n\n"
|
|
272
|
+
"💡 compress=false 可获取原图(用于添加模板)")
|
|
273
|
+
|
|
219
274
|
tools.append(Tool(
|
|
220
275
|
name="mobile_take_screenshot",
|
|
221
|
-
description=
|
|
222
|
-
"⚠️ 【推荐使用 mobile_screenshot_with_som 代替!】\n"
|
|
223
|
-
"SoM 截图会给元素标号,AI 可以直接说'点击几号',更精准!\n\n"
|
|
224
|
-
"🎯 本工具仅用于:\n"
|
|
225
|
-
"- 快速确认页面状态(不需要点击时)\n"
|
|
226
|
-
"- 操作后确认结果\n"
|
|
227
|
-
"- compress=false 时可获取原始分辨率截图(用于添加模板)\n\n"
|
|
228
|
-
"💡 如需点击元素,请用 mobile_screenshot_with_som + mobile_click_by_som",
|
|
276
|
+
description=desc_screenshot,
|
|
229
277
|
inputSchema={
|
|
230
278
|
"type": "object",
|
|
231
279
|
"properties": {
|
|
232
|
-
"description": {"type": "string", "description": "
|
|
233
|
-
"compress": {"type": "boolean", "description": "
|
|
234
|
-
"crop_x": {"type": "integer", "description": "
|
|
235
|
-
"crop_y": {"type": "integer", "description": "
|
|
236
|
-
"crop_size": {"type": "integer", "description": "
|
|
280
|
+
"description": {"type": "string", "description": "截图描述"},
|
|
281
|
+
"compress": {"type": "boolean", "description": "是否压缩", "default": True},
|
|
282
|
+
"crop_x": {"type": "integer", "description": "裁剪中心 X"},
|
|
283
|
+
"crop_y": {"type": "integer", "description": "裁剪中心 Y"},
|
|
284
|
+
"crop_size": {"type": "integer", "description": "裁剪大小"}
|
|
237
285
|
},
|
|
238
286
|
"required": []
|
|
239
287
|
}
|
|
@@ -245,22 +293,54 @@ class MobileMCPServer:
|
|
|
245
293
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
246
294
|
))
|
|
247
295
|
|
|
296
|
+
if compact:
|
|
297
|
+
desc_som = "📸 SoM截图(token高)。元素有text时优先用list_elements+click_by_text。"
|
|
298
|
+
else:
|
|
299
|
+
desc_som = ("📸🏷️ Set-of-Mark 截图(⚠️ Token 消耗高 ~2000)\n\n"
|
|
300
|
+
"【智能标注】给每个可点击元素画框+编号\n\n"
|
|
301
|
+
"❌ 【不推荐常规使用】:\n"
|
|
302
|
+
"- 如果元素有 text,用 list_elements + click_by_text 更省 token\n"
|
|
303
|
+
"- 确认页面状态用 list_elements,不要截图确认!\n\n"
|
|
304
|
+
"✅ 仅在以下场景使用:\n"
|
|
305
|
+
"- 元素无 text/id,只能看图点击\n"
|
|
306
|
+
"- 需要视觉布局信息\n"
|
|
307
|
+
"- 首次探索未知页面\n\n"
|
|
308
|
+
"💡 点击后用 list_elements 确认,不要再截图!")
|
|
309
|
+
|
|
248
310
|
tools.append(Tool(
|
|
249
311
|
name="mobile_screenshot_with_som",
|
|
250
|
-
description="📸🏷️ Set-of-Mark
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
312
|
+
description="""📸🏷️ Set-of-Mark 截图(⚠️ 兜底方案,非首选)
|
|
313
|
+
|
|
314
|
+
⚠️ 【重要】仅在控件树定位失败时使用!
|
|
315
|
+
|
|
316
|
+
🎯 使用场景(兜底方案):
|
|
317
|
+
1. ⚠️ 控件树定位失败:
|
|
318
|
+
- mobile_list_elements() 返回空或找不到目标元素
|
|
319
|
+
- 元素不在控件树中(如游戏、Unity 应用)
|
|
320
|
+
2. ✅ 需要视觉确认:
|
|
321
|
+
- 首次进入新页面,需要了解整体布局
|
|
322
|
+
- 操作后需要视觉确认页面变化
|
|
323
|
+
- 需要给用户展示页面状态
|
|
324
|
+
|
|
325
|
+
⚡ 推荐流程(优先使用控件树):
|
|
326
|
+
1. 先调用 mobile_list_elements() 获取元素列表
|
|
327
|
+
2. 如果找到目标元素 → 使用 mobile_click_by_text() 或 mobile_click_by_id()
|
|
328
|
+
3. 如果找不到 → 才调用 mobile_screenshot_with_som()
|
|
329
|
+
4. 从截图分析找到元素编号 → 使用 mobile_click_by_som(编号)
|
|
330
|
+
|
|
331
|
+
❌ 错误用法:
|
|
332
|
+
- 每次都先截图,不先调用 list_elements
|
|
333
|
+
- 在控件树能找到元素时也使用截图
|
|
334
|
+
|
|
335
|
+
✅ 正确用法:
|
|
336
|
+
elements = mobile_list_elements() # 先尝试控件树
|
|
337
|
+
if not find_target(elements):
|
|
338
|
+
screenshot = mobile_screenshot_with_som() # 控件树失败才截图
|
|
339
|
+
mobile_click_by_som(index)
|
|
340
|
+
|
|
341
|
+
💡 弹窗检测:
|
|
342
|
+
- check_popup=True: 明确弹窗场景时使用(如调用 mobile_close_popup 前)
|
|
343
|
+
- check_popup=False: 普通截图,不检测弹窗(默认)""",
|
|
264
344
|
inputSchema={
|
|
265
345
|
"type": "object",
|
|
266
346
|
"properties": {
|
|
@@ -276,17 +356,11 @@ class MobileMCPServer:
|
|
|
276
356
|
|
|
277
357
|
tools.append(Tool(
|
|
278
358
|
name="mobile_click_by_som",
|
|
279
|
-
description="🎯 根据
|
|
280
|
-
"配合 mobile_screenshot_with_som 使用。\n"
|
|
281
|
-
"看图后直接说'点击 3 号',调用此函数即可。\n\n"
|
|
282
|
-
"⚠️ 【重要】点击后建议再次截图确认操作是否成功!",
|
|
359
|
+
description="🎯 根据SoM编号点击。配合screenshot_with_som使用。",
|
|
283
360
|
inputSchema={
|
|
284
361
|
"type": "object",
|
|
285
362
|
"properties": {
|
|
286
|
-
"index": {
|
|
287
|
-
"type": "integer",
|
|
288
|
-
"description": "元素编号(从 1 开始,对应截图中的标注数字)"
|
|
289
|
-
}
|
|
363
|
+
"index": {"type": "integer", "description": "元素编号(从1开始)"}
|
|
290
364
|
},
|
|
291
365
|
"required": ["index"]
|
|
292
366
|
}
|
|
@@ -294,97 +368,116 @@ class MobileMCPServer:
|
|
|
294
368
|
|
|
295
369
|
tools.append(Tool(
|
|
296
370
|
name="mobile_screenshot_with_grid",
|
|
297
|
-
description="
|
|
298
|
-
"在截图上绘制网格线和坐标刻度,帮助快速定位元素位置。\n"
|
|
299
|
-
"如果检测到弹窗,会用绿色圆圈标注可能的关闭按钮位置。\n\n"
|
|
300
|
-
"🎯 适用场景:\n"
|
|
301
|
-
"- 需要精确知道某个元素的坐标\n"
|
|
302
|
-
"- 关闭广告弹窗时定位 X 按钮\n"
|
|
303
|
-
"- 元素不在控件树中时的视觉定位\n\n"
|
|
304
|
-
"💡 返回信息:\n"
|
|
305
|
-
"- 带网格标注的截图\n"
|
|
306
|
-
"- 弹窗边界坐标(如果检测到)\n"
|
|
307
|
-
"- 可能的关闭按钮位置列表(带优先级)\n\n"
|
|
308
|
-
"🔴 【必须】点击后必须再次截图确认操作是否成功!",
|
|
371
|
+
description="📸 带网格坐标截图。用于精确定位元素坐标。",
|
|
309
372
|
inputSchema={
|
|
310
373
|
"type": "object",
|
|
311
374
|
"properties": {
|
|
312
|
-
"grid_size": {
|
|
313
|
-
|
|
314
|
-
"description": "网格间距(像素),默认 100。值越小网格越密,建议 50-200"
|
|
315
|
-
},
|
|
316
|
-
"show_popup_hints": {
|
|
317
|
-
"type": "boolean",
|
|
318
|
-
"description": "是否显示弹窗关闭按钮提示位置,默认 true"
|
|
319
|
-
}
|
|
375
|
+
"grid_size": {"type": "integer", "description": "网格间距(px),默认100"},
|
|
376
|
+
"show_popup_hints": {"type": "boolean", "description": "显示弹窗提示"}
|
|
320
377
|
},
|
|
321
378
|
"required": []
|
|
322
379
|
}
|
|
323
380
|
))
|
|
324
381
|
|
|
325
382
|
# ==================== 点击操作 ====================
|
|
383
|
+
if compact:
|
|
384
|
+
desc_click_text = "👆 文本点击(推荐)。verify可验证点击结果,无需截图确认。position可选top/bottom/left/right。"
|
|
385
|
+
else:
|
|
386
|
+
desc_click_text = ("👆 通过文本点击元素(⭐ 最推荐)\n\n"
|
|
387
|
+
"✅ 最稳定的定位方式,跨设备兼容\n"
|
|
388
|
+
"✅ 元素不存在会报错,不会误点击\n\n"
|
|
389
|
+
"🚀 Token 优化流程:\n"
|
|
390
|
+
"1. list_elements 确认元素存在\n"
|
|
391
|
+
"2. click_by_text 点击\n"
|
|
392
|
+
"3. list_elements 确认页面变化(❌不要截图确认!)\n\n"
|
|
393
|
+
"📍 position 参数:多个相同文案时指定位置\n"
|
|
394
|
+
" - top/bottom/left/right/center\n\n"
|
|
395
|
+
"🔍 verify 参数:点击后自动验证文本是否出现\n"
|
|
396
|
+
" - 设置后无需额外调用 list_elements 确认")
|
|
397
|
+
|
|
326
398
|
tools.append(Tool(
|
|
327
399
|
name="mobile_click_by_text",
|
|
328
|
-
description="👆
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
400
|
+
description="""👆 通过文本点击元素(⭐⭐ 第一优先级点击方式)
|
|
401
|
+
|
|
402
|
+
✅ 最稳定的定位方式,跨设备兼容
|
|
403
|
+
✅ 实时检测元素是否存在,元素不存在会报错
|
|
404
|
+
✅ 不会误点击到其他位置
|
|
405
|
+
|
|
406
|
+
⚡ 使用流程(必须):
|
|
407
|
+
1. 先调用 mobile_list_elements() 获取元素列表
|
|
408
|
+
2. 从元素列表中找到目标元素的 text
|
|
409
|
+
3. 调用 mobile_click_by_text("文本") 点击
|
|
410
|
+
|
|
411
|
+
💡 定位优先级:文本 > ID > 百分比 > 坐标
|
|
412
|
+
|
|
413
|
+
📍 当页面有多个相同文案时,可使用 position 参数指定位置:
|
|
414
|
+
- 垂直方向: "top"/"upper"/"上", "bottom"/"lower"/"下", "middle"/"center"/"中"
|
|
415
|
+
- 水平方向: "left"/"左", "right"/"右", "center"/"中"
|
|
416
|
+
例如:点击"底部"的"微剧"tab,使用 position="bottom"
|
|
417
|
+
|
|
418
|
+
❌ 错误用法:
|
|
419
|
+
- 不先调用 list_elements,直接猜测文本点击
|
|
420
|
+
- 在控件树能找到元素时使用截图+坐标点击
|
|
421
|
+
|
|
422
|
+
✅ 正确用法:
|
|
423
|
+
elements = mobile_list_elements() # 先获取元素列表
|
|
424
|
+
mobile_click_by_text("设置") # 从元素列表中找到后直接点击""",
|
|
338
425
|
inputSchema={
|
|
339
426
|
"type": "object",
|
|
340
427
|
"properties": {
|
|
341
|
-
"text": {"type": "string", "description": "
|
|
342
|
-
"position": {"type": "string", "description": "
|
|
428
|
+
"text": {"type": "string", "description": "元素文本"},
|
|
429
|
+
"position": {"type": "string", "description": "位置:top/bottom/left/right"},
|
|
430
|
+
"verify": {"type": "string", "description": "点击后验证的文本(可选)"}
|
|
343
431
|
},
|
|
344
432
|
"required": ["text"]
|
|
345
433
|
}
|
|
346
434
|
))
|
|
347
435
|
|
|
436
|
+
if compact:
|
|
437
|
+
desc_click_id = "👆 通过resource-id点击。index指定第几个(从0开始)。点击后用list_elements确认。"
|
|
438
|
+
else:
|
|
439
|
+
desc_click_id = ("👆 通过 resource-id 点击元素(推荐)\n\n"
|
|
440
|
+
"✅ 稳定的定位方式,元素不存在会报错\n"
|
|
441
|
+
"📋 使用前 list_elements 获取元素 ID\n"
|
|
442
|
+
"📋 点击后 list_elements 确认(❌不要截图确认!)\n"
|
|
443
|
+
"💡 多个相同 ID 时用 index 指定第几个(从 0 开始)")
|
|
444
|
+
|
|
348
445
|
tools.append(Tool(
|
|
349
446
|
name="mobile_click_by_id",
|
|
350
|
-
description=
|
|
351
|
-
"✅ 稳定的定位方式\n"
|
|
352
|
-
"✅ 实时检测元素是否存在,元素不存在会报错\n"
|
|
353
|
-
"📋 使用前先调用 mobile_list_elements 获取元素 ID\n"
|
|
354
|
-
"💡 当有多个相同 ID 的元素时,用 index 指定第几个(从 0 开始)\n"
|
|
355
|
-
"💡 定位优先级:文本 > ID > 百分比 > 坐标",
|
|
447
|
+
description=desc_click_id,
|
|
356
448
|
inputSchema={
|
|
357
449
|
"type": "object",
|
|
358
450
|
"properties": {
|
|
359
|
-
"resource_id": {"type": "string", "description": "
|
|
360
|
-
"index": {"type": "integer", "description": "
|
|
451
|
+
"resource_id": {"type": "string", "description": "resource-id"},
|
|
452
|
+
"index": {"type": "integer", "description": "第几个(从0开始)", "default": 0}
|
|
361
453
|
},
|
|
362
454
|
"required": ["resource_id"]
|
|
363
455
|
}
|
|
364
456
|
))
|
|
365
457
|
|
|
458
|
+
if compact:
|
|
459
|
+
desc_click_coords = "👆 坐标点击(兜底)。优先用click_by_text/id,点击后用list_elements确认。"
|
|
460
|
+
else:
|
|
461
|
+
desc_click_coords = ("👆 点击指定坐标(⚠️ 兜底方案)\n\n"
|
|
462
|
+
"❌ 优先使用 click_by_text 或 click_by_id!\n"
|
|
463
|
+
"仅在 list_elements 无法获取元素时使用。\n\n"
|
|
464
|
+
"📐 坐标转换:截图返回的参数直接传入即可\n"
|
|
465
|
+
"📋 点击后用 list_elements 确认(❌不要截图确认!)")
|
|
466
|
+
|
|
366
467
|
tools.append(Tool(
|
|
367
468
|
name="mobile_click_at_coords",
|
|
368
|
-
description=
|
|
369
|
-
"⚠️ 【重要】优先使用 mobile_click_by_text 或 mobile_click_by_id!\n"
|
|
370
|
-
"仅在 mobile_list_elements 无法获取元素时使用此工具。\n\n"
|
|
371
|
-
"⚠️ 【时序限制】截图分析期间页面可能变化:\n"
|
|
372
|
-
"- 坐标是基于截图时刻的,点击时页面可能已不同\n"
|
|
373
|
-
"- 如果误点击,调用 mobile_press_key(back) 返回\n"
|
|
374
|
-
"- 对于定时弹窗(如广告),建议等待其自动消失\n\n"
|
|
375
|
-
"📐 坐标转换:截图返回的 image_width/height 等参数直接传入即可\n\n"
|
|
376
|
-
"🔴 【必须】点击后必须再次截图确认操作是否成功!",
|
|
469
|
+
description=desc_click_coords,
|
|
377
470
|
inputSchema={
|
|
378
471
|
"type": "object",
|
|
379
472
|
"properties": {
|
|
380
|
-
"x": {"type": "number", "description": "X
|
|
381
|
-
"y": {"type": "number", "description": "Y
|
|
382
|
-
"image_width": {"type": "number", "description": "
|
|
383
|
-
"image_height": {"type": "number", "description": "
|
|
384
|
-
"original_img_width": {"type": "number", "description": "
|
|
385
|
-
"original_img_height": {"type": "number", "description": "
|
|
386
|
-
"crop_offset_x": {"type": "number", "description": "
|
|
387
|
-
"crop_offset_y": {"type": "number", "description": "
|
|
473
|
+
"x": {"type": "number", "description": "X 坐标"},
|
|
474
|
+
"y": {"type": "number", "description": "Y 坐标"},
|
|
475
|
+
"image_width": {"type": "number", "description": "图片宽度"},
|
|
476
|
+
"image_height": {"type": "number", "description": "图片高度"},
|
|
477
|
+
"original_img_width": {"type": "number", "description": "原图宽"},
|
|
478
|
+
"original_img_height": {"type": "number", "description": "原图高"},
|
|
479
|
+
"crop_offset_x": {"type": "number", "description": "裁剪X偏移"},
|
|
480
|
+
"crop_offset_y": {"type": "number", "description": "裁剪Y偏移"}
|
|
388
481
|
},
|
|
389
482
|
"required": ["x", "y"]
|
|
390
483
|
}
|
|
@@ -392,15 +485,7 @@ class MobileMCPServer:
|
|
|
392
485
|
|
|
393
486
|
tools.append(Tool(
|
|
394
487
|
name="mobile_click_by_percent",
|
|
395
|
-
description="👆
|
|
396
|
-
"🎯 原理:屏幕左上角是 (0%, 0%),右下角是 (100%, 100%)\n"
|
|
397
|
-
"📐 示例:\n"
|
|
398
|
-
" - (50, 50) = 屏幕正中央\n"
|
|
399
|
-
" - (10, 5) = 左上角附近\n"
|
|
400
|
-
" - (85, 90) = 右下角附近\n\n"
|
|
401
|
-
"✅ 优势:同样的百分比在不同分辨率设备上都能点到相同相对位置\n"
|
|
402
|
-
"💡 录制一次,多设备回放\n\n"
|
|
403
|
-
"🔴 【必须】点击后必须再次截图确认操作是否成功!",
|
|
488
|
+
description="👆 百分比点击。(50,50)=屏幕中心。跨设备兼容。",
|
|
404
489
|
inputSchema={
|
|
405
490
|
"type": "object",
|
|
406
491
|
"properties": {
|
|
@@ -414,15 +499,12 @@ class MobileMCPServer:
|
|
|
414
499
|
# ==================== 长按操作 ====================
|
|
415
500
|
tools.append(Tool(
|
|
416
501
|
name="mobile_long_press_by_id",
|
|
417
|
-
description="👆 通过
|
|
418
|
-
"✅ 最稳定的长按定位方式,跨设备完美兼容\n"
|
|
419
|
-
"📋 使用前请先调用 mobile_list_elements 获取元素 ID\n"
|
|
420
|
-
"💡 生成的脚本使用 d(resourceId='...').long_click() 定位,最稳定",
|
|
502
|
+
description="👆 通过resource-id长按。",
|
|
421
503
|
inputSchema={
|
|
422
504
|
"type": "object",
|
|
423
505
|
"properties": {
|
|
424
|
-
"resource_id": {"type": "string", "description": "
|
|
425
|
-
"duration": {"type": "number", "description": "
|
|
506
|
+
"resource_id": {"type": "string", "description": "resource-id"},
|
|
507
|
+
"duration": {"type": "number", "description": "长按秒数,默认1.0"}
|
|
426
508
|
},
|
|
427
509
|
"required": ["resource_id"]
|
|
428
510
|
}
|
|
@@ -430,15 +512,12 @@ class MobileMCPServer:
|
|
|
430
512
|
|
|
431
513
|
tools.append(Tool(
|
|
432
514
|
name="mobile_long_press_by_text",
|
|
433
|
-
description="👆
|
|
434
|
-
"✅ 优势:跨设备兼容,不受屏幕分辨率影响\n"
|
|
435
|
-
"📋 使用前请先调用 mobile_list_elements 确认元素有文本\n"
|
|
436
|
-
"💡 生成的脚本使用 d(text='...').long_click() 定位,稳定可靠",
|
|
515
|
+
description="👆 通过文本长按。",
|
|
437
516
|
inputSchema={
|
|
438
517
|
"type": "object",
|
|
439
518
|
"properties": {
|
|
440
|
-
"text": {"type": "string", "description": "
|
|
441
|
-
"duration": {"type": "number", "description": "
|
|
519
|
+
"text": {"type": "string", "description": "文本内容"},
|
|
520
|
+
"duration": {"type": "number", "description": "长按秒数,默认1.0"}
|
|
442
521
|
},
|
|
443
522
|
"required": ["text"]
|
|
444
523
|
}
|
|
@@ -446,20 +525,13 @@ class MobileMCPServer:
|
|
|
446
525
|
|
|
447
526
|
tools.append(Tool(
|
|
448
527
|
name="mobile_long_press_by_percent",
|
|
449
|
-
description="👆
|
|
450
|
-
"🎯 原理:屏幕左上角是 (0%, 0%),右下角是 (100%, 100%)\n"
|
|
451
|
-
"📐 示例:\n"
|
|
452
|
-
" - (50, 50) = 屏幕正中央\n"
|
|
453
|
-
" - (10, 5) = 左上角附近\n"
|
|
454
|
-
" - (85, 90) = 右下角附近\n\n"
|
|
455
|
-
"✅ 优势:同样的百分比在不同分辨率设备上都能长按到相同相对位置\n"
|
|
456
|
-
"💡 录制一次,多设备回放",
|
|
528
|
+
description="👆 百分比长按。(50,50)=屏幕中心。",
|
|
457
529
|
inputSchema={
|
|
458
530
|
"type": "object",
|
|
459
531
|
"properties": {
|
|
460
|
-
"x_percent": {"type": "number", "description": "X
|
|
461
|
-
"y_percent": {"type": "number", "description": "Y
|
|
462
|
-
"duration": {"type": "number", "description": "
|
|
532
|
+
"x_percent": {"type": "number", "description": "X百分比(0-100)"},
|
|
533
|
+
"y_percent": {"type": "number", "description": "Y百分比(0-100)"},
|
|
534
|
+
"duration": {"type": "number", "description": "长按秒数,默认1.0"}
|
|
463
535
|
},
|
|
464
536
|
"required": ["x_percent", "y_percent"]
|
|
465
537
|
}
|
|
@@ -467,28 +539,19 @@ class MobileMCPServer:
|
|
|
467
539
|
|
|
468
540
|
tools.append(Tool(
|
|
469
541
|
name="mobile_long_press_at_coords",
|
|
470
|
-
description="👆
|
|
471
|
-
"🎯 仅在以下场景使用:\n"
|
|
472
|
-
"- 游戏(Unity/Cocos)无法获取元素\n"
|
|
473
|
-
"- mobile_list_elements 返回空\n"
|
|
474
|
-
"- 元素没有 id 和 text\n\n"
|
|
475
|
-
"⚠️ 【坐标转换】截图返回的参数直接传入:\n"
|
|
476
|
-
" - image_width/image_height: 压缩后尺寸(AI 看到的)\n"
|
|
477
|
-
" - original_img_width/original_img_height: 原图尺寸(用于转换)\n"
|
|
478
|
-
" - crop_offset_x/crop_offset_y: 局部截图偏移\n\n"
|
|
479
|
-
"✅ 自动记录百分比坐标,生成脚本时转换为跨分辨率兼容的百分比定位",
|
|
542
|
+
description="👆 坐标长按(兜底)。优先用text/id。",
|
|
480
543
|
inputSchema={
|
|
481
544
|
"type": "object",
|
|
482
545
|
"properties": {
|
|
483
|
-
"x": {"type": "number", "description": "X
|
|
484
|
-
"y": {"type": "number", "description": "Y
|
|
485
|
-
"duration": {"type": "number", "description": "
|
|
486
|
-
"image_width": {"type": "number", "description": "
|
|
487
|
-
"image_height": {"type": "number", "description": "
|
|
488
|
-
"original_img_width": {"type": "number", "description": "
|
|
489
|
-
"original_img_height": {"type": "number", "description": "
|
|
490
|
-
"crop_offset_x": {"type": "number", "description": "
|
|
491
|
-
"crop_offset_y": {"type": "number", "description": "
|
|
546
|
+
"x": {"type": "number", "description": "X坐标"},
|
|
547
|
+
"y": {"type": "number", "description": "Y坐标"},
|
|
548
|
+
"duration": {"type": "number", "description": "长按秒数"},
|
|
549
|
+
"image_width": {"type": "number", "description": "图片宽"},
|
|
550
|
+
"image_height": {"type": "number", "description": "图片高"},
|
|
551
|
+
"original_img_width": {"type": "number", "description": "原图宽"},
|
|
552
|
+
"original_img_height": {"type": "number", "description": "原图高"},
|
|
553
|
+
"crop_offset_x": {"type": "number", "description": "裁剪X偏移"},
|
|
554
|
+
"crop_offset_y": {"type": "number", "description": "裁剪Y偏移"}
|
|
492
555
|
},
|
|
493
556
|
"required": ["x", "y"]
|
|
494
557
|
}
|
|
@@ -497,12 +560,12 @@ class MobileMCPServer:
|
|
|
497
560
|
# ==================== 输入操作 ====================
|
|
498
561
|
tools.append(Tool(
|
|
499
562
|
name="mobile_input_text_by_id",
|
|
500
|
-
description="⌨️
|
|
563
|
+
description="⌨️ 通过ID输入文本。",
|
|
501
564
|
inputSchema={
|
|
502
565
|
"type": "object",
|
|
503
566
|
"properties": {
|
|
504
|
-
"resource_id": {"type": "string", "description": "
|
|
505
|
-
"text": {"type": "string", "description": "
|
|
567
|
+
"resource_id": {"type": "string", "description": "resource-id"},
|
|
568
|
+
"text": {"type": "string", "description": "输入文本"}
|
|
506
569
|
},
|
|
507
570
|
"required": ["resource_id", "text"]
|
|
508
571
|
}
|
|
@@ -510,13 +573,13 @@ class MobileMCPServer:
|
|
|
510
573
|
|
|
511
574
|
tools.append(Tool(
|
|
512
575
|
name="mobile_input_at_coords",
|
|
513
|
-
description="⌨️
|
|
576
|
+
description="⌨️ 坐标输入文本。",
|
|
514
577
|
inputSchema={
|
|
515
578
|
"type": "object",
|
|
516
579
|
"properties": {
|
|
517
|
-
"x": {"type": "number", "description": "
|
|
518
|
-
"y": {"type": "number", "description": "
|
|
519
|
-
"text": {"type": "string", "description": "
|
|
580
|
+
"x": {"type": "number", "description": "X坐标"},
|
|
581
|
+
"y": {"type": "number", "description": "Y坐标"},
|
|
582
|
+
"text": {"type": "string", "description": "输入文本"}
|
|
520
583
|
},
|
|
521
584
|
"required": ["x", "y", "text"]
|
|
522
585
|
}
|
|
@@ -525,105 +588,25 @@ class MobileMCPServer:
|
|
|
525
588
|
# ==================== 导航操作 ====================
|
|
526
589
|
tools.append(Tool(
|
|
527
590
|
name="mobile_swipe",
|
|
528
|
-
description="👆
|
|
529
|
-
"🎯 适用场景:\n"
|
|
530
|
-
"- 滑动页面(列表、页面切换)\n"
|
|
531
|
-
"- 拖动进度条/滑块(SeekBar、ProgressBar)\n"
|
|
532
|
-
"- 滑动选择器(Picker、Slider)\n\n"
|
|
533
|
-
"💡 左右滑动时,可指定高度坐标或百分比:\n"
|
|
534
|
-
"- y: 指定高度坐标(像素)\n"
|
|
535
|
-
"- y_percent: 指定高度百分比 (0-100)\n"
|
|
536
|
-
"- 两者都未指定时,使用屏幕中心高度\n"
|
|
537
|
-
"- 📌 拖动进度条时,使用进度条的 Y 位置(百分比或像素)\n\n"
|
|
538
|
-
"💡 横向滑动(left/right)时,可指定滑动距离:\n"
|
|
539
|
-
"- distance: 滑动距离(像素)\n"
|
|
540
|
-
"- distance_percent: 滑动距离百分比 (0-100)\n"
|
|
541
|
-
"- 两者都未指定时,使用默认距离(屏幕宽度的 60%)\n"
|
|
542
|
-
"- 📌 拖动进度条时,distance_percent 控制拖动幅度\n\n"
|
|
543
|
-
"💡 拖动进度条示例:\n"
|
|
544
|
-
"- 倒退:direction='left', y_percent=91(进度条位置), distance_percent=30\n"
|
|
545
|
-
"- 前进:direction='right', y_percent=91, distance_percent=30\n\n"
|
|
546
|
-
"⚠️ **推荐使用 mobile_drag_progress_bar 拖动进度条**(自动检测进度条位置,无需手动指定)",
|
|
591
|
+
description="👆 滑动。方向:up/down/left/right。",
|
|
547
592
|
inputSchema={
|
|
548
593
|
"type": "object",
|
|
549
594
|
"properties": {
|
|
550
|
-
"direction": {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
"description": "滑动方向"
|
|
554
|
-
},
|
|
555
|
-
"y": {
|
|
556
|
-
"type": "integer",
|
|
557
|
-
"description": "左右滑动时指定的高度坐标(像素,0-屏幕高度)"
|
|
558
|
-
},
|
|
559
|
-
"y_percent": {
|
|
560
|
-
"type": "number",
|
|
561
|
-
"description": "左右滑动时指定的高度百分比 (0-100)"
|
|
562
|
-
},
|
|
563
|
-
"distance": {
|
|
564
|
-
"type": "integer",
|
|
565
|
-
"description": "横向滑动时指定的滑动距离(像素),仅用于 left/right"
|
|
566
|
-
},
|
|
567
|
-
"distance_percent": {
|
|
568
|
-
"type": "number",
|
|
569
|
-
"description": "横向滑动时指定的滑动距离百分比 (0-100),仅用于 left/right"
|
|
570
|
-
}
|
|
595
|
+
"direction": {"type": "string", "enum": ["up", "down", "left", "right"], "description": "方向"},
|
|
596
|
+
"y": {"type": "integer", "description": "左右滑动高度(px)"},
|
|
597
|
+
"y_percent": {"type": "number", "description": "左右滑动高度(%)"}
|
|
571
598
|
},
|
|
572
599
|
"required": ["direction"]
|
|
573
600
|
}
|
|
574
601
|
))
|
|
575
602
|
|
|
576
|
-
tools.append(Tool(
|
|
577
|
-
name="mobile_drag_progress_bar",
|
|
578
|
-
description="🎯 智能拖动进度条(⭐⭐ 推荐用于拖动视频/音频进度条)\n\n"
|
|
579
|
-
"✅ **自动检测进度条是否可见**:\n"
|
|
580
|
-
"- 如果进度条已显示,直接拖动(无需先点击播放区域)\n"
|
|
581
|
-
"- 如果进度条未显示,自动点击播放区域显示控制栏,再拖动\n\n"
|
|
582
|
-
"🎯 优势:\n"
|
|
583
|
-
"- 自动检测进度条位置,无需手动指定 y_percent\n"
|
|
584
|
-
"- 智能判断是否需要显示控制栏\n"
|
|
585
|
-
"- 使用 swipe 拖动,更稳定可靠\n\n"
|
|
586
|
-
"💡 参数说明:\n"
|
|
587
|
-
"- direction: 'left'(倒退)或 'right'(前进),默认 'right'\n"
|
|
588
|
-
"- distance_percent: 拖动距离百分比 (0-100),默认 30%\n"
|
|
589
|
-
"- y_percent: 进度条位置(可选,未指定则自动检测)\n"
|
|
590
|
-
"- y: 进度条位置坐标(可选,未指定则自动检测)\n\n"
|
|
591
|
-
"📋 使用示例:\n"
|
|
592
|
-
"- 前进30%:mobile_drag_progress_bar(direction='right', distance_percent=30)\n"
|
|
593
|
-
"- 倒退30%:mobile_drag_progress_bar(direction='left', distance_percent=30)\n"
|
|
594
|
-
"- 前进到指定位置:先点击进度条位置,或使用 mobile_swipe",
|
|
595
|
-
inputSchema={
|
|
596
|
-
"type": "object",
|
|
597
|
-
"properties": {
|
|
598
|
-
"direction": {
|
|
599
|
-
"type": "string",
|
|
600
|
-
"enum": ["left", "right"],
|
|
601
|
-
"description": "拖动方向:'left'(倒退)或 'right'(前进),默认 'right'"
|
|
602
|
-
},
|
|
603
|
-
"distance_percent": {
|
|
604
|
-
"type": "number",
|
|
605
|
-
"description": "拖动距离百分比 (0-100),默认 30%"
|
|
606
|
-
},
|
|
607
|
-
"y_percent": {
|
|
608
|
-
"type": "number",
|
|
609
|
-
"description": "进度条的垂直位置百分比 (0-100),可选,未指定则自动检测"
|
|
610
|
-
},
|
|
611
|
-
"y": {
|
|
612
|
-
"type": "integer",
|
|
613
|
-
"description": "进度条的垂直位置坐标(像素),可选,未指定则自动检测"
|
|
614
|
-
}
|
|
615
|
-
},
|
|
616
|
-
"required": []
|
|
617
|
-
}
|
|
618
|
-
))
|
|
619
|
-
|
|
620
603
|
tools.append(Tool(
|
|
621
604
|
name="mobile_press_key",
|
|
622
|
-
description="⌨️
|
|
605
|
+
description="⌨️ 按键:home/back/enter/search。",
|
|
623
606
|
inputSchema={
|
|
624
607
|
"type": "object",
|
|
625
608
|
"properties": {
|
|
626
|
-
"key": {"type": "string", "description": "
|
|
609
|
+
"key": {"type": "string", "description": "按键名"}
|
|
627
610
|
},
|
|
628
611
|
"required": ["key"]
|
|
629
612
|
}
|
|
@@ -631,11 +614,11 @@ class MobileMCPServer:
|
|
|
631
614
|
|
|
632
615
|
tools.append(Tool(
|
|
633
616
|
name="mobile_wait",
|
|
634
|
-
description="⏰
|
|
617
|
+
description="⏰ 等待指定秒数。",
|
|
635
618
|
inputSchema={
|
|
636
619
|
"type": "object",
|
|
637
620
|
"properties": {
|
|
638
|
-
"seconds": {"type": "number", "description": "
|
|
621
|
+
"seconds": {"type": "number", "description": "等待秒数"}
|
|
639
622
|
},
|
|
640
623
|
"required": ["seconds"]
|
|
641
624
|
}
|
|
@@ -644,16 +627,11 @@ class MobileMCPServer:
|
|
|
644
627
|
# ==================== 应用管理 ====================
|
|
645
628
|
tools.append(Tool(
|
|
646
629
|
name="mobile_launch_app",
|
|
647
|
-
description="
|
|
648
|
-
|
|
649
|
-
🎯 弹窗检测场景:启动应用后会自动检测弹窗(启动应用场景)
|
|
650
|
-
|
|
651
|
-
启动后建议等待 2-3 秒让页面加载。
|
|
652
|
-
如果检测到弹窗,返回结果中会包含 popup_detected=true,建议调用 mobile_close_popup() 关闭弹窗。""",
|
|
630
|
+
description="🚀 启动应用。",
|
|
653
631
|
inputSchema={
|
|
654
632
|
"type": "object",
|
|
655
633
|
"properties": {
|
|
656
|
-
"package_name": {"type": "string", "description": "
|
|
634
|
+
"package_name": {"type": "string", "description": "包名"}
|
|
657
635
|
},
|
|
658
636
|
"required": ["package_name"]
|
|
659
637
|
}
|
|
@@ -665,7 +643,7 @@ class MobileMCPServer:
|
|
|
665
643
|
inputSchema={
|
|
666
644
|
"type": "object",
|
|
667
645
|
"properties": {
|
|
668
|
-
"package_name": {"type": "string", "description": "
|
|
646
|
+
"package_name": {"type": "string", "description": "包名"}
|
|
669
647
|
},
|
|
670
648
|
"required": ["package_name"]
|
|
671
649
|
}
|
|
@@ -673,11 +651,11 @@ class MobileMCPServer:
|
|
|
673
651
|
|
|
674
652
|
tools.append(Tool(
|
|
675
653
|
name="mobile_list_apps",
|
|
676
|
-
description="📦
|
|
654
|
+
description="📦 列出应用。",
|
|
677
655
|
inputSchema={
|
|
678
656
|
"type": "object",
|
|
679
657
|
"properties": {
|
|
680
|
-
"filter": {"type": "string", "description": "
|
|
658
|
+
"filter": {"type": "string", "description": "过滤词"}
|
|
681
659
|
},
|
|
682
660
|
"required": []
|
|
683
661
|
}
|
|
@@ -686,33 +664,31 @@ class MobileMCPServer:
|
|
|
686
664
|
# ==================== 设备管理 ====================
|
|
687
665
|
tools.append(Tool(
|
|
688
666
|
name="mobile_list_devices",
|
|
689
|
-
description="📱
|
|
667
|
+
description="📱 列出设备。",
|
|
690
668
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
691
669
|
))
|
|
692
670
|
|
|
693
671
|
tools.append(Tool(
|
|
694
672
|
name="mobile_check_connection",
|
|
695
|
-
description="🔌
|
|
673
|
+
description="🔌 检查连接。",
|
|
696
674
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
697
675
|
))
|
|
698
676
|
|
|
699
677
|
# ==================== 辅助工具 ====================
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
678
|
+
if compact:
|
|
679
|
+
desc_find_close = "🔍 查找关闭按钮(只找不点)。返回坐标和推荐的点击命令。"
|
|
680
|
+
else:
|
|
681
|
+
desc_find_close = """🔍 智能查找关闭按钮(只找不点,返回位置)
|
|
703
682
|
|
|
704
683
|
⚡ 【推荐首选】遇到弹窗时优先调用此工具!无需先截图。
|
|
705
684
|
|
|
706
685
|
从元素树中找最可能的关闭按钮,返回坐标和推荐的点击命令。
|
|
707
686
|
|
|
708
687
|
🎯 识别策略(优先级):
|
|
709
|
-
1.
|
|
710
|
-
2.
|
|
711
|
-
3.
|
|
712
|
-
4.
|
|
713
|
-
5. 小尺寸 clickable 元素(右上角优先,得分70+)
|
|
714
|
-
|
|
715
|
-
⭐ 优先点击确认性按钮(同意、确认等),而不是取消/拒绝按钮
|
|
688
|
+
1. 文本匹配:×、X、关闭、取消、跳过 等(得分100)
|
|
689
|
+
2. resource-id 匹配:包含 close/dismiss/skip(得分95)
|
|
690
|
+
3. content-desc 匹配:包含 close/关闭(得分90)
|
|
691
|
+
4. 小尺寸 clickable 元素(右上角优先,得分70+)
|
|
716
692
|
|
|
717
693
|
✅ 返回内容:
|
|
718
694
|
- 坐标 (x, y) 和百分比 (x%, y%)
|
|
@@ -722,100 +698,68 @@ class MobileMCPServer:
|
|
|
722
698
|
💡 使用流程:
|
|
723
699
|
1. 直接调用此工具(无需先截图/列元素)
|
|
724
700
|
2. 根据返回的 click_command 执行点击
|
|
725
|
-
3. 如果返回 success=false,才需要截图分析"""
|
|
701
|
+
3. 如果返回 success=false,才需要截图分析"""
|
|
702
|
+
|
|
703
|
+
tools.append(Tool(
|
|
704
|
+
name="mobile_find_close_button",
|
|
705
|
+
description=desc_find_close,
|
|
726
706
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
727
707
|
))
|
|
728
708
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
709
|
+
if compact:
|
|
710
|
+
desc_close_popup = "🚫 智能检测并关闭弹窗。自动查找×/关闭/跳过按钮。"
|
|
711
|
+
else:
|
|
712
|
+
desc_close_popup = """🚫 智能检测并关闭弹窗
|
|
732
713
|
|
|
733
|
-
|
|
734
|
-
-
|
|
735
|
-
-
|
|
736
|
-
- 明确弹窗场景:调用此工具时(明确弹窗场景)
|
|
714
|
+
⚡ 【自动检测】会先检测是否存在弹窗:
|
|
715
|
+
- 如果没有弹窗 → 直接返回"无弹窗",不执行任何操作
|
|
716
|
+
- 如果有弹窗 → 自动查找并点击关闭按钮
|
|
737
717
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
718
|
+
✅ 适用场景:
|
|
719
|
+
- 启动应用后检测并关闭可能出现的弹窗
|
|
720
|
+
- 页面跳转后检测并关闭弹窗
|
|
721
|
+
- 无需先截图确认弹窗是否存在
|
|
742
722
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
723
|
+
🎯 检测策略:
|
|
724
|
+
- 查找控件树中的关闭按钮(×、关闭、跳过等)
|
|
725
|
+
- 检测弹窗区域(Dialog/Popup/Alert 等)
|
|
726
|
+
- 查找小尺寸的可点击元素(优先角落位置)
|
|
747
727
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
inputSchema={
|
|
754
|
-
"type": "object",
|
|
755
|
-
"properties": {
|
|
756
|
-
"auto_learn": {
|
|
757
|
-
"type": "boolean",
|
|
758
|
-
"description": "是否自动学习新模板(模板匹配成功时),默认 false"
|
|
759
|
-
},
|
|
760
|
-
"confidence_threshold": {
|
|
761
|
-
"type": "number",
|
|
762
|
-
"description": "弹窗检测置信度阈值(0-1),默认 0.6。值越高越严格,减少误检但可能漏检"
|
|
763
|
-
}
|
|
764
|
-
},
|
|
765
|
-
"required": []
|
|
766
|
-
}
|
|
728
|
+
🔴 【必须】如果返回已点击,需再次截图确认弹窗是否真的关闭了!"""
|
|
729
|
+
|
|
730
|
+
tools.append(Tool(
|
|
731
|
+
name="mobile_close_popup",
|
|
732
|
+
description=desc_close_popup,
|
|
733
|
+
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
767
734
|
))
|
|
768
735
|
|
|
769
736
|
tools.append(Tool(
|
|
770
737
|
name="mobile_assert_text",
|
|
771
|
-
description="✅
|
|
738
|
+
description="✅ 检查页面是否包含文本。",
|
|
772
739
|
inputSchema={
|
|
773
740
|
"type": "object",
|
|
774
741
|
"properties": {
|
|
775
|
-
"text": {"type": "string", "description": "
|
|
742
|
+
"text": {"type": "string", "description": "文本"}
|
|
776
743
|
},
|
|
777
744
|
"required": ["text"]
|
|
778
745
|
}
|
|
779
746
|
))
|
|
780
747
|
|
|
781
|
-
# ==================== Toast
|
|
748
|
+
# ==================== Toast 检测(仅 Android)====================
|
|
782
749
|
tools.append(Tool(
|
|
783
750
|
name="mobile_start_toast_watch",
|
|
784
|
-
description="
|
|
785
|
-
|
|
786
|
-
⚠️ 【重要】必须在执行操作之前调用!
|
|
787
|
-
|
|
788
|
-
📋 正确流程(三步走):
|
|
789
|
-
1️⃣ 调用 mobile_start_toast_watch() 开始监听
|
|
790
|
-
2️⃣ 执行操作(如点击提交按钮)
|
|
791
|
-
3️⃣ 调用 mobile_get_toast() 或 mobile_assert_toast() 获取结果
|
|
792
|
-
|
|
793
|
-
❌ 错误用法:先点击按钮,再调用此工具(Toast 可能已消失)""",
|
|
794
|
-
inputSchema={
|
|
795
|
-
"type": "object",
|
|
796
|
-
"properties": {},
|
|
797
|
-
"required": []
|
|
798
|
-
}
|
|
751
|
+
description="🔔 开始监听Toast。必须在操作前调用。",
|
|
752
|
+
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
799
753
|
))
|
|
800
754
|
|
|
801
755
|
tools.append(Tool(
|
|
802
756
|
name="mobile_get_toast",
|
|
803
|
-
description="
|
|
804
|
-
|
|
805
|
-
Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果。
|
|
806
|
-
⚠️ Toast 不在控件树中,无法通过 mobile_list_elements 获取。
|
|
807
|
-
|
|
808
|
-
📋 推荐用法(三步走):
|
|
809
|
-
1️⃣ mobile_start_toast_watch() - 开始监听
|
|
810
|
-
2️⃣ 执行操作(点击按钮等)
|
|
811
|
-
3️⃣ mobile_get_toast() - 获取 Toast
|
|
812
|
-
|
|
813
|
-
⏱️ timeout 设置等待时间,默认 5 秒。""",
|
|
757
|
+
description="🍞 获取Toast消息。配合start_toast_watch使用。",
|
|
814
758
|
inputSchema={
|
|
815
759
|
"type": "object",
|
|
816
760
|
"properties": {
|
|
817
|
-
"timeout": {"type": "number", "description": "
|
|
818
|
-
"reset_first": {"type": "boolean", "description": "
|
|
761
|
+
"timeout": {"type": "number", "description": "超时秒数,默认5"},
|
|
762
|
+
"reset_first": {"type": "boolean", "description": "清除旧缓存"}
|
|
819
763
|
},
|
|
820
764
|
"required": []
|
|
821
765
|
}
|
|
@@ -823,22 +767,13 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
823
767
|
|
|
824
768
|
tools.append(Tool(
|
|
825
769
|
name="mobile_assert_toast",
|
|
826
|
-
description="
|
|
827
|
-
|
|
828
|
-
等待 Toast 出现并验证内容是否符合预期。
|
|
829
|
-
|
|
830
|
-
📋 推荐用法(三步走):
|
|
831
|
-
1️⃣ mobile_start_toast_watch() - 开始监听
|
|
832
|
-
2️⃣ 执行操作(点击按钮等)
|
|
833
|
-
3️⃣ mobile_assert_toast(expected_text="成功") - 断言
|
|
834
|
-
|
|
835
|
-
💡 支持包含匹配(默认)和精确匹配。""",
|
|
770
|
+
description="✅ 断言Toast内容。",
|
|
836
771
|
inputSchema={
|
|
837
772
|
"type": "object",
|
|
838
773
|
"properties": {
|
|
839
|
-
"expected_text": {"type": "string", "description": "
|
|
840
|
-
"timeout": {"type": "number", "description": "
|
|
841
|
-
"contains": {"type": "boolean", "description": "
|
|
774
|
+
"expected_text": {"type": "string", "description": "期望文本"},
|
|
775
|
+
"timeout": {"type": "number", "description": "超时秒数"},
|
|
776
|
+
"contains": {"type": "boolean", "description": "包含匹配(默认true)"}
|
|
842
777
|
},
|
|
843
778
|
"required": ["expected_text"]
|
|
844
779
|
}
|
|
@@ -847,11 +782,11 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
847
782
|
# ==================== pytest 脚本生成 ====================
|
|
848
783
|
tools.append(Tool(
|
|
849
784
|
name="mobile_get_operation_history",
|
|
850
|
-
description="📜
|
|
785
|
+
description="📜 获取操作历史。",
|
|
851
786
|
inputSchema={
|
|
852
787
|
"type": "object",
|
|
853
788
|
"properties": {
|
|
854
|
-
"limit": {"type": "number", "description": "
|
|
789
|
+
"limit": {"type": "number", "description": "条数"}
|
|
855
790
|
},
|
|
856
791
|
"required": []
|
|
857
792
|
}
|
|
@@ -859,50 +794,53 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
859
794
|
|
|
860
795
|
tools.append(Tool(
|
|
861
796
|
name="mobile_clear_operation_history",
|
|
862
|
-
description="🗑️
|
|
863
|
-
"⚠️ 开始新的测试录制前必须调用!\n"
|
|
864
|
-
"📋 录制流程:清空历史 → 执行操作(优先用文本/ID定位)→ 生成脚本",
|
|
797
|
+
description="🗑️ 清空操作历史。录制前调用。",
|
|
865
798
|
inputSchema={"type": "object", "properties": {}, "required": []}
|
|
866
799
|
))
|
|
867
800
|
|
|
868
801
|
tools.append(Tool(
|
|
869
802
|
name="mobile_generate_test_script",
|
|
870
|
-
description="📝 生成
|
|
871
|
-
"⚠️ 【重要】录制操作时请优先使用稳定定位:\n"
|
|
872
|
-
"1️⃣ 先调用 mobile_list_elements 获取元素列表\n"
|
|
873
|
-
"2️⃣ 优先用 mobile_click_by_text(最稳定,跨设备兼容)\n"
|
|
874
|
-
"3️⃣ 其次用 mobile_click_by_id(稳定)\n"
|
|
875
|
-
"4️⃣ 最后才用坐标点击(会自动转百分比,跨分辨率兼容)\n\n"
|
|
876
|
-
"使用流程:\n"
|
|
877
|
-
"1. 清空历史 mobile_clear_operation_history\n"
|
|
878
|
-
"2. 执行操作(优先用文本/ID定位)\n"
|
|
879
|
-
"3. 调用此工具生成脚本\n"
|
|
880
|
-
"4. 脚本保存到 tests/ 目录\n\n"
|
|
881
|
-
"💡 定位优先级:文本 > ID > 百分比 > 坐标",
|
|
803
|
+
description="📝 生成pytest脚本。基于操作历史生成。",
|
|
882
804
|
inputSchema={
|
|
883
805
|
"type": "object",
|
|
884
806
|
"properties": {
|
|
885
|
-
"test_name": {"type": "string", "description": "
|
|
886
|
-
"package_name": {"type": "string", "description": "
|
|
887
|
-
"filename": {"type": "string", "description": "
|
|
807
|
+
"test_name": {"type": "string", "description": "用例名"},
|
|
808
|
+
"package_name": {"type": "string", "description": "包名"},
|
|
809
|
+
"filename": {"type": "string", "description": "文件名(不含.py)"}
|
|
888
810
|
},
|
|
889
811
|
"required": ["test_name", "package_name", "filename"]
|
|
890
812
|
}
|
|
891
813
|
))
|
|
892
814
|
|
|
893
815
|
# ==================== 广告弹窗关闭工具 ====================
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
816
|
+
if compact:
|
|
817
|
+
desc_close_ad = "🚫 智能关闭广告弹窗。优先级:控件树→截图AI→模板匹配。"
|
|
818
|
+
else:
|
|
819
|
+
desc_close_ad = """🚫 【推荐】智能检测并关闭广告弹窗
|
|
897
820
|
|
|
898
|
-
⚡
|
|
821
|
+
⚡ 【自动检测】会先检测是否存在弹窗:
|
|
822
|
+
- 如果没有弹窗 → 直接返回"无弹窗",不执行任何操作
|
|
823
|
+
- 如果有弹窗 → 自动按优先级尝试关闭
|
|
899
824
|
|
|
900
|
-
|
|
901
|
-
1️⃣
|
|
902
|
-
|
|
903
|
-
|
|
825
|
+
🎯 关闭策略(优先级从高到低):
|
|
826
|
+
1️⃣ **控件树查找**(最可靠)
|
|
827
|
+
- 查找文本"关闭"、"跳过"、"×"等
|
|
828
|
+
- 查找 resource-id 包含 close/dismiss
|
|
829
|
+
|
|
830
|
+
2️⃣ **截图 AI 分析**(次优)
|
|
831
|
+
- 返回 SoM 标注截图供 AI 视觉分析
|
|
832
|
+
- AI 找到 X 按钮后用 click_by_som(编号) 点击
|
|
904
833
|
|
|
905
|
-
|
|
834
|
+
3️⃣ **模板匹配**(兜底)
|
|
835
|
+
- 用 OpenCV 匹配已保存的 X 按钮模板
|
|
836
|
+
|
|
837
|
+
✅ 适用场景:
|
|
838
|
+
- 启动应用后检测并关闭可能出现的广告
|
|
839
|
+
- 无需先截图确认弹窗是否存在"""
|
|
840
|
+
|
|
841
|
+
tools.append(Tool(
|
|
842
|
+
name="mobile_close_ad",
|
|
843
|
+
description=desc_close_ad,
|
|
906
844
|
inputSchema={
|
|
907
845
|
"type": "object",
|
|
908
846
|
"properties": {},
|
|
@@ -912,19 +850,12 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
912
850
|
|
|
913
851
|
tools.append(Tool(
|
|
914
852
|
name="mobile_template_close",
|
|
915
|
-
description="
|
|
916
|
-
|
|
917
|
-
只用 OpenCV 模板匹配,不走控件树。
|
|
918
|
-
一般建议用 mobile_close_ad 代替(会自动先查控件树)。
|
|
919
|
-
|
|
920
|
-
⚙️ 参数:
|
|
921
|
-
- click: 是否点击,默认 true
|
|
922
|
-
- threshold: 匹配阈值 0-1,默认 0.75""",
|
|
853
|
+
description="🎯 模板匹配关闭弹窗。",
|
|
923
854
|
inputSchema={
|
|
924
855
|
"type": "object",
|
|
925
856
|
"properties": {
|
|
926
|
-
"click": {"type": "boolean", "description": "
|
|
927
|
-
"threshold": {"type": "number", "description": "
|
|
857
|
+
"click": {"type": "boolean", "description": "是否点击"},
|
|
858
|
+
"threshold": {"type": "number", "description": "阈值0-1"}
|
|
928
859
|
},
|
|
929
860
|
"required": []
|
|
930
861
|
}
|
|
@@ -932,32 +863,19 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
932
863
|
|
|
933
864
|
tools.append(Tool(
|
|
934
865
|
name="mobile_template_add",
|
|
935
|
-
description="
|
|
936
|
-
|
|
937
|
-
遇到新样式 X 号时,截图并添加到模板库。
|
|
938
|
-
|
|
939
|
-
⚙️ 两种方式(二选一):
|
|
940
|
-
1. 百分比定位(推荐):提供 x_percent, y_percent, size
|
|
941
|
-
2. 像素定位:提供 screenshot_path, x, y, width, height
|
|
942
|
-
|
|
943
|
-
📋 流程:
|
|
944
|
-
1. mobile_screenshot_with_grid 查看 X 号位置
|
|
945
|
-
2. 调用此工具添加模板
|
|
946
|
-
3. 下次同样 X 号就能自动匹配
|
|
947
|
-
|
|
948
|
-
💡 百分比示例:X 在右上角 → x_percent=85, y_percent=12, size=80""",
|
|
866
|
+
description="➕ 添加X号模板。",
|
|
949
867
|
inputSchema={
|
|
950
868
|
"type": "object",
|
|
951
869
|
"properties": {
|
|
952
|
-
"template_name": {"type": "string", "description": "
|
|
953
|
-
"x_percent": {"type": "number", "description": "X
|
|
954
|
-
"y_percent": {"type": "number", "description": "
|
|
955
|
-
"size": {"type": "integer", "description": "
|
|
956
|
-
"screenshot_path": {"type": "string", "description": "
|
|
957
|
-
"x": {"type": "integer", "description": "
|
|
958
|
-
"y": {"type": "integer", "description": "
|
|
959
|
-
"width": {"type": "integer", "description": "
|
|
960
|
-
"height": {"type": "integer", "description": "
|
|
870
|
+
"template_name": {"type": "string", "description": "模板名"},
|
|
871
|
+
"x_percent": {"type": "number", "description": "X百分比"},
|
|
872
|
+
"y_percent": {"type": "number", "description": "Y百分比"},
|
|
873
|
+
"size": {"type": "integer", "description": "裁剪大小(px)"},
|
|
874
|
+
"screenshot_path": {"type": "string", "description": "截图路径"},
|
|
875
|
+
"x": {"type": "integer", "description": "左上X"},
|
|
876
|
+
"y": {"type": "integer", "description": "左上Y"},
|
|
877
|
+
"width": {"type": "integer", "description": "宽"},
|
|
878
|
+
"height": {"type": "integer", "description": "高"}
|
|
961
879
|
},
|
|
962
880
|
"required": ["template_name"]
|
|
963
881
|
}
|
|
@@ -1009,37 +927,7 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
1009
927
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1010
928
|
|
|
1011
929
|
elif name == "mobile_screenshot_with_som":
|
|
1012
|
-
|
|
1013
|
-
result = self.tools.take_screenshot_with_som(check_popup=check_popup)
|
|
1014
|
-
|
|
1015
|
-
# 如果结果包含截图路径,尝试返回图片内容供 AI 分析
|
|
1016
|
-
screenshot_path = result.get("screenshot_path")
|
|
1017
|
-
if screenshot_path:
|
|
1018
|
-
try:
|
|
1019
|
-
from pathlib import Path
|
|
1020
|
-
import base64
|
|
1021
|
-
|
|
1022
|
-
img_path = Path(screenshot_path)
|
|
1023
|
-
if img_path.exists():
|
|
1024
|
-
# 读取图片并转换为 base64
|
|
1025
|
-
with open(img_path, 'rb') as f:
|
|
1026
|
-
image_data = f.read()
|
|
1027
|
-
image_base64 = base64.b64encode(image_data).decode('utf-8')
|
|
1028
|
-
|
|
1029
|
-
# 检查是否有 AI 分析请求
|
|
1030
|
-
ai_analysis = result.get("ai_analysis")
|
|
1031
|
-
if ai_analysis and ai_analysis.get("needs_ai_analysis"):
|
|
1032
|
-
# 返回文本结果和图片内容
|
|
1033
|
-
# 注意:MCP 协议可能不支持 ImageContent,这里先返回文本
|
|
1034
|
-
# Cursor AI 会自动看到截图文件并分析
|
|
1035
|
-
return [
|
|
1036
|
-
TextContent(type="text", text=self.format_response(result)),
|
|
1037
|
-
# 如果 MCP 支持 ImageContent,可以添加:
|
|
1038
|
-
# ImageContent(type="image", data=image_base64, mimeType="image/jpeg")
|
|
1039
|
-
]
|
|
1040
|
-
except Exception:
|
|
1041
|
-
pass # 图片处理失败,只返回文本
|
|
1042
|
-
|
|
930
|
+
result = self.tools.take_screenshot_with_som()
|
|
1043
931
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1044
932
|
|
|
1045
933
|
elif name == "mobile_click_by_som":
|
|
@@ -1063,7 +951,8 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
1063
951
|
elif name == "mobile_click_by_text":
|
|
1064
952
|
result = self.tools.click_by_text(
|
|
1065
953
|
arguments["text"],
|
|
1066
|
-
position=arguments.get("position")
|
|
954
|
+
position=arguments.get("position"),
|
|
955
|
+
verify=arguments.get("verify")
|
|
1067
956
|
)
|
|
1068
957
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1069
958
|
|
|
@@ -1129,9 +1018,7 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
1129
1018
|
result = await self.tools.swipe(
|
|
1130
1019
|
arguments["direction"],
|
|
1131
1020
|
y=arguments.get("y"),
|
|
1132
|
-
y_percent=arguments.get("y_percent")
|
|
1133
|
-
distance=arguments.get("distance"),
|
|
1134
|
-
distance_percent=arguments.get("distance_percent")
|
|
1021
|
+
y_percent=arguments.get("y_percent")
|
|
1135
1022
|
)
|
|
1136
1023
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1137
1024
|
|
|
@@ -1175,12 +1062,7 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
1175
1062
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1176
1063
|
|
|
1177
1064
|
elif name == "mobile_close_popup":
|
|
1178
|
-
|
|
1179
|
-
confidence_threshold = arguments.get("confidence_threshold", None)
|
|
1180
|
-
result = self.tools.close_popup(
|
|
1181
|
-
auto_learn=auto_learn,
|
|
1182
|
-
confidence_threshold=confidence_threshold
|
|
1183
|
-
)
|
|
1065
|
+
result = self.tools.close_popup()
|
|
1184
1066
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1185
1067
|
|
|
1186
1068
|
elif name == "mobile_assert_text":
|
|
@@ -1223,9 +1105,9 @@ Toast 是 Android 系统级的短暂提示消息,常用于显示操作结果
|
|
|
1223
1105
|
)
|
|
1224
1106
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1225
1107
|
|
|
1226
|
-
#
|
|
1108
|
+
# 智能关闭广告弹窗
|
|
1227
1109
|
elif name == "mobile_close_ad":
|
|
1228
|
-
result = self.tools.
|
|
1110
|
+
result = self.tools.close_ad_popup(auto_learn=True)
|
|
1229
1111
|
return [TextContent(type="text", text=self.format_response(result))]
|
|
1230
1112
|
|
|
1231
1113
|
# 模板匹配(精简版)
|