Labsco
nim444 logo

MCP Android Agent

β˜… 53

from nim444

Automate Android devices using the uiautomator2 library, requiring adb and a connected device.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

Python 3.13 CI Pipeline Coverage: 90% Code style: ruff License: MIT

MCP Android Agent

This project provides an MCP (Model Context Protocol) server for automating Android devices using uiautomator2. It's designed to be easily plugged into AI agents like GitHub Copilot Chat, Claude, or Open Interpreter to control Android devices through natural language.

Modular Architecture

The server has been refactored into a clean, modular architecture with tools organized by functionality:

Copy & paste β€” that's it
mcp-android-server-python/
β”œβ”€β”€ server.py                    # Main server (61 lines - clean & focused)
β”œβ”€β”€ server_original_backup.py    # Backup of original monolithic version
└── tools/                       # πŸ†• Modular tools package
    β”œβ”€β”€ __init__.py             # Central registration & imports
    β”œβ”€β”€ device_tools.py         # Device connection & status tools
    β”œβ”€β”€ app_tools.py            # Application management tools
    β”œβ”€β”€ screen_tools.py         # Screen control & unlock tools
    β”œβ”€β”€ input_tools.py          # User input simulation (click, swipe, text)
    β”œβ”€β”€ inspection_tools.py     # UI inspection & screenshots
    └── advanced_tools.py       # Advanced features (toast, activity wait)

Benefits of Modular Architecture

  • Maintainability: Easy to add/modify/remove tools without touching main server
  • Organization: Tools grouped logically by functionality
  • Testing: Individual tool modules can be unit tested separately
  • Reusability: Tool modules can be reused in other projects
  • Scalability: New tool categories can be added as separate modules
  • Clean Code: Main server reduced from 1321 lines to 61 lines

Quick Demo

Demo


Demo

Features

Device Management

  • Smart Device Detection: Automatically finds and connects to available devices
  • Comprehensive Device Info: Get serial, resolution, battery, WiFi IP, Android version
  • ADB Diagnostics: Check ADB availability and connection status
  • Health Monitoring: Built-in server health checks

Application Management

  • App Discovery: List all installed applications (system + user apps)
  • App Lifecycle Control: Start, stop, force-stop apps by package name
  • App State Monitoring: Track current foreground app and activity
  • Data Management: Clear app data/cache for testing

Screen & Display Control

  • Screen Power Management: Turn screen on/off programmatically
  • Smart Unlock: Automatic screen unlocking with standard methods
  • Screen State Monitoring: Wait for screen activation (async support)

User Input Simulation

  • Precision Interactions: Click by text, resource ID, or content description
  • Advanced Gestures: Long click, swipe, drag operations
  • Text Input: Smart text entry with optional field clearing
  • Hardware Keys: Simulate home, back, menu, volume keys

UI Inspection & Debugging

  • Element Analysis: Get detailed UI element properties and bounds
  • Screen Capture: Take screenshots for debugging and documentation
  • UI Hierarchy: Export complete screen structure as XML
  • Smart Waiting: Wait for elements to appear with custom timeouts
  • Scroll Detection: Auto-scroll to find elements in long lists

Advanced Capabilities

  • Toast Detection: Capture system toast messages for verification
  • Activity Monitoring: Wait for specific Android activities
  • Background Operations: Async support for time-consuming operations

Use Cases

Perfect for:

  • AI agents that need to interact with real devices
  • Remote device control setups
  • Automated QA tools
  • Android bot frameworks
  • UI testing and automation
  • Device management and monitoring

UI Inspector

The project includes support for uiauto.dev, a powerful UI inspection tool for viewing and analyzing your device's interface structure.

  1. Install the UI inspector:
Copy & paste β€” that's it
uv pip install uiautodev
  1. Start the inspector:
Copy & paste β€” that's it
uiauto.dev
  1. Open your browser and navigate to https://uiauto.dev

Ui

Available MCP Tools

Device Management Tools

Tool NameDescription
mcp_healthCheck if the MCP server is running properly
get_device_statusGet complete device status and readiness information
connect_deviceConnect to an Android device and get basic info
get_device_infoGet detailed device info: serial, resolution, battery, etc.
check_adb_and_list_devicesCheck if ADB is installed and list connected devices

Application Management Tools

Tool NameDescription
get_installed_appsList all installed apps with version and package info
get_current_appGet info about the app currently in the foreground
start_appStart an app by its package name
stop_appStop an app by its package name
stop_all_appsStop all currently running apps
clear_app_dataClear user data/cache of a specified app

Screen Control Tools

Tool NameDescription
screen_onTurn on the screen
screen_offTurn off the screen
unlock_screenUnlock the screen (turn on and swipe if necessary)
wait_for_screen_onWait asynchronously until the screen is turned on

User Input Tools

Tool NameDescription
press_keySimulate hardware key press (e.g. home, back, menu, etc.)
clickTap on an element by text, resourceId, or description
long_clickPerform a long click on an element
send_textInput text into currently focused field (optionally clearing before)
swipeSwipe from one coordinate to another
dragDrag an element to a specific screen location

Inspection Tools

Tool NameDescription
get_element_infoGet info on UI elements (text, bounds, clickable, etc.)
wait_for_elementWait for an element to appear on screen
scroll_toScroll until a given element becomes visible
screenshotTake and save a screenshot from the device
dump_hierarchyDump the UI hierarchy of the current screen as XML

Advanced Tools

Tool NameDescription
get_toastGet the last toast message shown on screen
wait_activityWait until a specific activity appears

License

This project is licensed under the MIT License - see the LICENSE file for details.