uiautomator2-mcp-server 0.1.2__py3-none-any.whl → 0.1.3__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/action.py CHANGED
@@ -1,169 +1,169 @@
1
- from __future__ import annotations
2
-
3
- import asyncio
4
-
5
- from ..mcp import mcp
6
- from .device import get_device
7
-
8
- __all__ = (
9
- "click",
10
- "long_click",
11
- "double_click",
12
- "swipe",
13
- "swipe_points",
14
- "drag",
15
- "press_key",
16
- "send_text",
17
- "clear_text",
18
- "screen_on",
19
- "screen_off",
20
- )
21
-
22
-
23
- @mcp.tool("click")
24
- async def click(serial: str, x: int, y: int):
25
- """Click at specific coordinates
26
-
27
- Args:
28
- serial (str): Android device serialno
29
- x (int): X coordinate
30
- y (int): Y coordinate
31
- """
32
- async with get_device(serial) as device:
33
- await asyncio.to_thread(device.click, x, y)
34
-
35
-
36
- @mcp.tool("long_click")
37
- async def long_click(serial: str, x: int, y: int, duration: float = 0.5):
38
- """Long click at specific coordinates
39
-
40
- Args:
41
- serial (str): Android device serialno
42
- x (int): X coordinate
43
- y (int): Y coordinate
44
- duration (float): Duration of the long click in seconds, default is 0.5
45
- """
46
- async with get_device(serial) as device:
47
- await asyncio.to_thread(device.long_click, x, y, duration)
48
-
49
-
50
- @mcp.tool("double_click")
51
- async def double_click(serial: str, x: int, y: int, duration: float = 0.1):
52
- """Double click at specific coordinates
53
-
54
- Args:
55
- serial (str): Android device serialno
56
- x (int): X coordinate
57
- y (int): Y coordinate
58
- duration (float): Duration between clicks in seconds, default is 0.1
59
- """
60
- async with get_device(serial) as device:
61
- await asyncio.to_thread(device.double_click, x, y, duration)
62
-
63
-
64
- @mcp.tool("swipe")
65
- async def swipe(serial: str, fx: int, fy: int, tx: int, ty: int, duration: float = 0.0, step: int = 0):
66
- """Swipe from one point to another
67
-
68
- Args:
69
- serial (str): Android device serialno
70
- fx (int): From position X coordinate
71
- fy (int): From position Y coordinate
72
- tx (int): To position X coordinate
73
- ty (int): To position Y coordinate
74
- duration (float): duration
75
- steps: 1 steps is about 5ms, if set, duration will be ignore
76
- """
77
- async with get_device(serial) as device:
78
- await asyncio.to_thread(device.swipe, fx, fy, tx, ty, duration if duration > 0 else None, step if step > 0 else None)
79
-
80
-
81
- @mcp.tool("swipe_points")
82
- async def swipe_points(serial: str, points: list[tuple[int, int]], duration: float = 0.5):
83
- """Swipe through multiple points
84
-
85
- Args:
86
- serial (str): Android device serialno
87
- points (list[tuple[int, int]]): List of (x, y) coordinates to swipe through
88
- duration (float): Duration of swipe in seconds, default is 0.5
89
- """
90
- async with get_device(serial) as device:
91
- await asyncio.to_thread(device.swipe_points, points, duration)
92
-
93
-
94
- @mcp.tool("drag")
95
- async def drag(serial: str, sx: int, sy: int, ex: int, ey: int, duration: float = 0.5):
96
- """Swipe from one point to another point.
97
-
98
- Args:
99
- serial (str): Android device serialno
100
- sx (int): Start X coordinate
101
- sy (int): Start Y coordinate
102
- ex (int): End X coordinate
103
- ey (int): End Y coordinate
104
- duration (float): Duration of drag in seconds, default is 0.5
105
- """
106
- async with get_device(serial) as device:
107
- await asyncio.to_thread(device.drag, sx, sy, ex, ey, duration)
108
-
109
-
110
- @mcp.tool("press_key")
111
- async def press_key(serial: str, key: str):
112
- """Press a key
113
-
114
- Args:
115
- serial (str): Android device serialno
116
- key (str): Key to press.
117
- Supported key name includes:
118
- home, back, left, right, up, down, center, menu, search, enter,
119
- delete(or del), recent(recent apps), volume_up, volume_down,
120
- volume_mute, camera, power
121
- """
122
- async with get_device(serial) as device:
123
- await asyncio.to_thread(device.press, key)
124
-
125
-
126
- @mcp.tool("send_text")
127
- async def send_text(serial: str, text: str, clear: bool = False):
128
- """Send text to the current input field
129
-
130
- Args:
131
- serial (str): Android device serialno
132
- text (str): input text
133
- clear: clear text before input
134
- """
135
- async with get_device(serial) as device:
136
- await asyncio.to_thread(device.send_keys, text, clear)
137
-
138
-
139
- @mcp.tool("clear_text")
140
- async def clear_text(serial: str):
141
- """Clear text in the current input field
142
-
143
- Args:
144
- serial (str): Android device serialno
145
- """
146
- async with get_device(serial) as device:
147
- await asyncio.to_thread(device.clear_text)
148
-
149
-
150
- @mcp.tool("screen_on")
151
- async def screen_on(serial: str):
152
- """Turn screen on
153
-
154
- Args:
155
- serial (str): Android device serialno
156
- """
157
- async with get_device(serial) as device:
158
- await asyncio.to_thread(device.screen_on)
159
-
160
-
161
- @mcp.tool("screen_off")
162
- async def screen_off(serial: str):
163
- """Turn screen off
164
-
165
- Args:
166
- serial (str): Android device serialno
167
- """
168
- async with get_device(serial) as device:
169
- await asyncio.to_thread(device.screen_off)
1
+ from __future__ import annotations
2
+
3
+ from anyio import to_thread
4
+
5
+ from ..mcp import mcp
6
+ from .device import get_device
7
+
8
+ __all__ = (
9
+ "click",
10
+ "long_click",
11
+ "double_click",
12
+ "swipe",
13
+ "swipe_points",
14
+ "drag",
15
+ "press_key",
16
+ "send_text",
17
+ "clear_text",
18
+ "screen_on",
19
+ "screen_off",
20
+ )
21
+
22
+
23
+ @mcp.tool("click")
24
+ async def click(serial: str, x: int, y: int):
25
+ """Click at specific coordinates
26
+
27
+ Args:
28
+ serial (str): Android device serialno
29
+ x (int): X coordinate
30
+ y (int): Y coordinate
31
+ """
32
+ async with get_device(serial) as device:
33
+ await to_thread.run_sync(device.click, x, y)
34
+
35
+
36
+ @mcp.tool("long_click")
37
+ async def long_click(serial: str, x: int, y: int, duration: float = 0.5):
38
+ """Long click at specific coordinates
39
+
40
+ Args:
41
+ serial (str): Android device serialno
42
+ x (int): X coordinate
43
+ y (int): Y coordinate
44
+ duration (float): Duration of the long click in seconds, default is 0.5
45
+ """
46
+ async with get_device(serial) as device:
47
+ await to_thread.run_sync(device.long_click, x, y, duration)
48
+
49
+
50
+ @mcp.tool("double_click")
51
+ async def double_click(serial: str, x: int, y: int, duration: float = 0.1):
52
+ """Double click at specific coordinates
53
+
54
+ Args:
55
+ serial (str): Android device serialno
56
+ x (int): X coordinate
57
+ y (int): Y coordinate
58
+ duration (float): Duration between clicks in seconds, default is 0.1
59
+ """
60
+ async with get_device(serial) as device:
61
+ await to_thread.run_sync(device.double_click, x, y, duration)
62
+
63
+
64
+ @mcp.tool("swipe")
65
+ async def swipe(serial: str, fx: int, fy: int, tx: int, ty: int, duration: float = 0.0, step: int = 0):
66
+ """Swipe from one point to another
67
+
68
+ Args:
69
+ serial (str): Android device serialno
70
+ fx (int): From position X coordinate
71
+ fy (int): From position Y coordinate
72
+ tx (int): To position X coordinate
73
+ ty (int): To position Y coordinate
74
+ duration (float): duration
75
+ steps: 1 steps is about 5ms, if set, duration will be ignore
76
+ """
77
+ async with get_device(serial) as device:
78
+ await to_thread.run_sync(device.swipe, fx, fy, tx, ty, duration if duration > 0 else None, step if step > 0 else None)
79
+
80
+
81
+ @mcp.tool("swipe_points")
82
+ async def swipe_points(serial: str, points: list[tuple[int, int]], duration: float = 0.5):
83
+ """Swipe through multiple points
84
+
85
+ Args:
86
+ serial (str): Android device serialno
87
+ points (list[tuple[int, int]]): List of (x, y) coordinates to swipe through
88
+ duration (float): Duration of swipe in seconds, default is 0.5
89
+ """
90
+ async with get_device(serial) as device:
91
+ await to_thread.run_sync(device.swipe_points, points, duration)
92
+
93
+
94
+ @mcp.tool("drag")
95
+ async def drag(serial: str, sx: int, sy: int, ex: int, ey: int, duration: float = 0.5):
96
+ """Swipe from one point to another point.
97
+
98
+ Args:
99
+ serial (str): Android device serialno
100
+ sx (int): Start X coordinate
101
+ sy (int): Start Y coordinate
102
+ ex (int): End X coordinate
103
+ ey (int): End Y coordinate
104
+ duration (float): Duration of drag in seconds, default is 0.5
105
+ """
106
+ async with get_device(serial) as device:
107
+ await to_thread.run_sync(device.drag, sx, sy, ex, ey, duration)
108
+
109
+
110
+ @mcp.tool("press_key")
111
+ async def press_key(serial: str, key: str):
112
+ """Press a key
113
+
114
+ Args:
115
+ serial (str): Android device serialno
116
+ key (str): Key to press.
117
+ Supported key name includes:
118
+ home, back, left, right, up, down, center, menu, search, enter,
119
+ delete(or del), recent(recent apps), volume_up, volume_down,
120
+ volume_mute, camera, power
121
+ """
122
+ async with get_device(serial) as device:
123
+ await to_thread.run_sync(device.press, key)
124
+
125
+
126
+ @mcp.tool("send_text")
127
+ async def send_text(serial: str, text: str, clear: bool = False):
128
+ """Send text to the current input field
129
+
130
+ Args:
131
+ serial (str): Android device serialno
132
+ text (str): input text
133
+ clear: clear text before input
134
+ """
135
+ async with get_device(serial) as device:
136
+ await to_thread.run_sync(device.send_keys, text, clear)
137
+
138
+
139
+ @mcp.tool("clear_text")
140
+ async def clear_text(serial: str):
141
+ """Clear text in the current input field
142
+
143
+ Args:
144
+ serial (str): Android device serialno
145
+ """
146
+ async with get_device(serial) as device:
147
+ await to_thread.run_sync(device.clear_text)
148
+
149
+
150
+ @mcp.tool("screen_on")
151
+ async def screen_on(serial: str):
152
+ """Turn screen on
153
+
154
+ Args:
155
+ serial (str): Android device serialno
156
+ """
157
+ async with get_device(serial) as device:
158
+ await to_thread.run_sync(device.screen_on)
159
+
160
+
161
+ @mcp.tool("screen_off")
162
+ async def screen_off(serial: str):
163
+ """Turn screen off
164
+
165
+ Args:
166
+ serial (str): Android device serialno
167
+ """
168
+ async with get_device(serial) as device:
169
+ await to_thread.run_sync(device.screen_off)