Skip to main content
Glama

android-mcp-toolkit

get-current-activity

Retrieve the currently focused Android app or window using ADB's dumpsys command. Verify top activity in single-activity apps or identify active windows for debugging and automation tasks.

Instructions

Inspect current focused app/window via dumpsys window (mCurrentFocus/mFocusedApp). Useful even in single-activity apps to verify top window.

Input Schema

NameRequiredDescriptionDefault
timeoutMsNoTimeout per adb call in milliseconds

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "timeoutMs": { "default": 5000, "description": "Timeout per adb call in milliseconds", "maximum": 15000, "minimum": 1000, "type": "integer" } }, "type": "object" }

Implementation Reference

  • Handler function that executes adb shell dumpsys window, filters for current focus info (mCurrentFocus/mFocusedApp), trims to first 8 matching lines.
    async params => { const dump = await runAdbCommand(['shell', 'dumpsys', 'window'], params.timeoutMs); const lines = dump .split('\n') .filter(line => line.includes('mCurrentFocus') || line.includes('mFocusedApp')); const trimmed = lines.slice(0, 8).join('\n').trim(); if (!trimmed) { return { content: [{ type: 'text', text: 'No focus info found in dumpsys window.' }] }; } return { content: [{ type: 'text', text: trimmed }] }; }
  • Zod schema defining the input parameters for the get-current-activity tool (timeoutMs).
    const currentActivityInputSchema = z.object({ timeoutMs: z .number() .int() .min(1000) .max(15000) .default(5000) .describe('Timeout per adb call in milliseconds') });
  • Registration of the get-current-activity tool on the MCP server, specifying name, title, description, input schema, and inline handler function.
    server.registerTool( 'get-current-activity', { title: 'Get current activity/window focus', description: 'Inspect current focused app/window via dumpsys window (mCurrentFocus/mFocusedApp). Useful even in single-activity apps to verify top window.', inputSchema: currentActivityInputSchema }, async params => { const dump = await runAdbCommand(['shell', 'dumpsys', 'window'], params.timeoutMs); const lines = dump .split('\n') .filter(line => line.includes('mCurrentFocus') || line.includes('mFocusedApp')); const trimmed = lines.slice(0, 8).join('\n').trim(); if (!trimmed) { return { content: [{ type: 'text', text: 'No focus info found in dumpsys window.' }] }; } return { content: [{ type: 'text', text: trimmed }] }; } );
  • Utility function to run adb shell commands asynchronously with timeout, capturing stdout and handling errors appropriately.
    async function runAdbCommand(args, timeoutMs) { try { const { stdout } = await execFileAsync('adb', args, { timeout: timeoutMs, maxBuffer: 5 * 1024 * 1024 }); return stdout.trimEnd(); } catch (error) { const stderr = error && typeof error.stderr === 'string' ? error.stderr.trim() : ''; const message = [`adb ${args.join(' ')} failed`, error.message].filter(Boolean).join(': '); if (stderr) { throw new Error(`${message} | stderr: ${stderr}`); } throw new Error(message); } }

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/Nam0101/android-mcp-toolkit'

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