mcp-android-emulator 1.4.0 → 2.0.0

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.
package/README.md CHANGED
@@ -1,542 +1,555 @@
1
- # MCP Android Emulator
2
-
3
- [![npm version](https://badge.fury.io/js/mcp-android-emulator.svg)](https://www.npmjs.com/package/mcp-android-emulator)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- A Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Android devices and emulators via ADB (Android Debug Bridge).
7
-
8
- ## Features
9
-
10
- - **Screenshots**: Capture device screen as base64 images
11
- - **UI Inspection**: Get UI hierarchy (like DOM but for Android)
12
- - **Touch Input**: Tap, swipe, scroll, pinch zoom, multi-tap gestures
13
- - **Text Input**: Type, clear, select all, set text in input fields
14
- - **System Keys**: Press BACK, HOME, ENTER, VOLUME, etc.
15
- - **App Management**: Launch, install, force stop, clear data
16
- - **Clipboard**: Get and set clipboard content
17
- - **Device Control**: Rotate screen, get device info
18
- - **Logs**: Access logcat with filters and log levels
19
- - **Wait & Assert**: Wait for elements, UI stability, assertions for testing
20
- - **Safe Interactions**: Tap avoiding system bars, element bounds detection
21
-
22
- ## Requirements
23
-
24
- - Node.js 18+
25
- - ADB (Android Debug Bridge) installed
26
- - One of the following:
27
- - Android Studio Emulator (AVD)
28
- - Redroid (Docker-based Android)
29
- - Genymotion
30
- - Physical Android device via USB/WiFi
31
-
32
- ## Installation
33
-
34
- ### From npm (Recommended)
35
-
36
- ```bash
37
- npm install -g mcp-android-emulator
38
- ```
39
-
40
- ### From source
41
-
42
- ```bash
43
- git clone https://github.com/Anjos2/mcp-android-emulator.git
44
- cd mcp-android-emulator
45
- npm install
46
- npm run build
47
- ```
48
-
49
- ## Quick Start
50
-
51
- ### 1. Ensure ADB is working
52
-
53
- ```bash
54
- adb devices
55
- # Should show your device/emulator
56
- ```
57
-
58
- ### 2. Add to Claude Code
59
-
60
- ```bash
61
- claude mcp add android-emulator -- npx mcp-android-emulator
62
- ```
63
-
64
- ### 3. Start using
65
-
66
- Ask Claude: "Take a screenshot of the Android device"
67
-
68
- ---
69
-
70
- ## Configuration
71
-
72
- ### Environment Variables
73
-
74
- | Variable | Default | Description |
75
- |----------|---------|-------------|
76
- | `ADB_PATH` | `adb` | Path to ADB executable |
77
- | `SCREENSHOT_DIR` | `/tmp/android-screenshots` | Directory for temporary screenshots |
78
-
79
- ### Claude Code Integration
80
-
81
- **Option 1: CLI command**
82
-
83
- ```bash
84
- claude mcp add android-emulator -- npx mcp-android-emulator
85
- ```
86
-
87
- **Option 2: Manual configuration**
88
-
89
- Edit `~/.claude.json`:
90
-
91
- ```json
92
- {
93
- "mcpServers": {
94
- "android-emulator": {
95
- "command": "npx",
96
- "args": ["mcp-android-emulator"],
97
- "env": {
98
- "ADB_PATH": "/path/to/adb"
99
- }
100
- }
101
- }
102
- }
103
- ```
104
-
105
- ### Claude Desktop Integration
106
-
107
- Add to `claude_desktop_config.json`:
108
-
109
- ```json
110
- {
111
- "mcpServers": {
112
- "android-emulator": {
113
- "command": "npx",
114
- "args": ["mcp-android-emulator"],
115
- "env": {
116
- "ADB_PATH": "/path/to/adb"
117
- }
118
- }
119
- }
120
- }
121
- ```
122
-
123
- ---
124
-
125
- ## Available Tools (40 tools)
126
-
127
- ### Screen Capture & UI
128
-
129
- | Tool | Description |
130
- |------|-------------|
131
- | `screenshot` | Capture screen as base64 PNG image |
132
- | `get_ui_tree` | Get UI element hierarchy with coordinates |
133
- | `get_all_text` | Get all visible text elements on screen (for debugging) |
134
- | `get_clickable_elements` | **NEW** Get all clickable elements with text/id/coordinates (useful when tap_text fails) |
135
- | `get_screen_size` | Get screen dimensions and density |
136
- | `get_focused_element` | Get info about currently focused element |
137
- | `is_element_visible` | Check if element is visible on screen |
138
- | `get_element_bounds` | Get exact coordinates of an element |
139
- | `assert_screen_contains` | Assert text is visible (for testing) |
140
-
141
- ### Touch Interactions
142
-
143
- | Tool | Description |
144
- |------|-------------|
145
- | `tap` | Tap at specific coordinates |
146
- | `tap_text` | Find element by text and tap it |
147
- | `tap_element` | Tap element by text or resource-id (more reliable) |
148
- | `tap_safe` | Tap avoiding system navigation bars |
149
- | `double_tap` | Double tap at coordinates |
150
- | `long_press` | Long press for context menus |
151
- | `multi_tap` | Multiple rapid taps at same position |
152
- | `swipe` | Swipe between two points |
153
- | `scroll` | Scroll in a direction (up/down/left/right) |
154
- | `scroll_to_text` | Scroll until text is visible |
155
- | `drag` | Drag gesture for drag & drop |
156
- | `pinch_zoom` | Pinch zoom gesture (zoom in/out) |
157
-
158
- ### Text Input
159
-
160
- | Tool | Description |
161
- |------|-------------|
162
- | `type_text` | Type text into focused input |
163
- | `clear_input` | Clear focused text field |
164
- | `select_all` | Select all text in focused field |
165
- | `set_text` | Clear and type new text (combines both) |
166
- | `get_focused_input_value` | **NEW** Get current text value of focused input |
167
- | `is_keyboard_visible` | **NEW** Check if soft keyboard is currently visible |
168
-
169
- ### System & Keys
170
-
171
- | Tool | Description |
172
- |------|-------------|
173
- | `press_key` | Press system key (BACK, HOME, ENTER, etc.) |
174
- | `rotate_device` | Rotate to portrait or landscape |
175
- | `set_clipboard` | Set text to device clipboard |
176
- | `get_clipboard` | Get clipboard content |
177
-
178
- ### App Management
179
-
180
- | Tool | Description |
181
- |------|-------------|
182
- | `launch_app` | Launch app by package name |
183
- | `install_apk` | Install APK file |
184
- | `list_packages` | List installed packages |
185
- | `clear_app_data` | Clear app data |
186
- | `force_stop` | Force stop an app |
187
- | `get_current_activity` | Get currently focused activity |
188
-
189
- ### Device Info & Logs
190
-
191
- | Tool | Description |
192
- |------|-------------|
193
- | `device_info` | Get device model, Android version, screen size |
194
- | `get_logs` | Get logcat logs with filters and log levels |
195
-
196
- ### Wait & Sync
197
-
198
- | Tool | Description |
199
- |------|-------------|
200
- | `wait_for_element` | Wait for element with text to appear |
201
- | `wait_for_element_gone` | Wait for element to disappear |
202
- | `wait_for_ui_stable` | Wait for UI to stop changing (after animations) |
203
-
204
- ---
205
-
206
- ## Emulator Setup Guides
207
-
208
- ### Option 1: Android Studio Emulator (AVD)
209
-
210
- Best for: Local development on machines with display
211
-
212
- ```bash
213
- # List available AVDs
214
- emulator -list-avds
215
-
216
- # Start emulator
217
- emulator -avd YOUR_AVD_NAME
218
-
219
- # Verify connection
220
- adb devices
221
- ```
222
-
223
- ### Option 2: Redroid (Docker) - Recommended for Servers
224
-
225
- Best for: Headless servers, CI/CD, cloud VPS
226
-
227
- Redroid runs Android in a Docker container without requiring KVM on x86.
228
-
229
- ```bash
230
- # Run Redroid container
231
- docker run -d --name redroid \
232
- --privileged \
233
- -p 5555:5555 \
234
- redroid/redroid:13.0.0-latest \
235
- androidboot.redroid_width=720 \
236
- androidboot.redroid_height=1280 \
237
- androidboot.redroid_dpi=320
238
-
239
- # Connect ADB
240
- adb connect localhost:5555
241
-
242
- # Verify
243
- adb devices
244
- ```
245
-
246
- **For apps using network (React Native, Expo, etc.):**
247
-
248
- ```bash
249
- # Forward ports from device to host
250
- adb reverse tcp:8081 tcp:8081 # Metro bundler
251
- adb reverse tcp:3000 tcp:3000 # API server
252
- ```
253
-
254
- ### Option 3: Genymotion
255
-
256
- Best for: Local development, faster than AVD
257
-
258
- 1. Download from [genymotion.com](https://www.genymotion.com/)
259
- 2. Create and start a virtual device
260
- 3. Enable ADB bridge in settings
261
- 4. Connect: `adb connect localhost:5555`
262
-
263
- ### Option 4: Physical Device
264
-
265
- Best for: Real-world testing
266
-
267
- **USB Connection:**
268
- 1. Enable Developer Options on device
269
- 2. Enable USB Debugging
270
- 3. Connect via USB
271
- 4. Run `adb devices`
272
-
273
- **WiFi Connection:**
274
- ```bash
275
- # First connect via USB, then:
276
- adb tcpip 5555
277
- adb connect DEVICE_IP:5555
278
- # Disconnect USB
279
- ```
280
-
281
- ---
282
-
283
- ## Running on Cloud/VPS Servers
284
-
285
- ### Prerequisites
286
-
287
- - Linux server (Ubuntu 20.04+ recommended)
288
- - Docker installed
289
- - At least 4GB RAM, 2 CPU cores
290
-
291
- ### Step-by-Step Setup
292
-
293
- #### 1. Install ADB
294
-
295
- ```bash
296
- # Ubuntu/Debian
297
- sudo apt update
298
- sudo apt install android-tools-adb
299
-
300
- # Verify
301
- adb version
302
- ```
303
-
304
- #### 2. Run Redroid
305
-
306
- ```bash
307
- docker run -d --name redroid \
308
- --privileged \
309
- -p 5555:5555 \
310
- redroid/redroid:13.0.0-latest \
311
- androidboot.redroid_width=720 \
312
- androidboot.redroid_height=1280 \
313
- androidboot.redroid_dpi=320
314
- ```
315
-
316
- #### 3. Connect ADB
317
-
318
- ```bash
319
- adb connect localhost:5555
320
- adb devices # Should show "localhost:5555 device"
321
- ```
322
-
323
- #### 4. Install Node.js and MCP
324
-
325
- ```bash
326
- # Install Node.js 18+
327
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
328
- sudo apt install -y nodejs
329
-
330
- # Install MCP
331
- npm install -g mcp-android-emulator
332
- ```
333
-
334
- #### 5. Configure Claude Code
335
-
336
- ```bash
337
- claude mcp add android-emulator -- npx mcp-android-emulator
338
- ```
339
-
340
- ### Running AVD Headless (Alternative)
341
-
342
- If you have KVM support:
343
-
344
- ```bash
345
- # Install Android SDK
346
- sudo apt install openjdk-11-jdk
347
- wget https://dl.google.com/android/repository/commandlinetools-linux-latest.zip
348
- # ... setup SDK ...
349
-
350
- # Run emulator headless
351
- emulator -avd YOUR_AVD \
352
- -no-window \
353
- -no-audio \
354
- -no-boot-anim \
355
- -gpu swiftshader_indirect \
356
- -memory 2048 \
357
- -cores 2
358
- ```
359
-
360
- ---
361
-
362
- ## Usage Examples
363
-
364
- Once configured, ask Claude to:
365
-
366
- ```
367
- "Take a screenshot of the Android device"
368
-
369
- "Tap on the Login button"
370
-
371
- "Type 'hello@example.com' in the email field and press Enter"
372
-
373
- "Scroll down until you see 'Submit' and tap it"
374
-
375
- "Launch the Chrome app and navigate to google.com"
376
-
377
- "Get error logs from the last 100 lines"
378
-
379
- "Wait for the loading spinner to disappear, then take a screenshot"
380
-
381
- "Check if 'Welcome' text is visible on screen"
382
-
383
- "Rotate the device to landscape mode"
384
- ```
385
-
386
- ### Automated Testing Example
387
-
388
- ```
389
- "Test the login flow:
390
- 1. Take a screenshot of the initial state
391
- 2. Type 'testuser' in the username field
392
- 3. Type 'password123' in the password field
393
- 4. Tap the Login button
394
- 5. Wait for the UI to stabilize
395
- 6. Assert that 'Dashboard' is visible
396
- 7. Take a final screenshot"
397
- ```
398
-
399
- ---
400
-
401
- ## Troubleshooting
402
-
403
- ### ADB not found
404
-
405
- ```bash
406
- # Check if ADB is installed
407
- which adb
408
-
409
- # If not found, install it
410
- sudo apt install android-tools-adb # Ubuntu/Debian
411
- brew install android-platform-tools # macOS
412
-
413
- # Or set custom path
414
- export ADB_PATH=/path/to/android-sdk/platform-tools/adb
415
- ```
416
-
417
- ### No devices connected
418
-
419
- ```bash
420
- # List devices
421
- adb devices
422
-
423
- # If using Redroid, connect explicitly
424
- adb connect localhost:5555
425
-
426
- # Check if emulator is fully booted
427
- adb shell getprop sys.boot_completed # Should return "1"
428
- ```
429
-
430
- ### Permission denied on screenshots
431
-
432
- ```bash
433
- mkdir -p /tmp/android-screenshots
434
- chmod 755 /tmp/android-screenshots
435
- ```
436
-
437
- ### Redroid container won't start
438
-
439
- ```bash
440
- # Check logs
441
- docker logs redroid
442
-
443
- # Ensure privileged mode
444
- docker run --privileged ...
445
-
446
- # Try different Android version
447
- docker run ... redroid/redroid:11.0.0-latest
448
- ```
449
-
450
- ### Apps can't reach localhost services
451
-
452
- ```bash
453
- # Forward ports from device to host
454
- adb reverse tcp:8081 tcp:8081
455
- adb reverse tcp:3000 tcp:3000
456
-
457
- # Verify
458
- adb reverse --list
459
- ```
460
-
461
- ---
462
-
463
- ## Changelog
464
-
465
- ### v1.4.0 (Latest)
466
- - **New tools:**
467
- - `get_clickable_elements` - Get all clickable elements with text, resource-id, class, and coordinates. Useful when `tap_text` fails to find an element.
468
-
469
- ### v1.3.0
470
- - **New tools:**
471
- - `get_all_text` - Get all visible text elements on screen (useful for debugging)
472
- - `is_keyboard_visible` - Check if soft keyboard is currently visible
473
- - `get_focused_input_value` - Get current text value of focused input field
474
- - **Improvements:**
475
- - `wait_for_ui_stable` - Now uses UI fingerprint instead of raw XML comparison (more reliable)
476
- - `get_current_activity` - Multi-method approach for compatibility with different emulators (AVD, Redroid, Genymotion, etc.)
477
- - `is_keyboard_visible` - Multiple detection methods with fallbacks
478
-
479
- ### v1.2.3
480
- - Updated documentation with comprehensive setup guides
481
- - Added emulator comparison (AVD, Redroid, Genymotion, Physical)
482
- - Added cloud/VPS deployment instructions
483
- - Added troubleshooting section
484
-
485
- ### v1.2.2
486
- - Fixed `set_clipboard` and `get_clipboard` for Redroid/Docker compatibility
487
- - Uses `/data/local/tmp` as fallback path
488
-
489
- ### v1.2.0
490
- - Added 14 new tools:
491
- - `get_screen_size`, `is_element_visible`, `get_element_bounds`
492
- - `scroll_to_text`, `wait_for_ui_stable`, `wait_for_element_gone`
493
- - `multi_tap`, `pinch_zoom`, `tap_safe`, `tap_element`
494
- - `set_clipboard`, `get_clipboard`, `rotate_device`
495
- - `get_focused_element`, `assert_screen_contains`
496
-
497
- ### v1.1.0
498
- - Added `double_tap`, `drag`, `set_text`, `select_all`, `clear_input`
499
-
500
- ### v1.0.0
501
- - Initial release with core functionality
502
-
503
- ---
504
-
505
- ## Development
506
-
507
- ```bash
508
- # Clone repo
509
- git clone https://github.com/Anjos2/mcp-android-emulator.git
510
- cd mcp-android-emulator
511
-
512
- # Install dependencies
513
- npm install
514
-
515
- # Build
516
- npm run build
517
-
518
- # Watch mode for development
519
- npm run dev
520
- ```
521
-
522
- ## License
523
-
524
- MIT License - see [LICENSE](LICENSE) for details.
525
-
526
- ## Contributing
527
-
528
- Contributions are welcome! Please feel free to submit a Pull Request.
529
-
530
- ### Ideas for contributions:
531
- - Support for multiple connected devices
532
- - Screen recording
533
- - File transfer (push/pull)
534
- - Network simulation
535
- - Battery/GPS simulation
536
-
537
- ## Related Projects
538
-
539
- - [Model Context Protocol](https://modelcontextprotocol.io/)
540
- - [Android Debug Bridge (ADB)](https://developer.android.com/tools/adb)
541
- - [Claude Code](https://claude.ai/code)
542
- - [Redroid](https://github.com/remote-android/redroid-doc)
1
+ # MCP Android Emulator
2
+
3
+ [![npm version](https://badge.fury.io/js/mcp-android-emulator.svg)](https://www.npmjs.com/package/mcp-android-emulator)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ A Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Android devices and emulators via ADB (Android Debug Bridge).
7
+
8
+ ## Features
9
+
10
+ - **Screenshots**: Capture device screen as base64 images
11
+ - **UI Inspection**: Get UI hierarchy (like DOM but for Android)
12
+ - **Touch Input**: Tap, swipe, scroll, pinch zoom, multi-tap gestures
13
+ - **Text Input**: Type, clear, select all, set text in input fields
14
+ - **System Keys**: Press BACK, HOME, ENTER, VOLUME, etc.
15
+ - **App Management**: Launch, install, force stop, clear data
16
+ - **Clipboard**: Get and set clipboard content
17
+ - **Device Control**: Rotate screen, get device info
18
+ - **Logs**: Access logcat with filters and log levels
19
+ - **Wait & Assert**: Wait for elements, UI stability, assertions for testing
20
+ - **Safe Interactions**: Tap avoiding system bars, element bounds detection
21
+
22
+ ## Requirements
23
+
24
+ - Node.js 18+
25
+ - ADB (Android Debug Bridge) installed
26
+ - One of the following:
27
+ - Android Studio Emulator (AVD)
28
+ - Redroid (Docker-based Android)
29
+ - Genymotion
30
+ - Physical Android device via USB/WiFi
31
+
32
+ ## Installation
33
+
34
+ ### From npm (Recommended)
35
+
36
+ ```bash
37
+ npm install -g mcp-android-emulator
38
+ ```
39
+
40
+ ### From source
41
+
42
+ ```bash
43
+ git clone https://github.com/Anjos2/mcp-android-emulator.git
44
+ cd mcp-android-emulator
45
+ npm install
46
+ npm run build
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### 1. Ensure ADB is working
52
+
53
+ ```bash
54
+ adb devices
55
+ # Should show your device/emulator
56
+ ```
57
+
58
+ ### 2. Add to Claude Code
59
+
60
+ ```bash
61
+ claude mcp add android-emulator -- npx mcp-android-emulator
62
+ ```
63
+
64
+ ### 3. Start using
65
+
66
+ Ask Claude: "Take a screenshot of the Android device"
67
+
68
+ ---
69
+
70
+ ## Configuration
71
+
72
+ ### Environment Variables
73
+
74
+ | Variable | Default | Description |
75
+ |----------|---------|-------------|
76
+ | `ADB_PATH` | `adb` | Path to ADB executable |
77
+ | `SCREENSHOT_DIR` | `/tmp/android-screenshots` | Directory for temporary screenshots |
78
+
79
+ ### Claude Code Integration
80
+
81
+ **Option 1: CLI command**
82
+
83
+ ```bash
84
+ claude mcp add android-emulator -- npx mcp-android-emulator
85
+ ```
86
+
87
+ **Option 2: Manual configuration**
88
+
89
+ Edit `~/.claude.json`:
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "android-emulator": {
95
+ "command": "npx",
96
+ "args": ["mcp-android-emulator"],
97
+ "env": {
98
+ "ADB_PATH": "/path/to/adb"
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### Claude Desktop Integration
106
+
107
+ Add to `claude_desktop_config.json`:
108
+
109
+ ```json
110
+ {
111
+ "mcpServers": {
112
+ "android-emulator": {
113
+ "command": "npx",
114
+ "args": ["mcp-android-emulator"],
115
+ "env": {
116
+ "ADB_PATH": "/path/to/adb"
117
+ }
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Available Tools (40 tools)
126
+
127
+ ### Screen Capture & UI
128
+
129
+ | Tool | Description |
130
+ |------|-------------|
131
+ | `screenshot` | Capture screen as base64 PNG image |
132
+ | `get_ui_tree` | Get UI element hierarchy with coordinates |
133
+ | `get_all_text` | Get all visible text elements on screen (for debugging) |
134
+ | `get_clickable_elements` | **NEW** Get all clickable elements with text/id/coordinates (useful when tap_text fails) |
135
+ | `get_screen_size` | Get screen dimensions and density |
136
+ | `get_focused_element` | Get info about currently focused element |
137
+ | `is_element_visible` | Check if element is visible on screen |
138
+ | `get_element_bounds` | Get exact coordinates of an element |
139
+ | `assert_screen_contains` | Assert text is visible (for testing) |
140
+
141
+ ### Touch Interactions
142
+
143
+ | Tool | Description |
144
+ |------|-------------|
145
+ | `tap` | Tap at specific coordinates |
146
+ | `tap_text` | Find element by text and tap it |
147
+ | `tap_element` | Tap element by text or resource-id (more reliable) |
148
+ | `tap_safe` | Tap avoiding system navigation bars |
149
+ | `double_tap` | Double tap at coordinates |
150
+ | `long_press` | Long press for context menus |
151
+ | `multi_tap` | Multiple rapid taps at same position |
152
+ | `swipe` | Swipe between two points |
153
+ | `scroll` | Scroll in a direction (up/down/left/right) |
154
+ | `scroll_to_text` | Scroll until text is visible |
155
+ | `drag` | Drag gesture for drag & drop |
156
+ | `pinch_zoom` | Pinch zoom gesture (zoom in/out) |
157
+
158
+ ### Text Input
159
+
160
+ | Tool | Description |
161
+ |------|-------------|
162
+ | `type_text` | Type text into focused input |
163
+ | `clear_input` | Clear focused text field |
164
+ | `select_all` | Select all text in focused field |
165
+ | `set_text` | Clear and type new text (combines both) |
166
+ | `get_focused_input_value` | **NEW** Get current text value of focused input |
167
+ | `is_keyboard_visible` | **NEW** Check if soft keyboard is currently visible |
168
+
169
+ ### System & Keys
170
+
171
+ | Tool | Description |
172
+ |------|-------------|
173
+ | `press_key` | Press system key (BACK, HOME, ENTER, etc.) |
174
+ | `rotate_device` | Rotate to portrait or landscape |
175
+ | `set_clipboard` | Set text to device clipboard |
176
+ | `get_clipboard` | Get clipboard content |
177
+
178
+ ### App Management
179
+
180
+ | Tool | Description |
181
+ |------|-------------|
182
+ | `launch_app` | Launch app by package name |
183
+ | `install_apk` | Install APK file |
184
+ | `list_packages` | List installed packages |
185
+ | `clear_app_data` | Clear app data |
186
+ | `force_stop` | Force stop an app |
187
+ | `get_current_activity` | Get currently focused activity |
188
+
189
+ ### Device Info & Logs
190
+
191
+ | Tool | Description |
192
+ |------|-------------|
193
+ | `device_info` | Get device model, Android version, screen size |
194
+ | `get_logs` | Get logcat logs with filters and log levels |
195
+
196
+ ### Wait & Sync
197
+
198
+ | Tool | Description |
199
+ |------|-------------|
200
+ | `wait_for_element` | Wait for element with text to appear |
201
+ | `wait_for_element_gone` | Wait for element to disappear |
202
+ | `wait_for_ui_stable` | Wait for UI to stop changing (after animations) |
203
+
204
+ ---
205
+
206
+ ## Emulator Setup Guides
207
+
208
+ ### Option 1: Android Studio Emulator (AVD)
209
+
210
+ Best for: Local development on machines with display
211
+
212
+ ```bash
213
+ # List available AVDs
214
+ emulator -list-avds
215
+
216
+ # Start emulator
217
+ emulator -avd YOUR_AVD_NAME
218
+
219
+ # Verify connection
220
+ adb devices
221
+ ```
222
+
223
+ ### Option 2: Redroid (Docker) - Recommended for Servers
224
+
225
+ Best for: Headless servers, CI/CD, cloud VPS
226
+
227
+ Redroid runs Android in a Docker container without requiring KVM on x86.
228
+
229
+ ```bash
230
+ # Run Redroid container
231
+ docker run -d --name redroid \
232
+ --privileged \
233
+ -p 5555:5555 \
234
+ redroid/redroid:13.0.0-latest \
235
+ androidboot.redroid_width=720 \
236
+ androidboot.redroid_height=1280 \
237
+ androidboot.redroid_dpi=320
238
+
239
+ # Connect ADB
240
+ adb connect localhost:5555
241
+
242
+ # Verify
243
+ adb devices
244
+ ```
245
+
246
+ **For apps using network (React Native, Expo, etc.):**
247
+
248
+ ```bash
249
+ # Forward ports from device to host
250
+ adb reverse tcp:8081 tcp:8081 # Metro bundler
251
+ adb reverse tcp:3000 tcp:3000 # API server
252
+ ```
253
+
254
+ ### Option 3: Genymotion
255
+
256
+ Best for: Local development, faster than AVD
257
+
258
+ 1. Download from [genymotion.com](https://www.genymotion.com/)
259
+ 2. Create and start a virtual device
260
+ 3. Enable ADB bridge in settings
261
+ 4. Connect: `adb connect localhost:5555`
262
+
263
+ ### Option 4: Physical Device
264
+
265
+ Best for: Real-world testing
266
+
267
+ **USB Connection:**
268
+ 1. Enable Developer Options on device
269
+ 2. Enable USB Debugging
270
+ 3. Connect via USB
271
+ 4. Run `adb devices`
272
+
273
+ **WiFi Connection:**
274
+ ```bash
275
+ # First connect via USB, then:
276
+ adb tcpip 5555
277
+ adb connect DEVICE_IP:5555
278
+ # Disconnect USB
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Running on Cloud/VPS Servers
284
+
285
+ ### Prerequisites
286
+
287
+ - Linux server (Ubuntu 20.04+ recommended)
288
+ - Docker installed
289
+ - At least 4GB RAM, 2 CPU cores
290
+
291
+ ### Step-by-Step Setup
292
+
293
+ #### 1. Install ADB
294
+
295
+ ```bash
296
+ # Ubuntu/Debian
297
+ sudo apt update
298
+ sudo apt install android-tools-adb
299
+
300
+ # Verify
301
+ adb version
302
+ ```
303
+
304
+ #### 2. Run Redroid
305
+
306
+ ```bash
307
+ docker run -d --name redroid \
308
+ --privileged \
309
+ -p 5555:5555 \
310
+ redroid/redroid:13.0.0-latest \
311
+ androidboot.redroid_width=720 \
312
+ androidboot.redroid_height=1280 \
313
+ androidboot.redroid_dpi=320
314
+ ```
315
+
316
+ #### 3. Connect ADB
317
+
318
+ ```bash
319
+ adb connect localhost:5555
320
+ adb devices # Should show "localhost:5555 device"
321
+ ```
322
+
323
+ #### 4. Install Node.js and MCP
324
+
325
+ ```bash
326
+ # Install Node.js 18+
327
+ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
328
+ sudo apt install -y nodejs
329
+
330
+ # Install MCP
331
+ npm install -g mcp-android-emulator
332
+ ```
333
+
334
+ #### 5. Configure Claude Code
335
+
336
+ ```bash
337
+ claude mcp add android-emulator -- npx mcp-android-emulator
338
+ ```
339
+
340
+ ### Running AVD Headless (Alternative)
341
+
342
+ If you have KVM support:
343
+
344
+ ```bash
345
+ # Install Android SDK
346
+ sudo apt install openjdk-11-jdk
347
+ wget https://dl.google.com/android/repository/commandlinetools-linux-latest.zip
348
+ # ... setup SDK ...
349
+
350
+ # Run emulator headless
351
+ emulator -avd YOUR_AVD \
352
+ -no-window \
353
+ -no-audio \
354
+ -no-boot-anim \
355
+ -gpu swiftshader_indirect \
356
+ -memory 2048 \
357
+ -cores 2
358
+ ```
359
+
360
+ ---
361
+
362
+ ## Usage Examples
363
+
364
+ Once configured, ask Claude to:
365
+
366
+ ```
367
+ "Take a screenshot of the Android device"
368
+
369
+ "Tap on the Login button"
370
+
371
+ "Type 'hello@example.com' in the email field and press Enter"
372
+
373
+ "Scroll down until you see 'Submit' and tap it"
374
+
375
+ "Launch the Chrome app and navigate to google.com"
376
+
377
+ "Get error logs from the last 100 lines"
378
+
379
+ "Wait for the loading spinner to disappear, then take a screenshot"
380
+
381
+ "Check if 'Welcome' text is visible on screen"
382
+
383
+ "Rotate the device to landscape mode"
384
+ ```
385
+
386
+ ### Automated Testing Example
387
+
388
+ ```
389
+ "Test the login flow:
390
+ 1. Take a screenshot of the initial state
391
+ 2. Type 'testuser' in the username field
392
+ 3. Type 'password123' in the password field
393
+ 4. Tap the Login button
394
+ 5. Wait for the UI to stabilize
395
+ 6. Assert that 'Dashboard' is visible
396
+ 7. Take a final screenshot"
397
+ ```
398
+
399
+ ---
400
+
401
+ ## Troubleshooting
402
+
403
+ ### ADB not found
404
+
405
+ ```bash
406
+ # Check if ADB is installed
407
+ which adb
408
+
409
+ # If not found, install it
410
+ sudo apt install android-tools-adb # Ubuntu/Debian
411
+ brew install android-platform-tools # macOS
412
+
413
+ # Or set custom path
414
+ export ADB_PATH=/path/to/android-sdk/platform-tools/adb
415
+ ```
416
+
417
+ ### No devices connected
418
+
419
+ ```bash
420
+ # List devices
421
+ adb devices
422
+
423
+ # If using Redroid, connect explicitly
424
+ adb connect localhost:5555
425
+
426
+ # Check if emulator is fully booted
427
+ adb shell getprop sys.boot_completed # Should return "1"
428
+ ```
429
+
430
+ ### Permission denied on screenshots
431
+
432
+ ```bash
433
+ mkdir -p /tmp/android-screenshots
434
+ chmod 755 /tmp/android-screenshots
435
+ ```
436
+
437
+ ### Redroid container won't start
438
+
439
+ ```bash
440
+ # Check logs
441
+ docker logs redroid
442
+
443
+ # Ensure privileged mode
444
+ docker run --privileged ...
445
+
446
+ # Try different Android version
447
+ docker run ... redroid/redroid:11.0.0-latest
448
+ ```
449
+
450
+ ### Apps can't reach localhost services
451
+
452
+ ```bash
453
+ # Forward ports from device to host
454
+ adb reverse tcp:8081 tcp:8081
455
+ adb reverse tcp:3000 tcp:3000
456
+
457
+ # Verify
458
+ adb reverse --list
459
+ ```
460
+
461
+ ---
462
+
463
+ ## Changelog
464
+
465
+ See [CHANGELOG.md](CHANGELOG.md) for the full history.
466
+
467
+ ### v2.0.0 (Latest) Security release
468
+
469
+ - **Eliminated command injection across the MCP tool surface** (issue #1).
470
+ The ADB execution layer was rebuilt on `child_process.execFile`, and every
471
+ LLM-controlled input now passes through strict zod allowlists before reaching
472
+ the device shell.
473
+ - Dependencies pinned to exact versions (`npm audit` clean).
474
+ - New `SECURITY.md` with responsible disclosure policy.
475
+ - **Breaking:** stricter allowlists reject some inputs previously accepted.
476
+ See [CHANGELOG.md](CHANGELOG.md#200--2026-04-19) for migration notes.
477
+
478
+ ### v1.4.0
479
+ - **New tools:**
480
+ - `get_clickable_elements` - Get all clickable elements with text, resource-id, class, and coordinates. Useful when `tap_text` fails to find an element.
481
+
482
+ ### v1.3.0
483
+ - **New tools:**
484
+ - `get_all_text` - Get all visible text elements on screen (useful for debugging)
485
+ - `is_keyboard_visible` - Check if soft keyboard is currently visible
486
+ - `get_focused_input_value` - Get current text value of focused input field
487
+ - **Improvements:**
488
+ - `wait_for_ui_stable` - Now uses UI fingerprint instead of raw XML comparison (more reliable)
489
+ - `get_current_activity` - Multi-method approach for compatibility with different emulators (AVD, Redroid, Genymotion, etc.)
490
+ - `is_keyboard_visible` - Multiple detection methods with fallbacks
491
+
492
+ ### v1.2.3
493
+ - Updated documentation with comprehensive setup guides
494
+ - Added emulator comparison (AVD, Redroid, Genymotion, Physical)
495
+ - Added cloud/VPS deployment instructions
496
+ - Added troubleshooting section
497
+
498
+ ### v1.2.2
499
+ - Fixed `set_clipboard` and `get_clipboard` for Redroid/Docker compatibility
500
+ - Uses `/data/local/tmp` as fallback path
501
+
502
+ ### v1.2.0
503
+ - Added 14 new tools:
504
+ - `get_screen_size`, `is_element_visible`, `get_element_bounds`
505
+ - `scroll_to_text`, `wait_for_ui_stable`, `wait_for_element_gone`
506
+ - `multi_tap`, `pinch_zoom`, `tap_safe`, `tap_element`
507
+ - `set_clipboard`, `get_clipboard`, `rotate_device`
508
+ - `get_focused_element`, `assert_screen_contains`
509
+
510
+ ### v1.1.0
511
+ - Added `double_tap`, `drag`, `set_text`, `select_all`, `clear_input`
512
+
513
+ ### v1.0.0
514
+ - Initial release with core functionality
515
+
516
+ ---
517
+
518
+ ## Development
519
+
520
+ ```bash
521
+ # Clone repo
522
+ git clone https://github.com/Anjos2/mcp-android-emulator.git
523
+ cd mcp-android-emulator
524
+
525
+ # Install dependencies
526
+ npm install
527
+
528
+ # Build
529
+ npm run build
530
+
531
+ # Watch mode for development
532
+ npm run dev
533
+ ```
534
+
535
+ ## License
536
+
537
+ MIT License - see [LICENSE](LICENSE) for details.
538
+
539
+ ## Contributing
540
+
541
+ Contributions are welcome! Please feel free to submit a Pull Request.
542
+
543
+ ### Ideas for contributions:
544
+ - Support for multiple connected devices
545
+ - Screen recording
546
+ - File transfer (push/pull)
547
+ - Network simulation
548
+ - Battery/GPS simulation
549
+
550
+ ## Related Projects
551
+
552
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
553
+ - [Android Debug Bridge (ADB)](https://developer.android.com/tools/adb)
554
+ - [Claude Code](https://claude.ai/code)
555
+ - [Redroid](https://github.com/remote-android/redroid-doc)