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
| Name | Required | Description | Default |
|---|---|---|---|
| apk_path | Yes | ||
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:674-677 (handler)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)
- src/adb_mcp_server/server.py:24-40 (helper)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)}"
- src/adb_mcp_server/server.py:18-18 (registration)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")