uiautomator2-mcp-server 0.1.0__py3-none-any.whl → 0.1.1__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.
u2mcp/tools/device.py CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import asyncio
4
4
  import sys
5
5
  from base64 import b64encode
6
+ from collections.abc import AsyncGenerator
6
7
  from contextlib import asynccontextmanager
7
8
  from io import BytesIO
8
9
  from typing import Any, Literal
@@ -36,7 +37,7 @@ _device_connect_lock = asyncio.Lock()
36
37
 
37
38
 
38
39
  @asynccontextmanager
39
- async def get_device(serial: str):
40
+ async def get_device(serial: str) -> AsyncGenerator[u2.Device]:
40
41
  async with _device_connect_lock:
41
42
  try:
42
43
  semaphore, device = _devices[serial]
@@ -156,10 +157,10 @@ async def connect(serial: str = ""):
156
157
 
157
158
  if serial := serial.strip():
158
159
  try:
159
- async with get_device(serial) as device:
160
+ async with get_device(serial) as device_1:
160
161
  # Found, then check if it's still connected
161
162
  try:
162
- return await asyncio.to_thread(lambda: device.device_info | device.info)
163
+ return await asyncio.to_thread(lambda: device_1.device_info | device_1.info)
163
164
  except u2.ConnectError as e:
164
165
  # Found, but not connected, delete it
165
166
  logger.warning("Device %s is no longer connected, delete it!", serial)
@@ -172,6 +173,8 @@ async def connect(serial: str = ""):
172
173
  # make new connection here!
173
174
  async with _device_connect_lock:
174
175
  device = await asyncio.to_thread(u2.connect, serial)
176
+ if device is None:
177
+ raise RuntimeError("Cannot connect to device")
175
178
  logger.info("Connected to device %s", device.serial)
176
179
  result = await asyncio.to_thread(lambda: device.device_info | device.info)
177
180
  _devices[device.serial] = asyncio.Semaphore(), device
@@ -287,4 +290,3 @@ async def info(serial: str) -> dict[str, Any]:
287
290
 
288
291
  async with get_device(serial) as device:
289
292
  return await asyncio.to_thread(lambda: device.info)
