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
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | Device serial number |
Implementation Reference
- src/adb/app-manager.ts:117-129 (handler)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'; } - src/controllers/app-tools.ts:171-189 (registration)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), }], }; }); }