mcp-android-emulator 1.3.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,524 +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 (36 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_screen_size` | Get screen dimensions and density |
134
- | `get_focused_element` | Get info about currently focused element |
135
- | `is_element_visible` | Check if element is visible on screen |
136
- | `get_element_bounds` | Get exact coordinates of an element |
137
- | `assert_screen_contains` | Assert text is visible (for testing) |
138
-
139
- ### Touch Interactions
140
-
141
- | Tool | Description |
142
- |------|-------------|
143
- | `tap` | Tap at specific coordinates |
144
- | `tap_text` | Find element by text and tap it |
145
- | `tap_element` | Tap element by text or resource-id (more reliable) |
146
- | `tap_safe` | Tap avoiding system navigation bars |
147
- | `double_tap` | Double tap at coordinates |
148
- | `long_press` | Long press for context menus |
149
- | `multi_tap` | Multiple rapid taps at same position |
150
- | `swipe` | Swipe between two points |
151
- | `scroll` | Scroll in a direction (up/down/left/right) |
152
- | `scroll_to_text` | Scroll until text is visible |
153
- | `drag` | Drag gesture for drag & drop |
154
- | `pinch_zoom` | Pinch zoom gesture (zoom in/out) |
155
-
156
- ### Text Input
157
-
158
- | Tool | Description |
159
- |------|-------------|
160
- | `type_text` | Type text into focused input |
161
- | `clear_input` | Clear focused text field |
162
- | `select_all` | Select all text in focused field |
163
- | `set_text` | Clear and type new text (combines both) |
164
-
165
- ### System & Keys
166
-
167
- | Tool | Description |
168
- |------|-------------|
169
- | `press_key` | Press system key (BACK, HOME, ENTER, etc.) |
170
- | `rotate_device` | Rotate to portrait or landscape |
171
- | `set_clipboard` | Set text to device clipboard |
172
- | `get_clipboard` | Get clipboard content |
173
-
174
- ### App Management
175
-
176
- | Tool | Description |
177
- |------|-------------|
178
- | `launch_app` | Launch app by package name |
179
- | `install_apk` | Install APK file |
180
- | `list_packages` | List installed packages |
181
- | `clear_app_data` | Clear app data |
182
- | `force_stop` | Force stop an app |
183
- | `get_current_activity` | Get currently focused activity |
184
-
185
- ### Device Info & Logs
186
-
187
- | Tool | Description |
188
- |------|-------------|
189
- | `device_info` | Get device model, Android version, screen size |
190
- | `get_logs` | Get logcat logs with filters and log levels |
191
-
192
- ### Wait & Sync
193
-
194
- | Tool | Description |
195
- |------|-------------|
196
- | `wait_for_element` | Wait for element with text to appear |
197
- | `wait_for_element_gone` | Wait for element to disappear |
198
- | `wait_for_ui_stable` | Wait for UI to stop changing (after animations) |
199
-
200
- ---
201
-
202
- ## Emulator Setup Guides
203
-
204
- ### Option 1: Android Studio Emulator (AVD)
205
-
206
- Best for: Local development on machines with display
207
-
208
- ```bash
209
- # List available AVDs
210
- emulator -list-avds
211
-
212
- # Start emulator
213
- emulator -avd YOUR_AVD_NAME
214
-
215
- # Verify connection
216
- adb devices
217
- ```
218
-
219
- ### Option 2: Redroid (Docker) - Recommended for Servers
220
-
221
- Best for: Headless servers, CI/CD, cloud VPS
222
-
223
- Redroid runs Android in a Docker container without requiring KVM on x86.
224
-
225
- ```bash
226
- # Run Redroid container
227
- docker run -d --name redroid \
228
- --privileged \
229
- -p 5555:5555 \
230
- redroid/redroid:13.0.0-latest \
231
- androidboot.redroid_width=720 \
232
- androidboot.redroid_height=1280 \
233
- androidboot.redroid_dpi=320
234
-
235
- # Connect ADB
236
- adb connect localhost:5555
237
-
238
- # Verify
239
- adb devices
240
- ```
241
-
242
- **For apps using network (React Native, Expo, etc.):**
243
-
244
- ```bash
245
- # Forward ports from device to host
246
- adb reverse tcp:8081 tcp:8081 # Metro bundler
247
- adb reverse tcp:3000 tcp:3000 # API server
248
- ```
249
-
250
- ### Option 3: Genymotion
251
-
252
- Best for: Local development, faster than AVD
253
-
254
- 1. Download from [genymotion.com](https://www.genymotion.com/)
255
- 2. Create and start a virtual device
256
- 3. Enable ADB bridge in settings
257
- 4. Connect: `adb connect localhost:5555`
258
-
259
- ### Option 4: Physical Device
260
-
261
- Best for: Real-world testing
262
-
263
- **USB Connection:**
264
- 1. Enable Developer Options on device
265
- 2. Enable USB Debugging
266
- 3. Connect via USB
267
- 4. Run `adb devices`
268
-
269
- **WiFi Connection:**
270
- ```bash
271
- # First connect via USB, then:
272
- adb tcpip 5555
273
- adb connect DEVICE_IP:5555
274
- # Disconnect USB
275
- ```
276
-
277
- ---
278
-
279
- ## Running on Cloud/VPS Servers
280
-
281
- ### Prerequisites
282
-
283
- - Linux server (Ubuntu 20.04+ recommended)
284
- - Docker installed
285
- - At least 4GB RAM, 2 CPU cores
286
-
287
- ### Step-by-Step Setup
288
-
289
- #### 1. Install ADB
290
-
291
- ```bash
292
- # Ubuntu/Debian
293
- sudo apt update
294
- sudo apt install android-tools-adb
295
-
296
- # Verify
297
- adb version
298
- ```
299
-
300
- #### 2. Run Redroid
301
-
302
- ```bash
303
- docker run -d --name redroid \
304
- --privileged \
305
- -p 5555:5555 \
306
- redroid/redroid:13.0.0-latest \
307
- androidboot.redroid_width=720 \
308
- androidboot.redroid_height=1280 \
309
- androidboot.redroid_dpi=320
310
- ```
311
-
312
- #### 3. Connect ADB
313
-
314
- ```bash
315
- adb connect localhost:5555
316
- adb devices # Should show "localhost:5555 device"
317
- ```
318
-
319
- #### 4. Install Node.js and MCP
320
-
321
- ```bash
322
- # Install Node.js 18+
323
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
324
- sudo apt install -y nodejs
325
-
326
- # Install MCP
327
- npm install -g mcp-android-emulator
328
- ```
329
-
330
- #### 5. Configure Claude Code
331
-
332
- ```bash
333
- claude mcp add android-emulator -- npx mcp-android-emulator
334
- ```
335
-
336
- ### Running AVD Headless (Alternative)
337
-
338
- If you have KVM support:
339
-
340
- ```bash
341
- # Install Android SDK
342
- sudo apt install openjdk-11-jdk
343
- wget https://dl.google.com/android/repository/commandlinetools-linux-latest.zip
344
- # ... setup SDK ...
345
-
346
- # Run emulator headless
347
- emulator -avd YOUR_AVD \
348
- -no-window \
349
- -no-audio \
350
- -no-boot-anim \
351
- -gpu swiftshader_indirect \
352
- -memory 2048 \
353
- -cores 2
354
- ```
355
-
356
- ---
357
-
358
- ## Usage Examples
359
-
360
- Once configured, ask Claude to:
361
-
362
- ```
363
- "Take a screenshot of the Android device"
364
-
365
- "Tap on the Login button"
366
-
367
- "Type 'hello@example.com' in the email field and press Enter"
368
-
369
- "Scroll down until you see 'Submit' and tap it"
370
-
371
- "Launch the Chrome app and navigate to google.com"
372
-
373
- "Get error logs from the last 100 lines"
374
-
375
- "Wait for the loading spinner to disappear, then take a screenshot"
376
-
377
- "Check if 'Welcome' text is visible on screen"
378
-
379
- "Rotate the device to landscape mode"
380
- ```
381
-
382
- ### Automated Testing Example
383
-
384
- ```
385
- "Test the login flow:
386
- 1. Take a screenshot of the initial state
387
- 2. Type 'testuser' in the username field
388
- 3. Type 'password123' in the password field
389
- 4. Tap the Login button
390
- 5. Wait for the UI to stabilize
391
- 6. Assert that 'Dashboard' is visible
392
- 7. Take a final screenshot"
393
- ```
394
-
395
- ---
396
-
397
- ## Troubleshooting
398
-
399
- ### ADB not found
400
-
401
- ```bash
402
- # Check if ADB is installed
403
- which adb
404
-
405
- # If not found, install it
406
- sudo apt install android-tools-adb # Ubuntu/Debian
407
- brew install android-platform-tools # macOS
408
-
409
- # Or set custom path
410
- export ADB_PATH=/path/to/android-sdk/platform-tools/adb
411
- ```
412
-
413
- ### No devices connected
414
-
415
- ```bash
416
- # List devices
417
- adb devices
418
-
419
- # If using Redroid, connect explicitly
420
- adb connect localhost:5555
421
-
422
- # Check if emulator is fully booted
423
- adb shell getprop sys.boot_completed # Should return "1"
424
- ```
425
-
426
- ### Permission denied on screenshots
427
-
428
- ```bash
429
- mkdir -p /tmp/android-screenshots
430
- chmod 755 /tmp/android-screenshots
431
- ```
432
-
433
- ### Redroid container won't start
434
-
435
- ```bash
436
- # Check logs
437
- docker logs redroid
438
-
439
- # Ensure privileged mode
440
- docker run --privileged ...
441
-
442
- # Try different Android version
443
- docker run ... redroid/redroid:11.0.0-latest
444
- ```
445
-
446
- ### Apps can't reach localhost services
447
-
448
- ```bash
449
- # Forward ports from device to host
450
- adb reverse tcp:8081 tcp:8081
451
- adb reverse tcp:3000 tcp:3000
452
-
453
- # Verify
454
- adb reverse --list
455
- ```
456
-
457
- ---
458
-
459
- ## Changelog
460
-
461
- ### v1.2.3 (Latest)
462
- - Updated documentation with comprehensive setup guides
463
- - Added emulator comparison (AVD, Redroid, Genymotion, Physical)
464
- - Added cloud/VPS deployment instructions
465
- - Added troubleshooting section
466
-
467
- ### v1.2.2
468
- - Fixed `set_clipboard` and `get_clipboard` for Redroid/Docker compatibility
469
- - Uses `/data/local/tmp` as fallback path
470
-
471
- ### v1.2.0
472
- - Added 14 new tools:
473
- - `get_screen_size`, `is_element_visible`, `get_element_bounds`
474
- - `scroll_to_text`, `wait_for_ui_stable`, `wait_for_element_gone`
475
- - `multi_tap`, `pinch_zoom`, `tap_safe`, `tap_element`
476
- - `set_clipboard`, `get_clipboard`, `rotate_device`
477
- - `get_focused_element`, `assert_screen_contains`
478
-
479
- ### v1.1.0
480
- - Added `double_tap`, `drag`, `set_text`, `select_all`, `clear_input`
481
-
482
- ### v1.0.0
483
- - Initial release with core functionality
484
-
485
- ---
486
-
487
- ## Development
488
-
489
- ```bash
490
- # Clone repo
491
- git clone https://github.com/Anjos2/mcp-android-emulator.git
492
- cd mcp-android-emulator
493
-
494
- # Install dependencies
495
- npm install
496
-
497
- # Build
498
- npm run build
499
-
500
- # Watch mode for development
501
- npm run dev
502
- ```
503
-
504
- ## License
505
-
506
- MIT License - see [LICENSE](LICENSE) for details.
507
-
508
- ## Contributing
509
-
510
- Contributions are welcome! Please feel free to submit a Pull Request.
511
-
512
- ### Ideas for contributions:
513
- - Support for multiple connected devices
514
- - Screen recording
515
- - File transfer (push/pull)
516
- - Network simulation
517
- - Battery/GPS simulation
518
-
519
- ## Related Projects
520
-
521
- - [Model Context Protocol](https://modelcontextprotocol.io/)
522
- - [Android Debug Bridge (ADB)](https://developer.android.com/tools/adb)
523
- - [Claude Code](https://claude.ai/code)
524
- - [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)