android_list_packages
List installed packages on Android devices to identify applications and manage software inventory. 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 primary handler function that processes the android_list_packages tool call, invokes the ADB wrapper's listPackages method, and formats the response as MCP content.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/adb-wrapper.ts:379-393 (helper)Core helper method in ADBWrapper that executes 'adb shell pm list packages', parses the output to extract package names, applies optional filtering, and returns the list of installed packages.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; }
- src/index.ts:139-154 (schema)Tool schema definition including name, description, and input schema for the android_list_packages tool, returned by ListToolsRequestHandler.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)Dispatch/registration of the android_list_packages tool handler in the CallToolRequestSchema switch statement.case 'android_list_packages': return await listPackagesHandler(this.adb, args);
- src/handlers.ts:29-32 (schema)TypeScript interface defining the input arguments for the listPackagesHandler.interface ListPackagesArgs { filter?: string; deviceSerial?: string; }