mobile-mcp-ai 2.3.5__tar.gz → 2.4.1__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.
Files changed (44) hide show
  1. {mobile_mcp_ai-2.3.5/mobile_mcp_ai.egg-info → mobile_mcp_ai-2.4.1}/PKG-INFO +1 -1
  2. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/basic_tools_lite.py +618 -32
  3. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/ios_client_wda.py +4 -0
  4. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mcp_tools/mcp_server.py +69 -13
  5. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1/mobile_mcp_ai.egg-info}/PKG-INFO +1 -1
  6. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/setup.py +1 -1
  7. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/LICENSE +0 -0
  8. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/MANIFEST.in +0 -0
  9. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/README.md +0 -0
  10. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/__init__.py +0 -0
  11. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/config.py +0 -0
  12. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/__init__.py +0 -0
  13. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/device_manager.py +0 -0
  14. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/dynamic_config.py +0 -0
  15. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/ios_device_manager_wda.py +0 -0
  16. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/mobile_client.py +0 -0
  17. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/utils/__init__.py +0 -0
  18. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/utils/logger.py +0 -0
  19. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/utils/operation_history_manager.py +0 -0
  20. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/core/utils/smart_wait.py +0 -0
  21. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/docs/iOS_SETUP_GUIDE.md +0 -0
  22. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mcp_tools/__init__.py +0 -0
  23. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/SOURCES.txt +0 -0
  24. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/dependency_links.txt +0 -0
  25. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/entry_points.txt +0 -0
  26. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/not-zip-safe +0 -0
  27. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/requires.txt +0 -0
  28. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/mobile_mcp_ai.egg-info/top_level.txt +0 -0
  29. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/requirements.txt +0 -0
  30. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/setup.cfg +0 -0
  31. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_mind_cloud_my_space.py +0 -0
  32. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_mind_correct.py +0 -0
  33. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_mind_improved.py +0 -0
  34. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_mind_optimized.py +0 -0
  35. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_open_mind.py +0 -0
  36. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_priority_demo.py +0 -0
  37. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_simple.py +0 -0
  38. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_/344/270/276/346/212/245.py" +0 -0
  39. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_/345/210/207/346/215/242/350/257/255/350/250/200/345/210/260English.py" +0 -0
  40. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/tests/test_/346/265/213/350/257/225.py" +0 -0
  41. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/utils/__init__.py +0 -0
  42. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/utils/logger.py +0 -0
  43. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/utils/xml_formatter.py +0 -0
  44. {mobile_mcp_ai-2.3.5 → mobile_mcp_ai-2.4.1}/utils/xml_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobile-mcp-ai
3
- Version: 2.3.5
3
+ Version: 2.4.1
4
4
  Summary: 移动端自动化 MCP Server - 支持 Android/iOS,AI 功能可选(基础工具不需要 AI)
5
5
  Home-page: https://github.com/test111ddff-hash/mobile-mcp-ai
6
6
  Author: douzi
@@ -176,6 +176,11 @@ class BasicMobileToolsLite:
176
176
 
177
177
  # ========== 情况2:全屏压缩截图 ==========
178
178
  elif compress:
179
+ # 🔴 关键:记录原始图片尺寸(用于坐标转换)
180
+ # 注意:截图尺寸可能和 u2.info 的 displayWidth 不一致!
181
+ original_img_width = img.width
182
+ original_img_height = img.height
183
+
179
184
  # 第3步:缩小尺寸(保持宽高比)
180
185
  image_width, image_height = img.width, img.height
181
186
 
@@ -224,18 +229,19 @@ class BasicMobileToolsLite:
224
229
  "screenshot_path": str(final_path),
225
230
  "screen_width": screen_width,
226
231
  "screen_height": screen_height,
227
- "image_width": image_width,
228
- "image_height": image_height,
232
+ "original_img_width": original_img_width, # 截图原始宽度
233
+ "original_img_height": original_img_height, # 截图原始高度
234
+ "image_width": image_width, # 压缩后宽度(AI 看到的)
235
+ "image_height": image_height, # 压缩后高度(AI 看到的)
229
236
  "original_size": f"{original_size/1024:.1f}KB",
230
237
  "compressed_size": f"{compressed_size/1024:.1f}KB",
231
238
  "saved_percent": f"{saved_percent:.0f}%",
232
239
  "message": f"📸 截图已保存: {final_path}\n"
233
- f"📐 屏幕尺寸: {screen_width}x{screen_height}\n"
234
- f"🖼️ 图片尺寸: {image_width}x{image_height}(AI 分析用)\n"
240
+ f"📐 原始尺寸: {original_img_width}x{original_img_height} → 压缩后: {image_width}x{image_height}\n"
235
241
  f"📦 已压缩: {original_size/1024:.0f}KB → {compressed_size/1024:.0f}KB (省 {saved_percent:.0f}%)\n"
236
- f"⚠️ 【重要】AI 返回的坐标需要转换!\n"
237
- f" 请使用 mobile_click_at_coords 并传入 image_width={image_width}, image_height={image_height}\n"
238
- f" 工具会自动将图片坐标转换为屏幕坐标"
242
+ f"⚠️ 【坐标转换】AI 返回坐标后,请传入:\n"
243
+ f" image_width={image_width}, image_height={image_height},\n"
244
+ f" original_img_width={original_img_width}, original_img_height={original_img_height}"
239
245
  }
240
246
 
241
247
  # ========== 情况3:全屏不压缩截图 ==========
@@ -249,18 +255,21 @@ class BasicMobileToolsLite:
249
255
  final_path = self.screenshot_dir / filename
250
256
  temp_path.rename(final_path)
251
257
 
