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
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes | Android package name to resolve pid via adb shell pidof -s | |
| timeoutMs | No | Timeout 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
- src/tools/logcatTool.js:200-211 (registration)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 }] }; } );
- src/tools/logcatTool.js:48-57 (schema)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') });
- src/tools/logcatTool.js:135-142 (helper)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);
- src/tools/logcatTool.js:207-209 (handler)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 }] };