290
-
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: uiautomator2-mcp-server
3
+ Version: 0.1.1
4
+ Summary: uiautomator2 mcp server
5
+ Author: tanbro
6
+ License: GPL-3.0-or-later
7
+ Project-URL: homepage, https://github.com/tanbro/uiautomator2-mcp-server
8
+ Project-URL: documentation, https://github.com/tanbro/uiautomator2-mcp-server/blob/main/README.md
9
+ Project-URL: repository, https://github.com/tanbro/uiautomator2-mcp-server.git
10
+ Project-URL: issues, https://github.com/tanbro/uiautomator2-mcp-server/issues
11
+ Project-URL: changelog, https://github.com/tanbro/uiautomator2-mcp-server/blob/main/CHANGELOG.md
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: fastmcp<3.0,>=2.10
16
+ Requires-Dist: uiautomator2<4.0,>=3.5
17
+ Dynamic: license-file
18
+
19
+ # uiautomator2-mcp-server
20
+
21
+ ![GitHub Tag](https://img.shields.io/github/v/tag/tanbro/uiautomator2-mcp-server)
22
+ ![PyPI - Version](https://img.shields.io/pypi/v/uiautomator2-mcp-server)
23
+
24
+ A MCP (Model Context Protocol) server that provides tools for controlling and interacting with Android devices using uiautomator2. This server allows you to perform various operations on Android devices such as connecting to devices, taking screenshots, getting device information, accessing UI hierarchy, tap on screens, and more.
25
+
26
+ ## Features
27
+
28
+ - **Device Management**: List connected devices, initialize devices, connect/disconnect from devices
29
+ - **Screen Operations**: Take screenshots, get device window size, dump UI hierarchy
30
+ - **Touch Actions**: Click, long click, double click at specific coordinates
31
+ - **Gesture Controls**: Swipe, swipe through multiple points, drag operations
32
+ - **System Controls**: Screen on/off, key presses
33
+ - **App Management**: Install, uninstall, start, stop, clear, and manage Android applications
34
+ - **Text Operations**: Send text input, clear text fields
35
+
36
+ ## Requirements
37
+
38
+ - Python >= 3.11
39
+ - Android device with ADB access
40
+ - Android device with uiautomator2 resources installed
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ # Install the package
46
+ pip install uiautomator2-mcp-server
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ### Running the Server
52
+
53
+ The server can be run in different transport modes:
54
+
55
+ ```bash
56
+ # Run in streamable HTTP mode
57
+ u2mcp --http --host 0.0.0.0 --port 8000
58
+
59
+ # Run in stdio mode
60
+ u2mcp --stdio
61
+ ```
62
+
63
+ ### Using the Tools
64
+
65
+ Connect it to any tool that supports MCP protocol.
66
+
67
+ ## Available Tools
68
+
69
+ ### Device Management
70
+ - `device_list`: Get list of connected devices
71
+ - `init`: Install essential resources to device
72
+ - `connect`, `disconnect`, `disconnect_all`: Manage device connections
73
+ - `info`: Get device information
74
+ - `window_size`: Get device window size
75
+ - `screenshot`: Take device screenshot
76
+ - `dump_hierarchy`: Get UI hierarchy of device
77
+
78
+ ### Action Tools
79
+ - `click`: Click at specific coordinates
80
+ - `long_click`: Long click at specific coordinates
81
+ - `double_click`: Double click at specific coordinates
82
+ - `swipe`: Swipe from one point to another
83
+ - `swipe_points`: Swipe through multiple points
84
+ - `drag`: Drag from one point to another
85
+ - `press_key`: Press device key
86
+ - `send_text`: Send text to device
87
+ - `clear_text`: Clear text input
88
+ - `screen_on`/`screen_off`: Control screen state
89
+
90
+ ### App Management
91
+ - `app_install`: Install an app
92
+ - `app_uninstall`: Uninstall an app
93
+ - `app_uninstall_all`: Uninstall all apps
94
+ - `app_start`: Start an app
95
+ - `app_stop`: Stop an app
96
+ - `app_stop_all`: Stop all apps
97
+ - `app_clear`: Clear app data
98
+ - `app_info`: Get app information
99
+ - `app_current`: Get current app
100
+ - `app_list`: List installed apps
101
+ - `app_list_running`: List running apps
102
+ - `app_auto_grant_permissions`: Auto grant permissions
103
+
104
+ ## License
105
+
106
+ This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
@@ -0,0 +1,16 @@
1
+ u2mcp/.gitignore,sha256=mr9Izcwvjgv215xjRKhWEZ7vsyrKWhMqvWjSLHRYDjk,13
2
+ u2mcp/__init__.py,sha256=xsioVkbaN9sg-us_kNMeH-DojD8xM-h6Nlhde6uRHCQ,104
3
+ u2mcp/__main__.py,sha256=I5ON-vrBr8rGWblondFcP2HhuQKhDPLn1y40YYjCWng,1943
4
+ u2mcp/_version.py,sha256=qS3Rb8IU851vIlLXMW4dseE1Fx3Ssytyif_1QTy34YM,738
5
+ u2mcp/mcp.py,sha256=JSNkfVviZqeh-Io48STjRuI9jJYcw7eo-o80z6zOSQs,739
6
+ u2mcp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ u2mcp/tools/__init__.py,sha256=tKfsoF6tYQSapfGC1ybEcU4S77cipyfO5tYR6u0eAlI,66
8
+ u2mcp/tools/action.py,sha256=A9dCED1NiKOJpw9lBewOQ9YQvfGOkK8bEL1L9FLjCQg,5088
9
+ u2mcp/tools/app.py,sha256=b-cOdDtjSKC8KeUK5TTJCPRXtzvwSH74P02Cm3mS-ck,6809
10
+ u2mcp/tools/device.py,sha256=yN1mWMJeIh6cMQA3m5HE3VqAkaIJOyfNIuNgWn-xoSU,9242
11
+ uiautomator2_mcp_server-0.1.1.dist-info/licenses/LICENSE,sha256=ea2KuPdrBJ0Dhw1ncbc7siZDKG4cz2z-_8cSQiu4n1g,33122
12
+ uiautomator2_mcp_server-0.1.1.dist-info/METADATA,sha256=yw6XCj9zVj2jS108gHaCCZtQl3bOptakor8NpYO-tEg,3761
13
+ uiautomator2_mcp_server-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ uiautomator2_mcp_server-0.1.1.dist-info/entry_points.txt,sha256=y7lg94G2U5_VgrDtyY8-Ne4ZClFtHo6eAs3RnShuDSI,92
15
+ uiautomator2_mcp_server-0.1.1.dist-info/top_level.txt,sha256=elTNF05b2GS8jjS4Haa3ESnG6xbfRjpyoSRsivT0Uks,6
16
+ uiautomator2_mcp_server-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -1,3 +1,3 @@
1
1
  [console_scripts]
2
2
  u2mcp = u2mcp.__main__:main
3
-
3
+ uiautomator2-mcp-server = u2mcp.__main__:main