258
+ # 不压缩时,用截图实际尺寸(可能和 screen_width 不同)
252
259
  return {
253
260
  "success": True,
254
261
  "screenshot_path": str(final_path),
255
262
  "screen_width": screen_width,
256
263
  "screen_height": screen_height,
257
- "image_width": screen_width,
258
- "image_height": screen_height,
264
+ "original_img_width": img.width, # 截图实际尺寸
265
+ "original_img_height": img.height,
266
+ "image_width": img.width, # 未压缩,和原图一样
267
+ "image_height": img.height,
259
268
  "file_size": f"{original_size/1024:.1f}KB",
260
269
  "message": f"📸 截图已保存: {final_path}\n"
261
- f"📐 屏幕尺寸: {screen_width}x{screen_height}\n"
270
+ f"📐 截图尺寸: {img.width}x{img.height}\n"
262
271
  f"📦 文件大小: {original_size/1024:.0f}KB(未压缩)\n"
263
- f"💡 Cursor 分析图片后,返回的坐标可直接用于 mobile_click_at_coords"
272
+ f"💡 未压缩,坐标可直接使用"
264
273
  }
265
274
  except ImportError:
266
275
  # 如果没有 PIL,回退到原始方式(不压缩)
@@ -341,20 +350,23 @@ class BasicMobileToolsLite:
341
350
  # ==================== 点击操作 ====================
342
351
 
343
352
  def click_at_coords(self, x: int, y: int, image_width: int = 0, image_height: int = 0,
344
- crop_offset_x: int = 0, crop_offset_y: int = 0) -> Dict:
353
+ crop_offset_x: int = 0, crop_offset_y: int = 0,
354
+ original_img_width: int = 0, original_img_height: int = 0) -> Dict:
345
355
  """点击坐标(核心功能,支持自动坐标转换)
346
356
 
347
357
  Args:
348
358
  x: X 坐标(来自截图分析或屏幕坐标)
349
359
  y: Y 坐标(来自截图分析或屏幕坐标)
350
- image_width: 截图的宽度(可选,传入后自动转换坐标)
351
- image_height: 截图的高度(可选,传入后自动转换坐标)
352
- crop_offset_x: 局部截图的 X 偏移量(可选,局部截图时传入)
353
- crop_offset_y: 局部截图的 Y 偏移量(可选,局部截图时传入)
360
+ image_width: 压缩后图片宽度(AI 看到的图片尺寸)
361
+ image_height: 压缩后图片高度(AI 看到的图片尺寸)
362
+ crop_offset_x: 局部截图的 X 偏移量(局部截图时传入)
363
+ crop_offset_y: 局部截图的 Y 偏移量(局部截图时传入)
364
+ original_img_width: 截图原始宽度(压缩前的尺寸,用于精确转换)
365
+ original_img_height: 截图原始高度(压缩前的尺寸,用于精确转换)
354
366
 
355
367
  坐标转换说明:
356
- 1. 全屏压缩截图:传入 image_width/image_height,自动按比例转换
357
- 2. 局部裁剪截图:传入 crop_offset_x/crop_offset_y,自动加上偏移量
368
+ 1. 全屏压缩截图:AI 坐标 → 原图坐标(基于 image/original_img 比例)
369
+ 2. 局部裁剪截图:AI 坐标 + 偏移量 = 屏幕坐标
358
370
  """
359
371
  try:
360
372
  # 获取屏幕尺寸
@@ -382,13 +394,19 @@ class BasicMobileToolsLite:
382
394
  y = y + crop_offset_y
383
395
  converted = True
384
396
  conversion_type = "crop_offset"
385
- # 情况2:全屏压缩截图 - 按比例转换
386
- elif image_width > 0 and image_height > 0 and screen_width > 0 and screen_height > 0:
387
- if image_width != screen_width or image_height != screen_height:
388
- x = int(x * screen_width / image_width)
389
- y = int(y * screen_height / image_height)
390
- converted = True
391
- conversion_type = "scale"
397
+ # 情况2:全屏压缩截图 - 按比例转换到原图尺寸
398
+ elif image_width > 0 and image_height > 0:
399
+ # 优先使用 original_img_width/height(更精确)
400
+ # 如果没传,则用 screen_width/height(兼容旧版本)
401
+ target_width = original_img_width if original_img_width > 0 else screen_width
402
+ target_height = original_img_height if original_img_height > 0 else screen_height
403
+
404
+ if target_width > 0 and target_height > 0:
405
+ if image_width != target_width or image_height != target_height:
406
+ x = int(x * target_width / image_width)
407
+ y = int(y * target_height / image_height)
408
+ converted = True
409
+ conversion_type = "scale"
392
410
 
393
411
  # 执行点击
394
412
  if self._is_ios():
@@ -634,7 +652,14 @@ class BasicMobileToolsLite:
634
652
  # ==================== 输入操作 ====================
635
653
 
636
654
  def input_text_by_id(self, resource_id: str, text: str) -> Dict:
637
- """通过 resource-id 输入文本"""
655
+ """通过 resource-id 输入文本
656
+
657
+ 优化策略:
658
+ 1. 先用 resourceId 定位
659
+ 2. 如果只有 1 个元素 → 直接输入
660
+ 3. 如果有多个相同 ID(>5个说明 ID 不可靠)→ 改用 EditText 类型定位
661
+ 4. 多个 EditText 时选择最靠上的(搜索框通常在顶部)
662
+ """
638
663
  try:
639
664
  if self._is_ios():
640
665
  ios_client = self._get_ios_client()
@@ -649,13 +674,70 @@ class BasicMobileToolsLite:
649
674
  return {"success": True, "message": f"✅ 输入成功: '{text}'"}
650
675
  return {"success": False, "message": f"❌ 输入框不存在: {resource_id}"}
651
676
  else:
