Skip to main content
Glama
Android Control MCP Server

Android Control MCP Server

Android Control MCP Server

Node.js で構築された本番環境対応の Model Context Protocol (MCP) サーバーです。AI アシスタント(Claude Desktop、Cursor、カスタムエージェントワークフローなど)が、接続された Android デバイスを観察・推論・制御できるようにします。


🌟 特徴

  • 👀 コンピューター使用の観察: 高解像度の PNG スクリーンショットを、デバイスのメタデータとともに MCP イメージブロックとして直接返します。

  • 🔍 UIAutomator 階層の解析: 冗長な Android UI ツリーをコンパクトで構造化された JSON に変換するインテリジェントな XML ダンプパーサー。

  • 🎯 セマンティック要素クリック: 手動でピクセル計算を行うことなく、表示テキスト、アクセシビリティ説明、またはリソース ID でボタンやコントロールをクリックします。

  • ⚡ 高速ジェスチャーと入力: ピクセル精度のタップ、複数座標のスワイプ、方向スクロール、ハードウェアキーエミュレーション、シェルエスケープされたテキスト入力。

  • 📱 アプリライフサイクル管理: パッケージ名でアプリケーションを起動し、現在フォーカスされているフォアグラウンドアクティビティを検査します。

  • 🛡️ 安全性とサンドボックス化: 実際の画面境界に対する入力座標の検証、厳格な許可リストによるキーコード、引数のサニタイズ、コマンドタイムアウト、厳格な stderr ログ記録により、stdio MCP ストリームの整合性を保証します。

  • 🔄 マルチデバイス対応: 接続されたデバイスを自動検出するか、ANDROID_DEVICE_ID で特定のデバイスをターゲットにします。


Related MCP server: autoglm-mcp-server

🏗️ アーキテクチャ

AI Client (Claude Desktop, Cursor, Agent)
   │
   │ stdio transport (JSON-RPC)
   ▼
Node.js MCP Server
   │
   ├── Stderr Structured Logger
   ├── Zod Schema Validation
   │
   ├── ADB Controller Layer
   │   ├── Device Resolver (auto-detect or target serial)
   │   ├── Input Engine (tap, swipe, keyevent, text, scroll)
   │   ├── Screenshot Manager (exec-out binary stream)
   │   └── App Manager (launch, foreground inspection)
   │
   └── UIAutomator Engine
       ├── XML Hierarchy Dump & Normalizer
       ├── Bounds & Center Coordinate Extractor
       └── Semantic Element Finder & Click Resolver
   │
   ▼
Android Device / Emulator

📋 前提条件

  1. Node.js: v20.0.0 以上(node -v で確認)

  2. Android SDK Platform-Tools: ADB(adb)がインストールされ、システムの PATH に含まれていること(または ADB_PATH で設定)。

  3. Android デバイスまたはエミュレーター:

    • 物理デバイス: USB で接続し、開発者オプションとUSB デバッグを有効にします。

    • エミュレーター: Android Studio AVD、Genymotion、またはヘッドレスエミュレーター。

デバイス接続の確認

adb devices -l

デバイスが device として表示されるはずです:

List of devices attached
emulator-5554          device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64

🚀 インストールとクイックスタート

# Clone or navigate to the repository
cd c:/Users/Abhishek/Code/mcp

# Install dependencies
npm install

# Run unit tests
npm test

# Start the MCP server
npm start

⚙️ 設定

.env ファイルを作成するか、環境変数を渡します:

# Target device ID (serial number). If omitted and 1 device is connected, it auto-selects.
ANDROID_DEVICE_ID=

# Custom path to ADB executable if not in PATH
# Windows: C:\Users\<user>\AppData\Local\Android\Sdk\platform-tools\adb.exe
# macOS: /Users/<user>/Library/Android/sdk/platform-tools/adb
ADB_PATH=adb

# Log level: debug | info | warn | error
LOG_LEVEL=info

# Default ADB timeout in milliseconds
ADB_TIMEOUT_MS=15000

🔌 MCP クライアントへの接続

1. Claude Desktop の設定

claude_desktop_config.json に以下を追加します:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "android-control": {
      "command": "node",
      "args": ["C:/Users/Abhishek/Code/mcp/src/index.js"],
      "env": {
        "ANDROID_DEVICE_ID": "",
        "ADB_PATH": "adb",
        "LOG_LEVEL": "info"
      }
    }
  }
}

2. Cursor / Windsurf MCP 設定

