android_list_packages
Retrieve installed packages on an Android device to identify applications, manage software, or troubleshoot issues. Optionally filter results by package name or target specific devices.
Instructions
List installed packages on the Android device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Optional filter to search for specific packages (case-insensitive) | |
| deviceSerial | No | Specific device serial number to target (optional) |
Implementation Reference
- src/handlers.ts:235-255 (handler)The main handler function for the 'android_list_packages' tool. It processes input arguments, calls the ADB wrapper's listPackages method, formats the result into MCP response format, and handles errors.export async function listPackagesHandler( adb: ADBWrapper, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { const { filter, deviceSerial } = args as ListPackagesArgs; try { const packages = await adb.listPackages(filter, deviceSerial); return { content: [ { type: 'text', text: `Found ${packages.length} packages${filter ? ` matching "${filter}"` : ''}:\n${packages.join('\n')}`, }, ], }; } catch (error) { throw new Error(`List packages failed: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:138-154 (schema)Tool schema definition for 'android_list_packages', including name, description, and input schema, returned by ListToolsRequest handler.{ name: 'android_list_packages', description: 'List installed packages on the Android device', inputSchema: { type: 'object', properties: { filter: { type: 'string', description: 'Optional filter to search for specific packages (case-insensitive)', }, deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, }, },
- src/index.ts:472-473 (registration)Registration and dispatch in the CallToolRequest switch statement, mapping 'android_list_packages' to the listPackagesHandler function.case 'android_list_packages': return await listPackagesHandler(this.adb, args);
- src/handlers.ts:29-32 (schema)TypeScript interface defining the expected input shape for the android_list_packages handler arguments.interface ListPackagesArgs { filter?: string; deviceSerial?: string; }
- src/adb-wrapper.ts:379-393 (helper)Core utility method in ADBWrapper that executes the ADB command 'pm list packages', parses the output to extract package names, and applies optional case-insensitive filtering.async listPackages(filter?: string, deviceSerial?: string): Promise<string[]> { const device = await this.getTargetDevice(deviceSerial); const { stdout } = await this.exec(['shell', 'pm', 'list', 'packages'], device); const packages = stdout .split('\n') .map(line => line.replace('package:', '').trim()) .filter(pkg => pkg.length > 0); if (filter) { return packages.filter(pkg => pkg.toLowerCase().includes(filter.toLowerCase())); } return packages; }