652
- elem = self.client.u2(resourceId=resource_id)
653
- if elem.exists(timeout=0.5):
654
- elem.set_text(text)
655
- time.sleep(0.3)
656
- self._record_operation('input', element=resource_id, ref=resource_id, text=text)
657
- return {"success": True, "message": f"✅ 输入成功: '{text}'"}
677
+ elements = self.client.u2(resourceId=resource_id)
678
+
679
+ # 检查是否存在
680
+ if elements.exists(timeout=0.5):
681
+ count = elements.count
682
+
683
+ # 只有 1 个元素,直接输入
684
+ if count == 1:
685
+ elements.set_text(text)
686
+ time.sleep(0.3)
687
+ self._record_operation('input', element=resource_id, ref=resource_id, text=text)
688
+ return {"success": True, "message": f"✅ 输入成功: '{text}'"}
689
+
690
+ # 多个相同 ID(<=5个),尝试智能选择
691
+ if count <= 5:
692
+ for i in range(count):
693
+ try:
694
+ elem = elements[i]
695
+ info = elem.info
696
+ # 优先选择可编辑的
697
+ if info.get('editable') or info.get('focusable'):
698
+ elem.set_text(text)
699
+ time.sleep(0.3)
700
+ self._record_operation('input', element=resource_id, ref=resource_id, text=text)
701
+ return {"success": True, "message": f"✅ 输入成功: '{text}'"}
702
+ except:
703
+ continue
704
+ # 没找到可编辑的,用第一个
705
+ elements[0].set_text(text)
706
+ time.sleep(0.3)
707
+ self._record_operation('input', element=resource_id, ref=resource_id, text=text)
708
+ return {"success": True, "message": f"✅ 输入成功: '{text}'"}
709
+
710
+ # ID 不可靠(不存在或太多),改用 EditText 类型定位
711
+ edit_texts = self.client.u2(className='android.widget.EditText')
712
+ if edit_texts.exists(timeout=0.5):
713
+ et_count = edit_texts.count
714
+ if et_count == 1:
715
+ edit_texts.set_text(text)
716
+ time.sleep(0.3)
717
+ self._record_operation('input', element='EditText', ref='EditText', text=text)
718
+ return {"success": True, "message": f"✅ 输入成功: '{text}' (通过 EditText 定位)"}
719
+
720
+ # 多个 EditText,选择最靠上的
721
+ best_elem = None
722
+ min_top = 9999
723
+ for i in range(et_count):
724
+ try:
725
+ elem = edit_texts[i]
726
+ top = elem.info.get('bounds', {}).get('top', 9999)
727
+ if top < min_top:
728
+ min_top = top
729
+ best_elem = elem
730
+ except:
731
+ continue
732
+
733
+ if best_elem:
734
+ best_elem.set_text(text)
735
+ time.sleep(0.3)
736
+ self._record_operation('input', element='EditText', ref='EditText', text=text)
737
+ return {"success": True, "message": f"✅ 输入成功: '{text}' (通过 EditText 定位,选择最顶部的)"}
738
+
658
739
  return {"success": False, "message": f"❌ 输入框不存在: {resource_id}"}
740
+
659
741
  except Exception as e:
660
742
  return {"success": False, "message": f"❌ 输入失败: {e}"}
661
743
 
@@ -919,6 +1001,510 @@ class BasicMobileToolsLite:
919
1001
  except Exception as e:
920
1002
  return [{"error": f"获取元素失败: {e}"}]
921
1003
 
