droidmind

repository·main·Indexed 19 days ago

https://github.com/hyperb1iss/droidmind

An MCP (Model Context Protocol) server that enables AI assistants to control, debug, and analyze Android devices via ADB using natural language. It provides capabilities for device management, system analysis (logcat, bug reports), file management, app control, UI automation, and shell execution. Supports stdio and SSE transport modes and can be deployed via uvx, source installation, or Docker.

Tokens
23.1K
Snippets
102
Records
131
Agent score
59%

What's inside droidmind

  1. What is DroidMind?

    main

    DroidMind is an MCP (Model Context Protocol) server that exposes Android Debug Bridge (ADB) functionalities as tools and resources. It allows AI assistants (such as Claude, Cursor, and other MCP-compatible clients) to interact directly with Android devices using natural language.

    Key capabilities include:

    • Direct Device Control: Executing commands, managing files, and automating UI interactions.
    • Analysis and Diagnosis: Retrieving logs, inspecting device properties, and capturing diagnostic information.
    • Workflow Integration: Seamlessly integrating device interactions into AI-driven development loops.
  2. Overview of DroidMind capabilities

    main
    DroidMind is a tool designed to allow users to interact with Android devices using natural language via an AI assistant. It provides a bridge between AI reasoning and low-level Android device control, covering device connectivity, diagnostics, file management, application control, shell execution, and UI automation.
  3. Core Capabilities of DroidMind

    main

    DroidMind provides an AI assistant with the following capabilities via the Model Context Protocol (MCP):

    • Device Management: Connect via USB/TCP-IP, list devices, view properties, and reboot.
    • System Analysis: Access logs (logcat, ANR, crash, battery), capture bug reports, and dump heap.
    • File Management: Browse, read, write, push, pull, delete, and manage device files/directories.
    • App Control: Install, uninstall, start, stop, clear data, and inspect app details (manifest, permissions, activities).
    • UI Automation: Perform taps, swipes, text input, and key presses.
    • Shell Execution: Run ADB shell commands within a security-conscious framework.
    • Security: Built-in command validation, risk assessment, and sanitization.
  4. Understand DroidMind command risk assessment

    main

    DroidMind evaluates shell commands using a built-in security system to prevent accidental damage.

    Risk Levels

    Commands are categorized into: SAFE, LOW, MEDIUM, HIGH, and CRITICAL.

    • Allowed Commands: Generally safe utilities like ls, cat, ps, dumpsys, and getprop.
    • Disallowed/Blocked Commands: Destructive commands (e.g., rm -rf /, mkfs, or direct reboot via shell) are typically blocked.
    • Suspicious Patterns: Commands attempting to write to protected system paths (like /system) or containing patterns like rm -rf /system are flagged.

    Security Responses

    • High/Critical Risk: DroidMind will prepend a warning to the output: ⚠️ WARNING: This command has been assessed as HIGH risk.
    • Security Rejection: If a command is explicitly disallowed by policy, DroidMind returns an error: Error: Command rejected for security reasons: Command '[command]' is explicitly disallowed for security reasons.
  5. Identify device serials for targeting

    main

    The serial number is the unique identifier used to target specific devices when multiple connections are present. DroidMind uses these strings to distinguish between different hardware or instances.

    Serial Formats:

    • Physical USB Devices: A unique alphanumeric string (e.g., 1A2B3C4D5E6F or R5CR707QL9X).
    • Emulators: Typically follow the pattern emulator-XXXX (e.g., emulator-5554).
    • Networked Devices (TCP/IP): Formatted as ip_address:port (e.g., 192.168.1.123:5555).

    You must provide the correct serial when the AI assistant prompts for a device or when initiating specific commands.

  6. Understand DroidMind's command validation and sanitization

    main

    DroidMind implements several layers of protection to prevent accidental or malicious damage to Android devices. All commands, particularly shell commands, undergo the following checks:

    • Allowed Command List: Commands like ls, ps, getprop, and dumpsys are considered safe for diagnostics.
    • Disallowed Command List: Inherently dangerous or destructive commands (e.g., mkfs, certain setprop calls, or direct reboot via shell) are explicitly blocked.
    • Suspicious Pattern Detection: DroidMind scans for patterns such as attempts to delete critical system files (e.g., rm -rf /system), writing to protected partitions, or command chaining designed to bypass safety checks.
    • Input Sanitization: Inputs are sanitized to prevent injection attacks.

    If a command fails these checks, DroidMind will refuse execution and return an error message.

    Error: Command rejected for security reasons: Command 'setprop' is explicitly disallowed for security reasons.
  7. Identify protected paths and privilege constraints

    main

    DroidMind applies specific restrictions based on file paths and device permissions:

    Protected Paths

    Operations targeting critical system paths are heavily scrutinized:

    • Paths: /system, /vendor, /product, /proc, /dev, etc.
    • Read-only operations (e.g., ls, cat) on these paths are permitted but flagged as MEDIUM or HIGH risk.
    • Write operations or modifications to these paths are generally disallowed or flagged as CRITICAL risk and blocked.

    Principle of Least Privilege

    DroidMind's capabilities are limited by the permissions of the ADB daemon on the device:

    • Non-Rooted Devices: DroidMind cannot perform operations requiring root privileges.
    • Rooted Devices: If ADB is configured to run as root, DroidMind inherits these elevated privileges. Use extreme caution in this configuration as the impact of any command is significantly increased.
  8. Handle shell command output truncation

    main

    To prevent overwhelming the AI or terminal, DroidMind enforces limits on command output. If a command exceeds these limits, DroidMind appends a truncation note to the end of the output.

    Limits

    • max_lines: Controls line count. Default is 1000. Use positive values for the start of output and negative values for the end.
    • max_size: Controls total character count. Default is 100,000 characters.

    Truncation Indicators

    When output is cut off, you will see messages such as:

    • [Output truncated: 100000 chars, 1500 lines]
    • [Command output truncated: 1500 lines, 97.7 KB]
  9. Quickstart for IDEs (Zero Install with `uvx`)

    main

    You can integrate DroidMind with MCP-compatible IDEs (like Cursor) without manually cloning or installing the repository by using uvx. This method allows the IDE to launch DroidMind directly from its GitHub repository.

    To set this up, add the following configuration to your IDE's MCP settings (for example, .cursor/mcp.json in Cursor):

    {
      "mcpServers": {
        "droidmind": {
          "command": "uvx",
          "args": [
            "--from",
            "git+https://github.com/hyperb1iss/droidmind",
            "droidmind",
            "--transport",
            "stdio"
          ]
        }
      }
    }

    Note: stdio is the default and preferred transport mode for most IDE integrations.

    {
      "mcpServers": {
        "droidmind": {
          "command": "uvx",
          "args": [
            "--from",
            "git+https://github.com/hyperb1iss/droidmind",
            "droidmind",
            "--transport",
            "stdio"
          ]
        }
      }
    }
  10. Prerequisites for DroidMind

    main

    Before setting up DroidMind, ensure your environment meets the following requirements:

    • Python & UV: Python 3.13 must be installed. Note that Python 3.14 is not yet supported. The uv package manager is required as DroidMind uses uvx for zero-install integration.
    • AI Assistant with MCP Support: An AI client that supports the Model Context Protocol (MCP), such as Claude Desktop or Cursor.
    • Android Device/Emulator: A physical Android device connected via USB (with USB debugging enabled) or an active emulator. For network connections, ADB over TCP/IP must be configured.
    • ADB: The Android Debug Bridge (ADB) must be installed and available in your system's PATH.
  11. Connect to Android devices via ADB over TCP/IP in Docker

    main

    Connecting USB devices directly to a Docker container is complex. The recommended approach is to use ADB over TCP/IP on your Android device. This allows the container to connect to the device over your local network.

    Setup Steps:

    1. Enable ADB over TCP/IP on the device:
      • Connect device via USB to host.
      • Find device IP (e.g., 192.168.1.50).
      • Run adb tcpip 5555 from your host.
      • Disconnect USB.
      • Run adb connect <device_ip_address>:5555 from your host to verify.
    2. Connect via DroidMind:
      • Once DroidMind is running in the container, use its connect_device tool via your AI assistant to connect to <device_ip_address>:5555.
  12. Handle high-risk operations via AI assistant confirmation

    main

    DroidMind is a server and does not prompt for user confirmation directly. Instead, it relies on the AI assistant (the MCP client) to implement a confirmation workflow based on DroidMind's risk assessments.

    Recommended Workflow for AI Assistants:

    1. DroidMind flags a tool call as HIGH or CRITICAL risk.
    2. The AI assistant intercepts this risk assessment.
    3. The AI assistant presents the risk to the user and asks for explicit approval (e.g., Are you sure you want to proceed? (yes/no)).
    4. The AI assistant only proceeds with the instruction if the user provides confirmation.