Skip to main content

UIAutomator2 MCP Server with OCR support

Project description

UIAutomator2 MCP Server

基于FastMCP框架实现的UIAutomator2 MCP服务器,提供Android设备自动化控制能力。

功能特性

  • Android设备管理

    • ADB命令执行
    • 应用包管理
    • 屏幕截图
  • UI自动化操作

    • 元素点击
    • 文本输入
    • 屏幕滑动
    • 元素等待
    • 页面滚动
  • 应用管理

    • 应用启动/停止
    • 当前应用信息
    • UIAutomator2服务管理

环境要求

  • Python 3.10+
  • ADB工具
  • Android设备或模拟器

安装

  1. 克隆项目
git clone https://github.com/yourusername/uiautomator2-mcp.git
cd uiautomator2-mcp
  1. 安装依赖
pip install -e .

MCP配置

1. 配置mcp.json

在Claude Desktop的配置目录下创建或编辑mcp.json文件(通常在~/.cursor/mcp.json%APPDATA%\Cursor\mcp.json):

{
  "mcpServers": {
    "android": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/uiautomator2-mcp",  // 替换为你的项目路径
        "run",
        "src/server.py"
      ]
    }
  }
}

配置说明:

  • android: MCP服务器的唯一标识符
  • command: 用于运行Python的命令(这里使用uv,也可以使用python)
  • args: 命令行参数
    • --directory: 项目目录路径
    • run: uv的运行命令
    • src/server.py: 服务器入口文件路径

2. 配置选项

你可以根据需要调整以下配置:

  1. 使用Python直接运行:
{
  "mcpServers": {
    "android": {
      "command": "python",
      "args": [
        "/path/to/uiautomator2-mcp/src/server.py"
      ]
    }
  }
}
  1. 使用虚拟环境:
{
  "mcpServers": {
    "android": {
      "command": "/path/to/venv/bin/python",
      "args": [
        "/path/to/uiautomator2-mcp/src/server.py"
      ]
    }
  }
}
  1. 添加环境变量:
{
  "mcpServers": {
    "android": {
      "command": "python",
      "args": [
        "/path/to/uiautomator2-mcp/src/server.py"
      ],
      "env": {
        "PYTHONPATH": "/path/to/uiautomator2-mcp",
        "ANDROID_HOME": "/path/to/android-sdk"
      }
    }
  }
}

3. 多服务器配置

你可以在同一配置文件中定义多个MCP服务器:

{
  "mcpServers": {
    "android": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/uiautomator2-mcp",
        "run",
        "src/server.py"
      ]
    },
    "android-debug": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/uiautomator2-mcp",
        "run",
        "src/server.py",
        "--debug"
      ]
    }
  }
}

使用工具

配置完成后,你可以在Claude中直接使用所有可用的工具:

# 初始化UIAutomator2
await mcp.call_tool("mcp_android_init_uiautomator2", {})

# 启动应用
await mcp.call_tool("mcp_android_start_app", {
    "package_name": "com.example.app"
})

# 点击元素
await mcp.call_tool("mcp_android_click_element", {
    "text": "登录"
})

开发

  1. 安装开发依赖
pip install -e ".[dev]"
  1. 运行测试
pytest

贡献

欢迎提交Issue和Pull Request。

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_gitdzreal93_uiautomator2_mcp-0.1.1.tar.gz.

File metadata

File hashes

Hashes for iflow_mcp_gitdzreal93_uiautomator2_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a15a46cd68acdc8a5bb49b818a376ef955a5cce3cbff7037c54a480c25eab392
MD5 ff6c993156d56f51a429e691bdf21441
BLAKE2b-256 e54298ff0cfae445506e173932d82603e2ee022c535c05e8594ea9c5977d17ed

See more details on using hashes here.

File details

Details for the file iflow_mcp_gitdzreal93_uiautomator2_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for iflow_mcp_gitdzreal93_uiautomator2_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e1097c0e0eb4cac88b5b50523c586b63f491d1ed74f5fb601c2ab37021dae143
MD5 c159b3aa09a7f5bbfd2477bf5e198833
BLAKE2b-256 88d019fa4d54870f3817caae430d983b9fb5dea2c1bc587c0a97e96b97f1da77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page