1004
+ def find_close_button(self) -> Dict:
1005
+ """智能查找关闭按钮(不点击,只返回位置)
1006
+
1007
+ 从元素列表中找最可能的关闭按钮,返回其坐标和百分比位置。
1008
+ 适用于关闭弹窗广告等场景。
1009
+
1010
+ Returns:
1011
+ 包含关闭按钮位置信息的字典,或截图让 AI 分析
1012
+ """
1013
+ try:
1014
+ import re
1015
+
1016
+ if self._is_ios():
1017
+ return {"success": False, "message": "iOS 暂不支持,请使用截图+坐标点击"}
1018
+
1019
+ # 获取屏幕尺寸
1020
+ screen_width = self.client.u2.info.get('displayWidth', 720)
1021
+ screen_height = self.client.u2.info.get('displayHeight', 1280)
1022
+
1023
+ # 获取元素列表
1024
+ xml_string = self.client.u2.dump_hierarchy()
1025
+ import xml.etree.ElementTree as ET
1026
+ root = ET.fromstring(xml_string)
1027
+
1028
+ # 关闭按钮特征
1029
+ close_texts = ['×', 'X', 'x', '关闭', '取消', 'close', 'Close', '跳过', '知道了', '我知道了']
1030
+ candidates = []
1031
+
1032
+ for elem in root.iter():
1033
+ text = elem.attrib.get('text', '')
1034
+ content_desc = elem.attrib.get('content-desc', '')
1035
+ bounds_str = elem.attrib.get('bounds', '')
1036
+ class_name = elem.attrib.get('class', '')
1037
+ clickable = elem.attrib.get('clickable', 'false') == 'true'
1038
+
1039
+ if not bounds_str:
1040
+ continue
1041
+
1042
+ match = re.match(r'\[(\d+),(\d+)\]\[(\d+),(\d+)\]', bounds_str)
1043
+ if not match:
1044
+ continue
1045
+
1046
+ x1, y1, x2, y2 = map(int, match.groups())
1047
+ width = x2 - x1
1048
+ height = y2 - y1
1049
+ center_x = (x1 + x2) // 2
1050
+ center_y = (y1 + y2) // 2
1051
+
1052
+ # 计算百分比
1053
+ x_percent = round(center_x / screen_width * 100, 1)
1054
+ y_percent = round(center_y / screen_height * 100, 1)
1055
+
1056
+ score = 0
1057
+ reason = ""
1058
+
1059
+ # 策略1:关闭文本
1060
+ if text in close_texts:
1061
+ score = 100
1062
+ reason = f"文本='{text}'"
1063
+
1064
+ # 策略2:content-desc 包含关闭关键词
1065
+ elif any(kw in content_desc.lower() for kw in ['关闭', 'close', 'dismiss', '跳过']):
1066
+ score = 90
1067
+ reason = f"描述='{content_desc}'"
1068
+
1069
+ # 策略3:小尺寸的 clickable 元素(可能是 X 图标)
1070
+ elif clickable:
1071
+ min_size = max(20, int(screen_width * 0.03))
1072
+ max_size = max(120, int(screen_width * 0.12))
1073
+ if min_size <= width <= max_size and min_size <= height <= max_size:
1074
+ # 基于位置评分:角落位置加分
1075
+ rel_x = center_x / screen_width
1076
+ rel_y = center_y / screen_height
1077
+
1078
+ # 右上角得分最高
1079
+ if rel_x > 0.6 and rel_y < 0.5:
1080
+ score = 70 + (rel_x - 0.6) * 50 + (0.5 - rel_y) * 50
1081
+ reason = f"右上角小元素 {width}x{height}px"
1082
+ # 左上角
1083
+ elif rel_x < 0.4 and rel_y < 0.5:
1084
+ score = 60 + (0.4 - rel_x) * 50 + (0.5 - rel_y) * 50
1085
+ reason = f"左上角小元素 {width}x{height}px"
1086
+ # 其他位置的小元素
1087
+ elif 'Image' in class_name:
1088
+ score = 50
1089
+ reason = f"图片元素 {width}x{height}px"
1090
+ else:
1091
+ score = 40
1092
+ reason = f"小型可点击元素 {width}x{height}px"
1093
+
1094
+ if score > 0:
1095
+ candidates.append({
1096
+ 'score': score,
1097
+ 'reason': reason,
1098
+ 'bounds': bounds_str,
1099
+ 'center_x': center_x,
1100
+ 'center_y': center_y,
1101
+ 'x_percent': x_percent,
1102
+ 'y_percent': y_percent,
1103
+ 'size': f"{width}x{height}"
1104
+ })
1105
+
1106
+ if not candidates:
1107
+ # 没找到,截图让 AI 分析
1108
+ screenshot_result = self.take_screenshot(description="找关闭按钮", compress=True)
1109
+ return {
1110
+ "success": False,
1111
+ "message": "❌ 元素树未找到关闭按钮,已截图供 AI 分析",
1112
+ "screenshot": screenshot_result.get("screenshot_path", ""),
1113
+ "screen_size": {"width": screen_width, "height": screen_height},
1114
+ "image_size": {
1115
+ "width": screenshot_result.get("image_width"),
1116
+ "height": screenshot_result.get("image_height")
1117
+ },
1118
+ "original_size": {
1119
+ "width": screenshot_result.get("original_img_width"),
1120
+ "height": screenshot_result.get("original_img_height")
1121
+ },
1122
+ "tip": "请分析截图找到 X 关闭按钮,然后调用 mobile_click_by_percent(x_percent, y_percent)"
1123
+ }
1124
+
1125
+ # 按得分排序
1126
+ candidates.sort(key=lambda x: x['score'], reverse=True)
1127
+ best = candidates[0]
1128
+
1129
+ return {
1130
+ "success": True,
1131
+ "message": f"✅ 找到可能的关闭按钮",
1132
+ "best_candidate": {
1133
+ "reason": best['reason'],
1134
+ "center": {"x": best['center_x'], "y": best['center_y']},
1135
+ "percent": {"x": best['x_percent'], "y": best['y_percent']},
1136
+ "bounds": best['bounds'],
1137
+ "size": best['size'],
1138
+ "score": best['score']
1139
+ },
1140
+ "click_command": f"mobile_click_by_percent({best['x_percent']}, {best['y_percent']})",
1141
+ "other_candidates": [
1142
+ {"reason": c['reason'], "percent": f"({c['x_percent']}%, {c['y_percent']}%)", "score": c['score']}
1143
+ for c in candidates[1:4]
1144
+ ] if len(candidates) > 1 else [],
1145
+ "screen_size": {"width": screen_width, "height": screen_height}
1146
+ }
1147
+
1148
+ except Exception as e:
1149
+ return {"success": False, "message": f"❌ 查找关闭按钮失败: {e}"}
1150
+
1151
+ def close_popup(self) -> Dict:
1152
+ """智能关闭弹窗(改进版)
1153
+
1154
+ 核心改进:先检测弹窗区域,再在弹窗范围内查找关闭按钮
1155
+
1156
+ 策略(优先级从高到低):
1157
+ 1. 检测弹窗区域(非全屏的大面积容器)
1158
+ 2. 在弹窗边界内查找关闭相关的文本/描述(×、X、关闭、close 等)
1159
+ 3. 在弹窗边界内查找小尺寸的 clickable 元素(优先边角位置)
1160
+ 4. 如果都找不到,截图让 AI 视觉识别
1161
+
1162
+ 适配策略:
1163
+ - X 按钮可能在任意位置(上下左右都支持)
1164
+ - 使用百分比坐标记录,跨分辨率兼容
1165
+ """
1166
+ try:
1167
+ import re
1168
+ import xml.etree.ElementTree as ET
1169
+
1170
+ # 获取屏幕尺寸
1171
+ if self._is_ios():
1172
+ return {"success": False, "message": "iOS 暂不支持,请使用截图+坐标点击"}
1173
+
1174
+ screen_width = self.client.u2.info.get('displayWidth', 720)
1175
+ screen_height = self.client.u2.info.get('displayHeight', 1280)
1176
+
1177
+ # 获取原始 XML
1178
+ xml_string = self.client.u2.dump_hierarchy()
1179
+
1180
+ # 关闭按钮的文本特征
1181
+ close_texts = ['×', 'X', 'x', '关闭', '取消', 'close', 'Close', 'CLOSE', '跳过', '知道了']
1182
+ close_desc_keywords = ['关闭', 'close', 'dismiss', 'cancel', '跳过']
1183
+
1184
+ close_candidates = []
1185
+ popup_bounds = None # 弹窗区域
1186
+
1187
+ # 解析 XML
1188
+ try:
1189
+ root = ET.fromstring(xml_string)
1190
+ all_elements = list(root.iter())
1191
+
1192
+ # ===== 第一步:检测弹窗区域 =====
1193
+ # 弹窗特征:非全屏、面积较大、通常在屏幕中央的容器
1194
+ popup_containers = []
1195
+ for idx, elem in enumerate(all_elements):
1196
+ bounds_str = elem.attrib.get('bounds', '')
1197
+ class_name = elem.attrib.get('class', '')
1198
+
1199
+ if not bounds_str:
1200
+ continue
1201
+
1202
+ match = re.match(r'\[(\d+),(\d+)\]\[(\d+),(\d+)\]', bounds_str)
1203
+ if not match:
1204
+ continue
1205
+
1206
+ x1, y1, x2, y2 = map(int, match.groups())
1207
+ width = x2 - x1
1208
+ height = y2 - y1
1209
+ area = width * height
1210
+ screen_area = screen_width * screen_height
1211
+
1212
+ # 弹窗容器特征:
1213
+ # 1. 面积在屏幕的 10%-90% 之间(非全屏)
1214
+ # 2. 宽度或高度不等于屏幕尺寸
1215
+ # 3. 是容器类型(Layout/View/Dialog)
1216
+ is_container = any(kw in class_name for kw in ['Layout', 'View', 'Dialog', 'Card', 'Container'])
1217
+ area_ratio = area / screen_area
1218
+ is_not_fullscreen = (width < screen_width * 0.98 or height < screen_height * 0.98)
1219
+ is_reasonable_size = 0.08 < area_ratio < 0.9
1220
+
1221
+ # 排除状态栏区域(y1 通常很小)
1222
+ is_below_statusbar = y1 > 50
1223
+
1224
+ if is_container and is_not_fullscreen and is_reasonable_size and is_below_statusbar:
1225
+ popup_containers.append({
1226
+ 'bounds': (x1, y1, x2, y2),
1227
+ 'bounds_str': bounds_str,
1228
+ 'area': area,
1229
+ 'area_ratio': area_ratio,
1230
+ 'idx': idx, # 元素在 XML 中的顺序(越后越上层)
1231
+ 'class': class_name
1232
+ })
1233
+
1234
+ # 选择最可能的弹窗容器(优先选择:XML 顺序靠后 + 面积适中)
1235
+ if popup_containers:
1236
+ # 按 XML 顺序倒序(后出现的在上层),然后按面积适中程度排序
1237
+ popup_containers.sort(key=lambda x: (x['idx'], -abs(x['area_ratio'] - 0.3)), reverse=True)
1238
+ popup_bounds = popup_containers[0]['bounds']
1239
+
1240
+ # ===== 第二步:在弹窗范围内查找关闭按钮 =====
1241
+ for idx, elem in enumerate(all_elements):
1242
+ text = elem.attrib.get('text', '')
1243
+ content_desc = elem.attrib.get('content-desc', '')
1244
+ bounds_str = elem.attrib.get('bounds', '')
1245
+ class_name = elem.attrib.get('class', '')
1246
+ clickable = elem.attrib.get('clickable', 'false') == 'true'
1247
+
1248
+ if not bounds_str:
1249
+ continue
1250
+
1251
+ # 解析 bounds
1252
+ match = re.match(r'\[(\d+),(\d+)\]\[(\d+),(\d+)\]', bounds_str)
1253
+ if not match:
1254
+ continue
1255
+
1256
+ x1, y1, x2, y2 = map(int, match.groups())
1257
+ width = x2 - x1
1258
+ height = y2 - y1
1259
+ center_x = (x1 + x2) // 2
1260
+ center_y = (y1 + y2) // 2
1261
+
1262
+ # 如果检测到弹窗区域,检查元素是否在弹窗范围内或附近
1263
+ in_popup = True
1264
+ popup_edge_bonus = 0
1265
+ is_floating_close = False # 是否是浮动关闭按钮(在弹窗外部上方)
1266
+ if popup_bounds:
1267
+ px1, py1, px2, py2 = popup_bounds
1268
+
1269
+ # 关闭按钮可能在弹窗外部(常见设计:X 按钮浮在弹窗右上角外侧)
1270
+ # 扩大搜索范围:弹窗上方 200 像素,右侧 50 像素
1271
+ margin_top = 200 # 上方扩展范围(关闭按钮常在弹窗上方)
1272
+ margin_side = 50 # 左右扩展范围
1273
+ margin_bottom = 30 # 下方扩展范围
1274
+
1275
+ in_popup = (px1 - margin_side <= center_x <= px2 + margin_side and
1276
+ py1 - margin_top <= center_y <= py2 + margin_bottom)
1277
+
1278
+ # 检查是否是浮动关闭按钮(在弹窗外侧:上方或下方)
1279
+ # 上方浮动关闭按钮(常见:右上角外侧)
1280
+ if center_y < py1 and center_y > py1 - margin_top:
1281
+ if center_x > (px1 + px2) / 2: # 在弹窗右半部分上方
1282
+ is_floating_close = True
1283
+ # 下方浮动关闭按钮(常见:底部中间外侧)
1284
+ elif center_y > py2 and center_y < py2 + margin_top:
1285
+ # 下方关闭按钮通常在中间位置
1286
+ if abs(center_x - (px1 + px2) / 2) < (px2 - px1) / 2:
1287
+ is_floating_close = True
1288
+
1289
+ if in_popup:
1290
+ # 计算元素是否在弹窗边缘(关闭按钮通常在边缘)
1291
+ dist_to_top = abs(center_y - py1)
1292
+ dist_to_bottom = abs(center_y - py2)
1293
+ dist_to_left = abs(center_x - px1)
1294
+ dist_to_right = abs(center_x - px2)
1295
+ min_dist = min(dist_to_top, dist_to_bottom, dist_to_left, dist_to_right)
1296
+
1297
+ # 在弹窗边缘 100 像素内的元素加分
1298
+ if min_dist < 100:
1299
+ popup_edge_bonus = 3.0 * (1 - min_dist / 100)
1300
+
1301
+ # 浮动关闭按钮(在弹窗上方外侧)给予高额加分
1302
+ if is_floating_close:
1303
+ popup_edge_bonus += 5.0 # 大幅加分
1304
+
1305
+ if not in_popup:
1306
+ continue
1307
+
1308
+ # 相对位置(0-1)
1309
+ rel_x = center_x / screen_width
1310
+ rel_y = center_y / screen_height
1311
+
1312
+ score = 0
1313
+ match_type = ""
1314
+ position = self._get_position_name(rel_x, rel_y)
1315
+
1316
+ # ===== 策略1:精确匹配关闭文本(最高优先级)=====
1317
+ if text in close_texts:
1318
+ score = 15.0 + popup_edge_bonus
1319
+ match_type = f"text='{text}'"
1320
+
1321
+ # ===== 策略2:content-desc 包含关闭关键词 =====
1322
+ elif any(kw in content_desc.lower() for kw in close_desc_keywords):
1323
+ score = 12.0 + popup_edge_bonus
1324
+ match_type = f"desc='{content_desc}'"
1325
+
1326
+ # ===== 策略3:clickable 的小尺寸元素(优先于非 clickable)=====
1327
+ elif clickable:
1328
+ min_size = max(20, int(screen_width * 0.03))
1329
+ max_size = max(120, int(screen_width * 0.15))
1330
+ if min_size <= width <= max_size and min_size <= height <= max_size:
1331
+ # clickable 元素基础分更高
1332
+ base_score = 8.0
1333
+ # 浮动关闭按钮给予最高分
1334
+ if is_floating_close:
1335
+ base_score = 12.0
1336
+ match_type = "floating_close"
1337
+ elif 'Image' in class_name:
1338
+ score = base_score + 2.0
1339
+ match_type = "clickable_image"
1340
+ else:
1341
+ match_type = "clickable"
1342
+ score = base_score + self._get_position_score(rel_x, rel_y) + popup_edge_bonus
1343
+
1344
+ # ===== 策略4:ImageView/ImageButton 类型的小元素(非 clickable)=====
1345
+ elif 'Image' in class_name:
1346
+ min_size = max(15, int(screen_width * 0.02))
1347
+ max_size = max(120, int(screen_width * 0.12))
1348
+ if min_size <= width <= max_size and min_size <= height <= max_size:
1349
+ score = 5.0 + self._get_position_score(rel_x, rel_y) + popup_edge_bonus
1350
+ match_type = "ImageView"
1351
+
1352
+ # XML 顺序加分(后出现的元素在上层,更可能是弹窗内的元素)
1353
+ if score > 0:
1354
+ xml_order_bonus = idx / len(all_elements) * 2.0 # 最多加 2 分
1355
+ score += xml_order_bonus
1356
+
1357
+ close_candidates.append({
1358
+ 'bounds': bounds_str,
1359
+ 'center_x': center_x,
1360
+ 'center_y': center_y,
1361
+ 'width': width,
1362
+ 'height': height,
1363
+ 'score': score,
1364
+ 'position': position,
1365
+ 'match_type': match_type,
1366
+ 'text': text,
1367
+ 'content_desc': content_desc,
1368
+ 'x_percent': round(rel_x * 100, 1),
1369
+ 'y_percent': round(rel_y * 100, 1),
1370
+ 'in_popup': popup_bounds is not None
1371
+ })
1372
+
1373
+ except ET.ParseError:
1374
+ pass
1375
+
1376
+ if not close_candidates:
1377
+ # 控件树未找到,自动截全屏图供 AI 分析
1378
+ screenshot_result = self.take_screenshot(description="弹窗全屏", compress=True)
1379
+
1380
+ # 构建更详细的视觉分析提示
1381
+ visual_hint = "请仔细查看截图,找到关闭按钮(通常是 × 或 X 图标)。"
1382
+ if popup_bounds:
1383
+ px1, py1, px2, py2 = popup_bounds
1384
+ visual_hint += f" 弹窗区域大约在 [{px1},{py1}] 到 [{px2},{py2}],关闭按钮通常在弹窗的右上角或正上方。"
1385
+ else:
1386
+ visual_hint += " 关闭按钮通常在屏幕右上角、弹窗右上角、或弹窗下方中间位置。"
1387
+
1388
+ return {
1389
+ "success": False,
1390
+ "message": "❌ 控件树未找到关闭按钮,已截全屏图供 AI 视觉分析",
1391
+ "action_required": visual_hint + " 找到后调用 mobile_click_at_coords(x, y, image_width, image_height, original_img_width, original_img_height) 点击。",
1392
+ "screenshot": screenshot_result.get("screenshot_path", ""),
1393
+ "screen_size": {"width": screen_width, "height": screen_height},
1394
+ "image_size": {
1395
+ "width": screenshot_result.get("image_width", screen_width),
1396
+ "height": screenshot_result.get("image_height", screen_height)
1397
+ },
1398
+ "original_size": {
1399
+ "width": screenshot_result.get("original_img_width", screen_width),
1400
+ "height": screenshot_result.get("original_img_height", screen_height)
1401
+ },
1402
+ "popup_detected": popup_bounds is not None,
1403
+ "popup_bounds": f"[{popup_bounds[0]},{popup_bounds[1]}][{popup_bounds[2]},{popup_bounds[3]}]" if popup_bounds else None,
1404
+ "search_areas": [
1405
+ "弹窗右上角(最常见)",
1406
+ "弹窗正上方外侧(浮动X按钮)",
1407
+ "弹窗下方中间(某些广告)",
1408
+ "屏幕右上角"
1409
+ ],
1410
+ "button_features": "关闭按钮通常是:小圆形/方形图标、灰色或白色、带有 × 或 X 符号",
1411
+ "tip": "注意:不要点击广告内容区域,只点击关闭按钮"
1412
+ }
1413
+
1414
+ # 按得分排序,取最可能的
1415
+ close_candidates.sort(key=lambda x: x['score'], reverse=True)
1416
+ best = close_candidates[0]
1417
+
1418
+ # 点击
1419
+ self.client.u2.click(best['center_x'], best['center_y'])
1420
+ time.sleep(0.5)
1421
+
1422
+ # 点击后截图,让 AI 判断是否成功
1423
+ screenshot_result = self.take_screenshot("关闭弹窗后")
1424
+
1425
+ # 记录操作(使用百分比,跨设备兼容)
1426
+ self._record_operation(
1427
+ 'click',
1428
+ x=best['center_x'],
1429
+ y=best['center_y'],
1430
+ x_percent=best['x_percent'],
1431
+ y_percent=best['y_percent'],
1432
+ screen_width=screen_width,
1433
+ screen_height=screen_height,
1434
+ ref=f"close_popup_{best['position']}"
1435
+ )
1436
+
1437
+ # 返回候选按钮列表,让 AI 看截图判断
1438
+ # 如果弹窗还在,AI 可以选择点击其他候选按钮
1439
+ return {
1440
+ "success": True,
1441
+ "message": f"✅ 已点击关闭按钮 ({best['position']}): ({best['center_x']}, {best['center_y']})",
1442
+ "clicked": {
1443
+ "position": best['position'],
1444
+ "match_type": best['match_type'],
1445
+ "coords": (best['center_x'], best['center_y']),
1446
+ "percent": (best['x_percent'], best['y_percent'])
1447
+ },
1448
+ "screenshot": screenshot_result.get("screenshot_path", ""),
1449
+ "popup_detected": popup_bounds is not None,
1450
+ "popup_bounds": f"[{popup_bounds[0]},{popup_bounds[1]}][{popup_bounds[2]},{popup_bounds[3]}]" if popup_bounds else None,
1451
+ "other_candidates": [
1452
+ {
1453
+ "position": c['position'],
1454
+ "type": c['match_type'],
1455
+ "coords": (c['center_x'], c['center_y']),
1456
+ "percent": (c['x_percent'], c['y_percent'])
1457
+ }
1458
+ for c in close_candidates[1:4] # 返回其他3个候选,AI 可以选择
1459
+ ],
1460
+ "tip": "请查看截图判断弹窗是否已关闭。如果弹窗还在,可以尝试点击 other_candidates 中的其他位置;如果误点跳转了,请按返回键"
1461
+ }
1462
+
1463
+ except Exception as e:
1464
+ return {"success": False, "message": f"❌ 关闭弹窗失败: {e}"}
1465
+
1466
+ def _get_position_name(self, rel_x: float, rel_y: float) -> str:
1467
+ """根据相对坐标获取位置名称"""
1468
+ if rel_y < 0.4:
1469
+ if rel_x > 0.6:
1470
+ return "右上角"
1471
+ elif rel_x < 0.4:
1472
+ return "左上角"
1473
+ else:
1474
+ return "顶部中间"
1475
+ elif rel_y > 0.6:
1476
+ if rel_x > 0.6:
1477
+ return "右下角"
1478
+ elif rel_x < 0.4:
1479
+ return "左下角"
1480
+ else:
1481
+ return "底部中间"
1482
+ else:
1483
+ if rel_x > 0.6:
1484
+ return "右侧"
1485
+ elif rel_x < 0.4:
1486
+ return "左侧"
1487
+ else:
1488
+ return "中间"
1489
+
1490
+ def _get_position_score(self, rel_x: float, rel_y: float) -> float:
1491
+ """根据位置计算额外得分(角落位置加分更多)"""
1492
+ # 弹窗关闭按钮常见位置得分:右上角 > 左上角 > 底部中间 > 其他角落
1493
+ if rel_y < 0.4: # 上半部分
1494
+ if rel_x > 0.6: # 右上角
1495
+ return 2.0 + (rel_x - 0.6) + (0.4 - rel_y)
1496
+ elif rel_x < 0.4: # 左上角
1497
+ return 1.5 + (0.4 - rel_x) + (0.4 - rel_y)
1498
+ else: # 顶部中间
1499
+ return 1.0
1500
+ elif rel_y > 0.6: # 下半部分
1501
+ if 0.3 < rel_x < 0.7: # 底部中间
1502
+ return 1.2 + (1 - abs(rel_x - 0.5) * 2)
1503
+ else: # 底部角落
1504
+ return 0.8
1505
+ else: # 中间区域
1506
+ return 0.5
1507
+
922
1508
  def assert_text(self, text: str) -> Dict:
923
1509
  """检查页面是否包含文本"""
924
1510
  try:
@@ -99,7 +99,8 @@ class MobileMCPServer:
99
99
 
100
100
  async def initialize(self):
101
101
  """延迟初始化设备连接"""
102
- if self._initialized:
102
+ # 如果已成功初始化,直接返回
103
+ if self._initialized and self.tools is not None:
103
104
  return
104
105
 
105
106
  platform = self._detect_platform()
@@ -110,13 +111,13 @@ class MobileMCPServer:
110
111
 
111
112
  self.client = MobileClient(platform=platform)
112
113
  self.tools = BasicMobileToolsLite(self.client)
114
+ self._initialized = True # 只在成功时标记
113
115
  print(f"📱 已连接到 {platform.upper()} 设备", file=sys.stderr)
114
116
  except Exception as e:
115
- print(f"⚠️ 设备连接失败: {e}", file=sys.stderr)
116
- self.client = type('MockClient', (), {'platform': platform})()
117
+ print(f"⚠️ 设备连接失败: {e},下次调用时将重试", file=sys.stderr)
118
+ self.client = None
117
119
  self.tools = None
118
-
119
- self._initialized = True
120
+ # 不设置 _initialized = True,下次调用会重试
120
121
 
121
122
  def _detect_platform(self) -> str:
