Skip to main content
Glama
rahulkr
by rahulkr

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
NameRequiredDescriptionDefault
device_serialNo

Implementation Reference

  • 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

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