Cursor の Features > MCP Servers または Windsurf の設定で:

  • 名前: android-control

  • タイプ: command

  • コマンド: node C:/Users/Abhishek/Code/mcp/src/index.js


🛠️ MCP ツールリファレンス

1. android_device_info

デバイスのハードウェアと OS の包括的なメタデータを取得します。

  • パラメータ:

    • deviceId (任意の文字列): ターゲットデバイスのシリアル番号。

  • 応答例:

    {
      "deviceId": "emulator-5554",
      "model": "Pixel 8",
      "manufacturer": "Google",
      "androidVersion": "15",
      "sdk": 35,
      "resolution": {
        "width": 1080,
        "height": 2400
      },
      "connectionState": "connected"
    }

2. android_screenshot

Android 画面を MCP イメージコンテンツブロック(image/png)としてキャプチャします。

  • パラメータ:

    • deviceId (任意の文字列): ターゲットデバイスのシリアル番号。

  • 戻り値: PNG base64 イメージデータブロック + 寸法メタデータ。


3. android_ui_dump

現在の画面の UIAutomator 階層を、AI に適したコンパクトな JSON 形式でダンプします。

  • パラメータ:

    • deviceId (任意の文字列): ターゲットデバイスのシリアル番号。

  • 出力例:

    {
      "package": "com.android.settings",
      "activity": "com.android.settings.Settings",
      "totalElements": 24,
      "interactiveElementsCount": 8,
      "elements": [
        {
          "index": 0,
          "text": "Network & internet",
          "resourceId": "android:id/title",
          "className": "TextView",
          "clickable": true,
          "bounds": [196, 340, 1016, 400],
          "center": [606, 370]
        }
      ]
    }

4. android_find_element

現在の画面上で特定の条件に一致する UI 要素を検索します。

  • パラメータ:

    • text (任意の文字列): 表示テキスト(完全一致または部分一致)。

    • contentDescription (任意の文字列): アクセシビリティラベル。

    • resourceId (任意の文字列): リソース ID。

    • className (任意の文字列): ウィジェットのクラス名。

    • clickable (任意のブール値): クリック可能性でフィルタリング。

    • exactMatch (任意のブール値、デフォルト false): 完全一致の文字列マッチ。


5. android_click_element

要素を検索し、その中心点をワンステップでクリックします。

  • パラメータ:

    • text (任意の文字列): 要素のテキスト。

    • contentDescription (任意の文字列): 要素のコンテンツ説明。

    • resourceId (任意の文字列): 要素のリソース ID。

    • className (任意の文字列): 要素のクラス。


6. android_tap

画面境界の検証付きで、正確な (x, y) 座標をタップします。

  • パラメータ:

    • x (数値): X 座標。

    • y (数値): Y 座標。


7. android_swipe

2 点間でドラッグ / スワイプジェスチャーを実行します。

  • パラメータ:

    • x1, y1 (数値): 開始座標。

    • x2, y2 (数値): 終了座標。

    • duration (任意の数値、デフォルト: 300): ミリ秒単位の持続時間。


8. android_type_text

現在フォーカスされている入力フィールドにテキストを入力します。スペースのエンコード(%s)とシェル文字のエスケープを処理します。

  • パラメータ:

    • text (文字列): 入力するテキスト。


9. android_press_key

ハードウェアキーまたはナビゲーションキーを押します。

  • 対応キー: HOME、BACK、ENTER、TAB、ESC、DELETE、SPACE、VOLUME_UP、VOLUME_DOWN、POWER、APP_SWITCH、CAMERA など。

  • パラメータ:

    • key (文字列): キー名または数値のキーコード。


10. android_scroll

実際の画面寸法に基づいて計算された方向スクロール。

  • パラメータ:

    • direction (文字列: up | down | left | right)

    • amount (任意の数値): ピクセル単位のスクロール距離。


11. android_launch_app

パッケージ名でアプリケーションを起動します。

  • パラメータ:

    • packageName (文字列): 例: com.android.settings、com.google.android.youtube。

    • activity (任意の文字列): 特定のアクティビティ名。


12. android_current_app

現在フォーカスされているフォアグラウンドのパッケージとアクティビティを検査します。


13. android_execute_action(統合コンピューター使用ツール)

tap、swipe、type、press_key、click_element、scroll、launch_app のすべてのアクションをサポートする単一の統合アクションディスパッチャー。

{
  "action": "click_element",
  "text": "Wi-Fi"
}

🤖 推奨 AI ワークフロー: 観察 → 推論 → 行動 → 検証

