Skip to main content
Glama

get_current_app

Retrieve the package name of the foreground Android application to identify active apps for automation or monitoring purposes.

Instructions

Get the package name of the currently focused/foreground Android application.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNoDevice serial number

Implementation Reference

  • The actual implementation of the get_current_app logic using adb dumpsys.
    export async function getCurrentApp(deviceId?: string): Promise<string> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
    
      const result = await adbShell([
        'dumpsys', 'window', 'displays', '|', 'grep', '-E', 'mCurrentFocus|mFocusedApp',
      ], resolved);
    
      // Parse the package name from output like: mCurrentFocus=Window{... com.example.app/...}
      const match = result.stdout.match(/([a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9_]*)+)\//);
      return match ? match[1] : 'unknown';
    }
  • The MCP tool registration for get_current_app.
    server.registerTool(
      'get_current_app',
      {
        description: 'Get the package name of the currently focused/foreground Android application.',
        inputSchema: {
          device_id: z.string().optional().describe('Device serial number'),
        },
      },
      async ({ device_id }) => {
        return await metrics.measure('get_current_app', device_id || 'default', async () => {
          const app = await getCurrentApp(device_id);
          return {
            content: [{
              type: 'text' as const,
              text: JSON.stringify({ success: true, current_app: app }, null, 2),
            }],
          };
        });
      }

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/divineDev-dotcom/android_mcp'

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