Skip to main content
Glama
rahulkr
by rahulkr

install_apk

Install APK files on Android devices through ADB commands for app deployment, testing, and development workflows.

Instructions

Install an APK file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apk_pathYes
device_serialNo

Implementation Reference

  • The main handler function implementing the 'install_apk' MCP tool. It uses the run_adb helper to execute 'adb install -r' on the specified APK path, optionally targeting a specific device serial. The @mcp.tool() decorator registers it as an MCP tool.
    @mcp.tool()
    def install_apk(apk_path: str, device_serial: str | None = None) -> str:
        """Install an APK file"""
        return run_adb(["install", "-r", apk_path], device_serial)
  • Supporting helper function that executes arbitrary ADB commands via subprocess.run(). Handles device targeting with -s flag, captures output/errors, and manages timeouts. Directly called by the install_apk handler.
    def run_adb(args: list[str], device_serial: str | None = None, timeout: int = 30) -> str:
        """Run an ADB command and return output"""
        cmd = ["adb"]
        if device_serial:
            cmd.extend(["-s", device_serial])
        cmd.extend(args)
        
        try:
            result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
            if result.returncode != 0 and result.stderr:
                return f"Error: {result.stderr}"
            return result.stdout
        except subprocess.TimeoutExpired:
            return "Error: Command timed out"
        except Exception as e:
            return f"Error: {str(e)}"
  • Creation of the FastMCP server instance named 'adb-dev-server'. All @mcp.tool() decorated functions, including install_apk, are automatically registered with this server instance. The server is run via mcp.run() at the end of the file.
    mcp = FastMCP("adb-dev-server")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rahulkr/r_adb_mcp_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server