1. OBSERVE:
   AI calls `android_screenshot` and `android_ui_dump`.

2. REASON:
   AI inspects visual and UI structure to identify target elements.

3. ACT:
   AI calls `android_click_element`, `android_type_text`, or `android_scroll`.

4. VERIFY:
   AI captures another screenshot/dump to confirm desired state change.

🧪 テスト

自動テストスイートを実行します:

npm test

テストは Vitest を使用し、ADB 実行レイヤーをモックするため、CI/CD 中に物理的な Android デバイスを接続しなくても完全なユニット検証が可能です。


🔒 セキュリティのベストプラクティス

  • 任意のシェル実行なし: サーバーは生の adb shell 実行ツールを公開しません。

  • 安全なプロセス呼び出し: すべてのコマンドは child_process.execFile と明示的な引数配列を使用して、シェルインジェクションを防ぎます。

  • 入力のサニタイズ: パッケージ名、キーコード、座標パラメータは、Zod スキーマと境界チェックで厳密に検証されます。

  • stderr 分離ログ: すべてのログは stderr にのみ出力され、stdout で厳格な JSON-RPC プロトコル準拠を維持します。


📄 ライセンス

MIT

Available Tools

13 tools
android_click_elementB

Find and click a UI element on the current Android screen by its visible text, content description, or resource ID. Computes the center of the element and executes a precise tap.

Inputs: text, deviceId, className, exactMatch, +2 more.

android_current_appA

Get the package name and activity of the currently focused foreground Android application.

Inputs: deviceId.

android_device_infoA

Get detailed information about the connected Android device, including device ID, model, manufacturer, Android OS version, SDK level, and screen resolution.

Inputs: deviceId.

android_execute_actionC

Execute a high-level Android action in a single tool call. Supports tap, swipe, type, press_key, click_element, scroll, and launch_app.

Inputs: action (required), x, y, x1, +13 more.

android_find_elementA

Search for UI elements on the current Android screen by visible text, content description, resource ID, or class name. Returns matching elements with their computed center tap coordinates.

Inputs: text, deviceId, className, clickable, +3 more.

android_launch_appB

Launch an Android application by its package name (e.g. "com.android.settings", "com.google.android.youtube", "com.android.chrome").

Inputs: packageName (required), activity, deviceId.

android_press_keyC

Press an Android hardware or navigation key. Supported keys include: HOME, BACK, CALL, ENDCALL, VOLUME_UP, VOLUME_DOWN, POWER, CAMERA, CLEAR, COMMA, PERIOD, TAB, SPACE, ENTER, DELETE, etc.

Inputs: key (required), deviceId.

android_screenshotA

Capture the current screen of the Android device as a PNG image for visual inspection and AI computer-use reasoning.

Inputs: deviceId.

android_scrollB

Scroll the screen in a specified direction (up, down, left, right).

Inputs: direction (required), amount, deviceId.

android_swipeA

Perform a swipe / drag gesture between two points (x1, y1) and (x2, y2) with a configurable duration.

Inputs: x1 (required), x2 (required), y1 (required), y2 (required), +2 more.

android_tapB

Tap at specific (x, y) pixel coordinates on the Android device screen.

Inputs: x (required), y (required), deviceId.

android_type_textA

Type text into the currently focused Android input field. Handles escaping for spaces and special characters.

Inputs: text (required), deviceId.

android_ui_dumpA

Dump the current Android screen UI hierarchy using UIAutomator. Returns a structured, compact list of visible and interactive UI elements with their text, resource IDs, and screen bounds.

Inputs: deviceId.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 13 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes, but android_tap, android_click_element, and android_execute_action overlap in interaction, differing only by abstraction level (raw coordinates, element-based, and high-level bundling). Descriptions help disambiguate these, so the overlap is minor.

    Naming Consistency3/5

    All tools share the 'android_' prefix, which is good, but the naming pattern is inconsistent: some are bare nouns (screenshot, scroll), some are verb phrases (type_text, launch_app), and some are noun phrases (current_app, device_info). This mix of conventions is still readable but not fully predictable.

    Tool Count5/5

    With 13 tools, the server is well-scoped for a mobile automation domain, offering both low-level gestures and high-level actions without redundancy. This count is appropriate and each tool earns its place.

    Completeness4/5

    The tool surface covers core UI automation: screen capture, interaction (tap, swipe, type, press, scroll), element discovery (ui_dump, find_element, click_element), and app control (launch_app, current_app). Missing advanced gestures like pinch or long-press, but these are not essential for typical agent tasks.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers