Created
August 18, 2025 00:08
-
-
Save lethargicpanda/f63877e78822c85062f43b9930ab6fb6 to your computer and use it in GitHub Desktop.
Experimental ADB MCP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mcp.server.fastmcp import FastMCP | |
import subprocess | |
# Create an MCP server | |
mcp = FastMCP("ADB MCP") | |
@mcp.tool() | |
def get_devices() -> str: | |
"""Get the list of Android devices connected to the laptop""" | |
result = subprocess.run(['adb', 'devices'], capture_output=True, text=True) | |
return result.stdout | |
@mcp.tool() | |
def get_apps() -> str: | |
"""Use ADB to get the list of all the apps installed on a specific Android devices connected to the laptop. | |
Search through the output of this list to confirm if an app is installed.""" | |
result = subprocess.run(['adb', 'shell', 'pm', 'list', 'packages'], capture_output=True, text=True) | |
if result.returncode != 0: | |
return f"Error: {result.stderr}" | |
return result.stdout | |
@mcp.tool() | |
def open_app(package_name: str) -> str: | |
"""Open an app on the connected Android device using its package name via ADB.""" | |
# The command to launch the main activity of the app | |
cmd = [ | |
'adb', 'shell', 'monkey', '-p', package_name, '-c', 'android.intent.category.LAUNCHER', '1' | |
] | |
result = subprocess.run(cmd, capture_output=True, text=True) | |
if result.returncode != 0: | |
return f"Error opening app: {result.stderr.strip()}" | |
return f"App '{package_name}' launched successfully." | |
if __name__ == "__main__": | |
mcp.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment