mobile-mcp-ai 2.5.2__py3-none-any.whl → 2.5.4__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.
@@ -89,6 +89,7 @@ class MobileMCPServer:
89
89
  self.client = None
90
90
  self.tools = None
91
91
  self._initialized = False
92
+ self._last_error = None # 保存最后一次连接失败的错误
92
93
 
93
94
  @staticmethod
94
95
  def format_response(result) -> str:
@@ -99,9 +100,17 @@ class MobileMCPServer:
99
100
 
100
101
  async def initialize(self):
101
102
  """延迟初始化设备连接"""
102
- # 如果已成功初始化,直接返回
103
+ # 如果已成功初始化,检查连接是否仍然有效
103
104
  if self._initialized and self.tools is not None:
104
- return
105
+ # 验证设备连接是否仍然有效
106
+ if self._is_connection_valid():
107
+ return
108
+ else:
109
+ # 连接已失效,重置状态
110
+ print("⚠️ 检测到设备连接已断开,正在重新连接...", file=sys.stderr)
111
+ self._initialized = False
112
+ self.client = None
113
+ self.tools = None
105
114
 
106
115
  platform = self._detect_platform()
107
116
 
@@ -114,11 +123,40 @@ class MobileMCPServer:
114
123
  self._initialized = True # 只在成功时标记
115
124
  print(f"📱 已连接到 {platform.upper()} 设备", file=sys.stderr)
116
125
  except Exception as e:
117
- print(f"⚠️ 设备连接失败: {e},下次调用时将重试", file=sys.stderr)
126
+ error_msg = str(e)
127
+ print(f"⚠️ 设备连接失败: {error_msg},下次调用时将重试", file=sys.stderr)
118
128
  self.client = None
119
129
  self.tools = None
130
+ self._last_error = error_msg # 保存错误信息
120
131
  # 不设置 _initialized = True,下次调用会重试
121
132
 
133
+ def _is_connection_valid(self) -> bool:
134
+ """检查设备连接是否仍然有效"""
135
+ try:
136
+ if self.client is None:
137
+ return False
138
+
139
+ # Android: 检查 u2 连接
140
+ if hasattr(self.client, 'u2') and self.client.u2:
141
+ # 尝试获取设备信息,如果失败说明连接断开
142
+ self.client.u2.info
143
+ return True
144
+
145
+ # iOS: 检查 wda 连接
146
+ if hasattr(self.client, 'wda') and self.client.wda:
147
+ self.client.wda.status()
148
+ return True
149
+
150
+ # iOS (通过 _ios_client)
151
+ if hasattr(self.client, '_ios_client') and self.client._ios_client:
152
+ if hasattr(self.client._ios_client, 'wda') and self.client._ios_client.wda:
153
+ self.client._ios_client.wda.status()
154
+ return True
155
+
156
+ return False
157
+ except Exception:
158
+ return False
159
+
122
160
  def _detect_platform(self) -> str:
123
161
  """自动检测设备平台"""
124
162
  platform = os.getenv("MOBILE_PLATFORM", "").lower()
@@ -722,7 +760,20 @@ class MobileMCPServer:
722
760
  await self.initialize()
723
761
 
724
762
  if not self.tools:
725
- return [TextContent(type="text", text="❌ 设备未连接,请检查连接状态")]
763
+ # 提供详细的错误信息和解决方案
764
+ error_detail = self._last_error or "未知错误"
765
+ help_msg = (
766
+ f"❌ 设备连接失败\n\n"
767
+ f"错误详情: {error_detail}\n\n"
768
+ f"🔧 解决方案:\n"
769
+ f"1. 检查 USB 连接: adb devices\n"
770
+ f"2. 重启 adb: adb kill-server && adb start-server\n"
771
+ f"3. 初始化 uiautomator2: python -m uiautomator2 init\n"
772
+ f"4. 手机上允许 USB 调试授权\n"
773
+ f"5. 确保手机已解锁\n\n"
774
+ f"完成后请重试操作。"
775
+ )
776
+ return [TextContent(type="text", text=help_msg)]
726
777
 
727
778
  try:
728
779
  # 截图
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobile-mcp-ai
3
- Version: 2.5.2
3
+ Version: 2.5.4
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
@@ -19,14 +19,14 @@ mobile_mcp/core/utils/logger.py,sha256=XXQAHUwT1jc70pq_tYFmL6f_nKrFlYm3hcgl-5RYR
19
19
  mobile_mcp/core/utils/operation_history_manager.py,sha256=gi8S8HJAMqvkUrY7_-kVbko3Xt7c4GAUziEujRd-N-Y,4792
20
20
  mobile_mcp/core/utils/smart_wait.py,sha256=PvKXImfN9Irru3bQJUjf4FLGn8LjY2VLzUNEl-i7xLE,8601
21
21
  mobile_mcp/mcp_tools/__init__.py,sha256=xkro8Rwqv_55YlVyhh-3DgRFSsLE3h1r31VIb3bpM6E,143
22
- mobile_mcp/mcp_tools/mcp_server.py,sha256=K53DSxKGT3B_f6mqaoTID2th5luBtwlh5MjoUDGbhl0,45263
22
+ mobile_mcp/mcp_tools/mcp_server.py,sha256=wqNOkjWYxxPYTAjU8e8yn8EyeRtO9NMhPTqGZ18jfnM,47471
23
23
  mobile_mcp/utils/__init__.py,sha256=8EH0i7UGtx1y_j_GEgdN-cZdWn2sRtZSEOLlNF9HRnY,158
24
24
  mobile_mcp/utils/logger.py,sha256=Sqq2Nr0Y4p03erqcrbYKVPCGiFaNGHMcE_JwCkeOfU4,3626
25
25
  mobile_mcp/utils/xml_formatter.py,sha256=uwTRb3vLbqhT8O-udzWT7s7LsV-DyDUz2DkofD3hXOE,4556
26
26
  mobile_mcp/utils/xml_parser.py,sha256=QhL8CWbdmNDzmBLjtx6mEnjHgMFZzJeHpCL15qfXSpI,3926
27
- mobile_mcp_ai-2.5.2.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
28
- mobile_mcp_ai-2.5.2.dist-info/METADATA,sha256=fqKamhjV66KFBFvcfGrfHYFKb-zB75P8-mqEVuhDlSI,9745
29
- mobile_mcp_ai-2.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- mobile_mcp_ai-2.5.2.dist-info/entry_points.txt,sha256=KB_FglozgPHBprSM1vFbIzGyheFuHFmGanscRdMJ_8A,68
31
- mobile_mcp_ai-2.5.2.dist-info/top_level.txt,sha256=lLm6YpbTv855Lbh8BIA0rPxhybIrvYUzMEk9OErHT94,11
32
- mobile_mcp_ai-2.5.2.dist-info/RECORD,,
27
+ mobile_mcp_ai-2.5.4.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
28
+ mobile_mcp_ai-2.5.4.dist-info/METADATA,sha256=EUiIZ3uxIiyK-P9Sf558k8nu6dAWnl1U6mcjBby0Lso,9745
29
+ mobile_mcp_ai-2.5.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
+ mobile_mcp_ai-2.5.4.dist-info/entry_points.txt,sha256=KB_FglozgPHBprSM1vFbIzGyheFuHFmGanscRdMJ_8A,68
31
+ mobile_mcp_ai-2.5.4.dist-info/top_level.txt,sha256=lLm6YpbTv855Lbh8BIA0rPxhybIrvYUzMEk9OErHT94,11
32
+ mobile_mcp_ai-2.5.4.dist-info/RECORD,,