Skip to main content
Glama

android-mcp-toolkit

get-pid-by-package

Find the process ID (PID) of an Android app package using adb shell pidof command for debugging and monitoring purposes.

Instructions

Resolve process id for a package via adb shell pidof -s.

Input Schema

NameRequiredDescriptionDefault
packageNameYesAndroid package name to resolve pid via adb shell pidof -s
timeoutMsNoTimeout per adb call in milliseconds

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "packageName": { "description": "Android package name to resolve pid via adb shell pidof -s", "minLength": 1, "type": "string" }, "timeoutMs": { "default": 5000, "description": "Timeout per adb call in milliseconds", "maximum": 15000, "minimum": 1000, "type": "integer" } }, "required": [ "packageName" ], "type": "object" }

Implementation Reference

  • Registration of the 'get-pid-by-package' tool on the MCP server, including inline handler that calls resolvePid.
    server.registerTool( 'get-pid-by-package', { title: 'Get pid by package', description: 'Resolve process id for a package via adb shell pidof -s.', inputSchema: pidInputSchema }, async params => { const pid = await resolvePid(params.packageName, params.timeoutMs); return { content: [{ type: 'text', text: pid }] }; } );
  • Zod input schema for the get-pid-by-package tool defining packageName and timeoutMs.
    const pidInputSchema = z.object({ packageName: z.string().min(1).describe('Android package name to resolve pid via adb shell pidof -s'), timeoutMs: z .number() .int() .min(1000) .max(15000) .default(5000) .describe('Timeout per adb call in milliseconds') });
  • Helper function that executes the core logic: runs adb shell pidof -s to get PID for the package.
    async function resolvePid(packageName, timeoutMs) { const output = await runAdbCommand(['shell', 'pidof', '-s', packageName], timeoutMs); const pid = output.split(/\s+/).find(Boolean); if (!pid) { throw new Error(`Could not resolve pid for package ${packageName}`); } return pid; }
  • src/index.js:21-21 (registration)
    Invocation of registerLogcatTool which includes registration of get-pid-by-package.
    registerLogcatTool(server);
  • Inline handler function for get-pid-by-package tool that resolves PID and returns it as text.
    async params => { const pid = await resolvePid(params.packageName, params.timeoutMs); return { content: [{ type: 'text', text: pid }] };

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