122
123
  """自动检测设备平台"""
@@ -225,17 +226,20 @@ class MobileMCPServer:
225
226
  "- 游戏(Unity/Cocos)无法获取元素\n"
226
227
  "- mobile_list_elements 返回空\n"
227
228
  "- 元素没有 id 和 text\n\n"
228
- "⚠️ 【坐标转换】两种场景:\n"
229
- " 1. 全屏压缩截图:传入 image_width + image_height 自动按比例转换\n"
230
- " 2. 局部裁剪截图:传入 crop_offset_x + crop_offset_y → 自动加偏移\n\n"
229
+ "⚠️ 【坐标转换】截图返回的参数直接传入:\n"
230
+ " - image_width/image_height: 压缩后尺寸(AI 看到的)\n"
231
+ " - original_img_width/original_img_height: 原图尺寸(用于转换)\n"
232
+ " - crop_offset_x/crop_offset_y: 局部截图偏移\n\n"
231
233
  "✅ 自动记录百分比坐标,生成脚本时转换为跨分辨率兼容的百分比定位",
232
234
  inputSchema={
233
235
  "type": "object",
234
236
  "properties": {
235
- "x": {"type": "number", "description": "X 坐标(像素,来自截图分析或屏幕坐标)"},
236
- "y": {"type": "number", "description": "Y 坐标(像素,来自截图分析或屏幕坐标)"},
237
- "image_width": {"type": "number", "description": "全屏截图宽度(压缩截图时传入)"},
238
- "image_height": {"type": "number", "description": "全屏截图高度(压缩截图时传入)"},
237
+ "x": {"type": "number", "description": "X 坐标(来自 AI 分析截图)"},
238
+ "y": {"type": "number", "description": "Y 坐标(来自 AI 分析截图)"},
239
+ "image_width": {"type": "number", "description": "压缩后图片宽度(截图返回的 image_width)"},
240
+ "image_height": {"type": "number", "description": "压缩后图片高度(截图返回的 image_height)"},
241
+ "original_img_width": {"type": "number", "description": "原图宽度(截图返回的 original_img_width)"},
242
+ "original_img_height": {"type": "number", "description": "原图高度(截图返回的 original_img_height)"},
239
243
  "crop_offset_x": {"type": "number", "description": "局部截图 X 偏移(裁剪截图时传入)"},
240
244
  "crop_offset_y": {"type": "number", "description": "局部截图 Y 偏移(裁剪截图时传入)"}
241
245
  },
@@ -383,6 +387,48 @@ class MobileMCPServer:
383
387
  ))
384
388
 
385
389
  # ==================== 辅助工具 ====================
390
+ tools.append(Tool(
391
+ name="mobile_find_close_button",
392
+ description="""🔍 智能查找关闭按钮(只找不点,返回位置)
393
+
394
+ 从元素树中找最可能的关闭按钮,返回坐标和百分比位置。
395
+
396
+ 🎯 识别策略(优先级):
397
+ 1. 文本匹配:×、X、关闭、取消、跳过 等
398
+ 2. 描述匹配:content-desc 包含 close/关闭
399
+ 3. 小尺寸 clickable 元素(右上角优先)
400
+
401
+ ✅ 返回内容:
402
+ - 坐标 (x, y) 和百分比 (x%, y%)
403
+ - 推荐的点击命令:mobile_click_by_percent(x%, y%)
404
+ - 多个候选位置(供确认)
405
+
406
+ 💡 使用流程:
407
+ 1. 调用此工具找到关闭按钮位置
408
+ 2. 确认位置正确后,用 mobile_click_by_percent 点击
409
+ 3. 百分比点击兼容不同分辨率手机""",
410
+ inputSchema={"type": "object", "properties": {}, "required": []}
411
+ ))
412
+
413
+ tools.append(Tool(
414
+ name="mobile_close_popup",
415
+ description="""🚫 智能关闭弹窗(直接点击)
416
+
417
+ 自动识别并点击关闭按钮,一步完成。
418
+
419
+ 🎯 识别策略:
420
+ 1. 文本匹配:×、X、关闭、取消、跳过 等
421
+ 2. 描述匹配:content-desc 包含 close/关闭
422
+ 3. ImageView/ImageButton 小元素
423
+ 4. clickable 的小尺寸元素(角落位置优先)
424
+
425
+ ⚠️ 如果自动识别失败:
426
+ - 会截图供 AI 分析
427
+ - 用 mobile_find_close_button 先查看候选位置
428
+ - 或用 mobile_click_by_percent 手动点击""",
429
+ inputSchema={"type": "object", "properties": {}, "required": []}
430
+ ))
431
+
386
432
  tools.append(Tool(
387
433
  name="mobile_assert_text",
388
434
  description="✅ 检查页面是否包含指定文本。用于验证操作结果。",
@@ -473,7 +519,9 @@ class MobileMCPServer:
473
519
  arguments.get("image_width", 0),
474
520
  arguments.get("image_height", 0),
475
521
  arguments.get("crop_offset_x", 0),
476
- arguments.get("crop_offset_y", 0)
522
+ arguments.get("crop_offset_y", 0),
523
+ arguments.get("original_img_width", 0),
524
+ arguments.get("original_img_height", 0)
477
525
  )
478
526
  return [TextContent(type="text", text=self.format_response(result))]
479
527
 
@@ -538,6 +586,14 @@ class MobileMCPServer:
538
586
  result = self.tools.list_elements()
539
587
  return [TextContent(type="text", text=self.format_response(result))]
540
588
 
589
+ elif name == "mobile_find_close_button":
590
+ result = self.tools.find_close_button()
591
+ return [TextContent(type="text", text=self.format_response(result))]
592
+
593
+ elif name == "mobile_close_popup":
594
+ result = self.tools.close_popup()
595
+ return [TextContent(type="text", text=self.format_response(result))]
596
+
541
597
  elif name == "mobile_assert_text":
542
598
  result = self.tools.assert_text(arguments["text"])
543
599
  return [TextContent(type="text", text=self.format_response(result))]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobile-mcp-ai
3
- Version: 2.3.5
3
+ Version: 2.4.1
4
4
  Summary: 移动端自动化 MCP Server - 支持 Android/iOS,AI 功能可选(基础工具不需要 AI)
5
5
  Home-page: https://github.com/test111ddff-hash/mobile-mcp-ai
6
6
  Author: douzi
@@ -25,7 +25,7 @@ if requirements_file.exists():
25
25
 
26
26
  setup(
27
27
  name="mobile-mcp-ai",
28
- version="2.3.5", # 新增局部截图功能:精确识别小元素(广告关闭按钮等)
28
+ version="2.4.1", # close_popup改为AI看截图判断是否成功,更智能灵活
29
29
  author="douzi",
30
30
  author_email="1492994674@qq.com",
31
31
  description="移动端自动化 MCP Server - 支持 Android/iOS,AI 功能可选(基础工具不需要 AI)",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes