get_current_activity
Retrieve the currently focused Android app and activity for debugging, UI testing, or workflow automation.
Instructions
Get the currently focused app and activity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:563-584 (handler)The main handler function for the 'get_current_activity' tool, decorated with @mcp.tool() for automatic registration in the MCP server. It executes ADB command to dump activity info, parses for the focused package/activity using regex, and returns a dict with package, activity, and full_component.@mcp.tool() def get_current_activity(device_serial: str | None = None) -> dict: """Get the currently focused app and activity""" output = run_adb(["shell", "dumpsys", "activity", "activities"], device_serial) result = { "package": None, "activity": None, "full_component": None } # Look for ResumedActivity or mFocusedActivity for line in output.split('\n'): if 'ResumedActivity' in line or 'mFocusedActivity' in line: match = re.search(r'([a-zA-Z0-9_.]+)/([a-zA-Z0-9_.]+)', line) if match: result['package'] = match.group(1) result['activity'] = match.group(2) result['full_component'] = f"{match.group(1)}/{match.group(2)}" break return result