tanbro/uiautomator2-mcp-server
Sobre
A MCP (Model Context Protocol) server that provides tools for controlling and interacting with Android devices using uiautomator2.
IA e aprendizado de máquinaO que você pode fazer
- 📱 Multi-Device - One server, many phones
- 🔍 XPath Filtering - Dump only the UI elements you need — save tokens and speed up responses
- 🎛️ Tool Filtering - Show the AI only the tools it needs — fewer hallucinations, better results
- ⚡ Zero Setup - Run with uvx immediately, no installation needed
Crescimento medido de estrelas
- em 24 h
- 0
- em 7 dias
- Coletando histórico
- em 15 dias
- Coletando histórico
- em 1 mês
- Coletando histórico
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
Originaluiautomator2-mcp-server
- 🇨🇳 中文说明
Code of Conduct: Please follow our Code of Conduct when participating in this project.
An MCP server that provides tools for controlling Android devices using uiautomator2.
Use AI to automate your Android device: take screenshots, tap/swipe, manage apps, send text, and more.
📺 Demo
Conversational Android Automation
User says: "Search cat videos on xxx App then play the video and swap to the next video"
AI automatically:

- ✅ Launch app → Tap search → Enter keywords → Execute search → Tap result -> Swap to next video
Control Android devices with natural language, no coding required
Detailed example: skills/douyin-search
✨ Features
- 📱 Multi-Device - One server, many phones
- 🔍 XPath Filtering - Dump only the UI elements you need — save tokens and speed up responses
- 🎛️ Tool Filtering - Show the AI only the tools it needs — fewer hallucinations, better results
- ⚡ Zero Setup - Run with
uvximmediately, no installation needed - 📦 Standalone Executable - Bundle into a standalone app with PyInstaller or Nuitka — no Python runtime required
- 🧰 70+ Tools - Click, swipe, type, apps, screenshots — everything you need
- 🧪 Built-in Testing - Includes AI-driven UI test framework out of the box
- 🔄 Two Modes - STDIO for local, HTTP for remote
- ⚙️ Config Files - TOML/YAML/JSON config with auto-discovery
- 🔒 Clean Code - Type hints, linted, formatted — easy to extend
🎯 Use Cases
| Scenario | Description |
|---|---|
| 🧪 Automated Testing | Run natural language UI tests with AI-driven test framework |
| ⚡ Rapid Prototyping | Quickly test Android app interactions without writing code |
| ♿ Accessibility Testing | Verify app accessibility features automatically |
| 📊 Health Monitoring | Periodic device health and status checks |
| 🤖 Task Automation | Automate repetitive tasks like form filling, navigation |
| 🔬 Remote Debugging | Inspect UI hierarchy and capture screenshots remotely |
🏗️ Architecture
graph TD
AI[AI Assistant<br/>Claude/GPT/etc.] --> MCP[MCP Protocol]
MCP --> Server[u2mcp Server]
Server --> uiautomator2[uiautomator2]
uiautomator2 --> ADB[ADB]
ADB --> Device[Android Device<br/>Physical/Emulator]
style AI fill:#e1f5ff
style MCP fill:#fff4e6
style Server fill:#f3e5f5
style uiautomator2 fill:#e8f5e9
style ADB fill:#fff3e0
style Device fill:#fce4ec
Migration from v0.1.x
If you're upgrading from v0.1.3 or earlier: The CLI now requires an explicit subcommand. Change your command from:
# Old (v0.1.3 and earlier)
u2mcp
to:
# New (v0.2.0+)
u2mcp stdio
All other commands remain the same (just add the transport subcommand).
Prerequisites
- Python 3.11+
- Android device with USB debugging enabled
adb: bundled with the platform-specificadbutilswheels (macOS, Linux x86_64, Windows), so no separate install is needed on those platforms. On other platforms, or to use your own build, install Android SDK Platform Tools and make sureadbis in your PATH (or setADBUTILS_ADB_PATH)
💡 Which install route? All routes give you the same server. Use the install script for a standalone binary; use
uvxif you prefer running from PyPI without installing (most MCP clients also expectuvxto exist — see MCP Client Configuration).
Installation
Option 1 — pre-compiled binary (recommended)
# macOS / Linux curl -fsSL https://raw.githubusercontent.com/tanbro/uiautomator2-mcp-server/main/scripts/install.sh | bash# Windows (PowerShell) irm https://raw.githubusercontent.com/tanbro/uiautomator2-mcp-server/main/scripts/install.ps1 | iexAfter installation, the short alias
u2mcpis available:u2mcp --versionSupported platforms for the pre-compiled binaries:
Platform Release asset Requirement Linux x86_64 u2mcp-x86_64-unknown-linux-gnu-<version>.tar.gzglibc; built in quay.io/pypa/manylinux_2_28_x86_64Linux aarch64 not published — macOS (Apple Silicon) u2mcp-aarch64-apple-darwin-<version>.tar.gzarm64 Mac Windows x64 u2mcp-x86_64-pc-windows-msvc-<version>.zipx64 Windows (ARM64 runs it under emulation) Release assets are named with a Rust-style target triple, so a new ABI is a new triple rather than a new naming scheme. The Linux floor is the build image's, not a number we maintain here: the image above is a manylinux profile whose name states the glibc it targets. musl systems (Alpine and friends), distributions older than that profile (CentOS 7, Debian 9) and Intel Macs have no pre-compiled binary and must install from PyPI below.
These binaries are built with PyInstaller; maintainers can see CONTRIBUTING.md for how.
Option 2 — run directly without installing
Install uv first (one command;
uvxis part of the uv toolkit and can run any package from PyPI without manual installation):# macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh # Windows (PowerShell) powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # or: winget install --id=astral-sh.uv -eThen run:
uvx uiautomator2-mcp-server stdioOption 3 — install from PyPI
# Install using uv (tool method) uv tool install uiautomator2-mcp-server # Or install with pipx pipx install uiautomator2-mcp-server # Or install with pip python -m pip install uiautomator2-mcp-serverAfter installation, the short alias
u2mcpis available:u2mcp --versionAfter installation, the short alias
u2mcpis available:u2mcp --version
Note on Package Name:
While the CLI command isu2mcp, the PyPI package name isuiautomator2-mcp-server. We plan to simplify this tou2mcpin v1.0.0. For now, please install using the full package name above.
Running Modes
Note: The commands below use
u2mcp, which requires the package to be installed. If you haven't installed it yet, you can run directly usinguvx uiautomator2-mcp-server ...instead.
The MCP server can run in two modes:
STDIO Mode (for local MCP clients)
# If installed
u2mcp stdio
# Or run directly without installation
uvx uiautomator2-mcp-server stdio
This mode communicates via standard input/output and is typically used by MCP clients that spawn the server process directly.
HTTP Mode (for remote/network access)
# If installed
u2mcp http -H 0.0.0.0 -p 8000 --no-auth
# Or run directly without installation
uvx uiautomator2-mcp-server http -H 0.0.0.0 -p 8000 --no-auth
# With authentication token (if installed)
u2mcp http -H 0.0.0.0 -p 8000 -t YOUR_SECRET_TOKEN
# Or run directly without installation
uvx uiautomator2-mcp-server http -H 0.0.0.0 -p 8000 -t YOUR_SECRET_TOKEN
The server will listen on http://localhost:8000/mcp (or your specified host/port).
Configuration Files
You can configure u2mcp using config files instead of (or in addition to) CLI flags. Supported formats: TOML, YAML, and JSON.
Config File Locations
The server automatically discovers config files in platform-specific directories:
| Priority | Location | Platform Example |
|---|---|---|
| 1 (lowest) | System config dir | /etc/u2mcp/ (Linux), C:\ProgramData\u2mcp\ (Windows) |
| 2 | User config dir | ~/.config/u2mcp/ (Linux), %APPDATA%\u2mcp\ (Windows) |
| 3 (highest) | Current working directory | ./ |
In each directory, the server looks for the first matching file: u2mcp.toml, u2mcp.yaml, u2mcp.yml, u2mcp.json (at most one file per directory).
Priority order: CLI args > Environment variables > Config file (cwd > user > system) > Defaults.
Using a Custom Config File
# Via CLI option
u2mcp stdio --config-file my-config.toml
# Via environment variable
U2MCP_CONFIG_FILE=my-config.toml u2mcp stdio
Config File Structure
Config files use command names as top-level keys:
# u2mcp.toml
[stdio]
log-level = "debug"
check-adb = false
include-tags = ["device:info", "action:touch"]
exclude-tools = ["shell_command"]
[http]
host = "0.0.0.0"
port = 8000
auth = true
json-response = true
# u2mcp.yaml
stdio:
log-level: debug
check-adb: false
http:
host: "0.0.0.0"
port: 8000
auth: false
{
"stdio": {
"log-level": "warning",
"print-tags": false
}
}
Environment Variables
CLI parameters can be set via environment variables with the U2MCP_{COMMAND}_{PARAM} format:
U2MCP_STDIO_LOG_LEVEL=debug u2mcp stdio
U2MCP_HTTP_HOST=0.0.0.0 U2MCP_HTTP_PORT=9000 u2mcp http
U2MCP_HTTP_AUTH=false u2mcp http
Example Config Files
See the examples/ directory for ready-to-use config files:
| File | Description |
|---|---|
config-minimal-stdio.toml |
Minimal stdio config with quiet mode |
config-full.toml |
Full config with stdio, http, and doctor sections |
config-filtered-tools.toml |
Tool filtering by tags |
config-http-server.yaml |
HTTP server config in YAML format |
config-quiet-mode.json |
Quiet mode config in JSON format |
CLI Utility Commands
Note: The commands below use
u2mcp, which requires the package to be installed. If you haven't installed it yet, you can run directly usinguvx uiautomator2-mcp-server ...instead.
The u2mcp CLI provides several utility commands for exploring available tools and tags:
# List all available tools
u2mcp tools
# Or run directly
uvx uiautomator2-mcp-server tools
# Show detailed information about a specific tool
u2mcp info screenshot
# Show tools matching a pattern (supports wildcards)
u2mcp info "device:*" # All device tools
u2mcp info "*screenshot*" # Tools with 'screenshot' in name
# List all available tool tags
u2mcp tags
# Show version information
u2mcp --version
Tool Filtering
Note: The commands below use
u2mcp, which requires the package to be installed. Replace withuvx uiautomator2-mcp-server ...if running directly.
You can selectively expose tools using tag-based filtering. This reduces the number of tools available to the LLM, which can improve performance and reduce confusion.
# Only expose device management tools
u2mcp stdio -i device:manage
# Or run directly
uvx uiautomator2-mcp-server stdio -i device:manage
# Only expose touch and gesture operations
u2mcp stdio -i action:touch -i action:gesture
# Exclude screen mirroring tools
u2mcp stdio -e screen:mirror
# Only expose app lifecycle and element interaction tools
u2mcp stdio -i app:lifecycle -i xpath:interact
# Exclude shell command tools (for security)
u2mcp stdio -e device:shell
# Only expose input-related tools
u2mcp stdio -i input:text
# Combine include and exclude
u2mcp stdio -i device:info -i action:touch -e screen:capture
# Bare category tags expose a whole category
u2mcp stdio -i device
# Filter by tool name instead of tags
u2mcp stdio --include-tools click --include-tools screenshot
# List all available tags
u2mcp tags
Quick Start
Before you start: Make sure you have configured an MCP client (like Claude Desktop) to use this server. See MCP Client Configuration below for details.
Connect your Android device via USB with USB debugging enabled
Configure your MCP client to use this server (see MCP Client Configuration)
Initialize the device (required first time):
"Initialize my Android device"
Start automating:
"Take a screenshot" "Tap at coordinates 500, 1000" "Swipe up" "Open YouTube app"
Short Options:
All common options support short flags for convenience:
-l/--log-level- Set log level-i/--include-tools- Include tools by name (repeatable)-e/--exclude-tools- Exclude tools by name (repeatable)-H/--host- Set host address (HTTP mode)-p/--port- Set port number (HTTP mode)-t/--token- Set authentication token (HTTP mode)--no-auth- Disable authentication (HTTP mode)
Filtering Options:
--include-tags/--exclude-tags and --include-tools/--exclude-tools take values as repeatable flags or lists in the config file:
# Allowlist: only expose touch actions and the screenshot tool
u2mcp stdio --include-tags action:touch --include-tools screenshot
# Denylist: expose everything except shell and mirroring
u2mcp stdio --exclude-tags device:shell --exclude-tags screen:mirror
Include filters act as an allowlist (only matching tools are exposed); exclude filters remove from that set afterwards and take precedence. Within a direction, tag and tool filters combine as a union.
Each tool carries two tags: a bare category (e.g. device) and a subcategory (e.g. device:capture). Selecting a bare tag exposes the whole category.
Available Tags:
| Tag | Description |
|---|---|
device |
All device tools |
device:manage |
Device connection, initialization, and management |
device:info |
Device information and status |
device:capture |
Screenshots and UI hierarchy |
device:shell |
Shell command execution |
action |
All touch/gesture/key/screen tools |
action:touch |
Click and tap actions |
action:gesture |
Swipe and drag gestures |
action:key |
Physical key presses |
action:screen |
Screen control (on/off) |
app |
All app management tools |
app:manage |
Install and uninstall apps |
app:lifecycle |
Start and stop apps |
app:info |
App information and listing |
app:config |
App configuration (clear data, permissions) |
xpath |
All XPath-based element tools |
xpath:wait |
Wait for elements to appear/disappear |
xpath:interact |
Click and interact with elements |
xpath:query |
Get element info (text, bounds) |
xpath:gesture |
Element-specific gestures (swipe, scroll) |
xpath:capture |
Element screenshots |
gesture |
Edge swipe gestures |
gesture:edge |
Directional edge swipes |
input |
All text input tools |
input:text |
Text input, focusing, clearing, keyboard |
clipboard |
All clipboard tools |
clipboard:read |
Read clipboard |
clipboard:write |
Write clipboard |
screen |
All screen tools |
screen:mirror |
Screen mirroring (scrcpy) |
screen:record |
Screen recording |
screen:capture |
Screen screenshots |
system |
All system control tools |
system:orientation |
Device orientation control |
system:ui |
Notifications, quick settings, unlock |
system:toast |
Toast message utilities |
util |
Utilities (delay/sleep) |
Testing and Debugging
Using MCP Inspector
MCP Inspector is a command-line tool for testing and debugging MCP servers without requiring an AI client.
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector
# Inspect the server in STDIO mode
npx @modelcontextprotocol/inspector u2mcp stdio
# Or inspect the server in HTTP mode
# First start the server: u2mcp http --host 0.0.0.0 --port 8000
# Then run inspector with the URL
npx @modelcontextprotocol/inspector http://localhost:8000/mcp
The inspector will display:
- Available tools and their parameters
- Server resources and prompts
- Real-time tool execution results
- Request/response logs
Using Postman
Postman has native MCP support for testing and debugging MCP servers.
- Open Postman and create a new MCP Request
- Enter the server connection details:
STDIO Mode:
Command: u2mcp
Arguments: stdio
HTTP Mode:
URL: http://localhost:8000/mcp
(First start the server: u2mcp http --host 0.0.0.0 --port 8000)
- Click Load Capabilities to connect and discover available tools
- Use the Tools, Resources, and Prompts tabs to interact with the server
- Click Run to execute tool calls and view responses
For more information, see the Postman MCP documentation.
Using cURL
You can also test the HTTP endpoint using cURL with JSON-RPC 2.0 requests:
# 1. Start the server first
u2mcp http --host 0.0.0.0 --port 8000
# 2. In another terminal, send MCP requests
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'
# Call a tool (e.g., list devices)
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "device_list",
"arguments": {}
}
}'
MCP Client Configuration
Every MCP-compatible client connects to this server in one of the same two ways — a command (stdio) or a URL (HTTP). For full instructions and a per-client pointer list, see docs/mcp-clients.md.
stdio — paste the command where your client asks for the server command:
uvx uiautomator2-mcp-server stdio
HTTP — start the server, then give your client the URL:
uvx uiautomator2-mcp-server http -H 0.0.0.0 -p 8000
http://localhost:8000/mcp
Clients that have been verified to work include Claude Desktop, Codex, Antigravity, Trae, OpenClaw, Hermes Agent, DeepSeek Harness, WorkBuddy, Claude Code, Codex CLI, and Gemini CLI — see docs/mcp-clients.md for where each one asks for the command or URL. Agents that support skills work better with the companion uiautomator2-mcp skill — see docs/mcp-clients.md.
AI-Driven UI Testing
Prerequisite: To use AI-driven UI testing, you must first configure an MCP client to connect to this server. See the MCP Client Configuration section above and docs/mcp-clients.md for setup instructions.
This project includes an AI-driven UI testing framework using the skills/ system. The android-ui-test skill serves a dual purpose:
- Educational Example: Demonstrates best practices for MCP skill development
- Production Testing: Acts as the project's automated UI test suite for CI/CD
Skill Structure
skills/android-ui-test/
├── SKILL.md # Core skill definition (YAML metadata + lightweight description)
├── README.md # Architecture overview and quick start
├── examples/ # Learning materials
│ └── usage-examples.md # Detailed usage patterns and examples
└── references/ # Technical specifications
└── test-specification.md # Complete test specification (TC001-TC010)
Running UI Tests
Simply ask the AI to execute the UI test:
Run the Android UI test suite on my connected device
The AI will:
- Auto-detect and connect to the first available device
- Run comprehensive tests covering all device operations
- Provide a detailed test report with pass/fail/skip status
Test Coverage
| Category | Tests |
|---|---|
| Device | Connection, Info, Screenshot, Hierarchy, Doctor |
| Touch | Click, Long Click, Double Click |
| Gesture | Swipe, Drag, Key Press |
| App | List, Start, Wait, Info, Permissions |
| Element | Wait, Exists, Bounds, Get Text, Click, Screenshot |
| Input | Text Input, Focused Text, Keyboard |
| Clipboard | Read/Write (with known limitations) |
Sample Test Report
Android UI Test Summary
=======================
Device: UGAILFCIU88TT469 (PDKM00, Android 11, SDK 31)
Test Cases:
[PASS] TC001: Device Connection & Initialization
[PASS] TC002: Device Info & Capture
[PASS] TC003: Touch Actions
[PASS] TC004: Gesture Actions
[PASS] TC005: Application Management
[PASS] TC006: Element Operations
[PASS] TC007: Input & Keyboard
[SKIP] TC008: Clipboard Operations (Android security restriction)
Total: 7 passed, 1 skipped, 0 failed
Creating Custom Skills
See skills/android-ui-test/ for a complete reference implementation.
Each skill directory contains:
SKILL.md- YAML frontmatter with metadata and lightweight descriptionexamples/- Detailed usage patterns for learningreferences/- Technical specifications and test cases
Available Tools
The server provides 70+ tools organized into the following categories:
| Category | Description |
|---|---|
| Device | Connection, info, screenshot, hierarchy, shell |
| Actions | Touch, gestures, key presses, screen control |
| Apps | Install, launch, manage, list app info |
| Element | XPath-based element location and interaction (v0.3.0+) |
| Input | Text input, keyboard control, focused text |
| Clipboard | Read/write clipboard content |
| Toast | Android Toast message detection and display |
| Scrcpy | Screen mirroring with scrcpy |
Listing Tools
Run these commands to explore available tools:
# List all tools
u2mcp tools
# Show detailed info for a specific tool
u2mcp info screenshot
# Show tools matching a pattern (supports wildcards)
u2mcp info "device:*" # All device tools
u2mcp info "*screenshot*" # Tools with 'screenshot' in name
u2mcp info "xpath:*" # All XPath tools (v0.3.0+)
# List all tool tags
u2mcp tags
Key Features
- XPath-based element interaction - Primary method for UI automation, LLM-optimized (v0.3.0+)
- Tag-based filtering - Expose only relevant tools to reduce AI confusion
- Comprehensive coverage - Everything from basic clicks to advanced element queries
Example Usage
You: Take a screenshot
Claude: [Uses screenshot tool, displays image]
You: What apps are installed?
Claude: [Lists installed apps using app_list]
You: Open the YouTube app
Claude: [Uses app_start with package name]
You: Search for "cats"
Claude: [Uses click to tap search bar, then send_text to type "cats"]
You: Scroll down
Claude: [Uses swipe to scroll down]
License
Apache-2.0
Explore projetos relacionados
Carregando…