list_apps
Retrieve installed applications on an Android device by providing the device serial number. This tool supports app development by enabling access to app listings for preference management.
Instructions
Lists apps installed on device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | Yes | The device's serial number. |
Implementation Reference
- src/tools/common.ts:38-59 (handler)The handler function for the list_apps tool. It validates the input connection (deviceId), calls listApps from the external library, and formats the app package names as text content. Handles errors by returning an error response.async (connection: z.infer<typeof DeviceSchema>) => { try { validate(connection, DeviceSchema); return { content: (await listApps(connection)).map((app) => ({ type: "text", text: app.packageName, })), }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; } }
- src/schema.ts:3-5 (schema)DeviceSchema defines the input schema for list_apps, requiring a deviceId string.export const DeviceSchema = z.object({ deviceId: z.string().describe("The device's serial number."), });
- src/tools/common.ts:34-60 (registration)Registers the list_apps tool on the MCP server within configureCommonTools, specifying name, description, input schema (DeviceSchema.shape), and the handler function.server.tool( "list_apps", "Lists apps installed on device", DeviceSchema.shape, async (connection: z.infer<typeof DeviceSchema>) => { try { validate(connection, DeviceSchema); return { content: (await listApps(connection)).map((app) => ({ type: "text", text: app.packageName, })), }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; } } );
- src/utils.ts:13-21 (helper)validate function used in the list_apps handler to validate the input against DeviceSchema.export const validate = (input: unknown, type: ZodType) => { const validationResult = type.safeParse(input); if (!validationResult.success) throw new Error( `Invalid input: ${validationResult.error.errors .map((err) => err.message) .join(", ")}` ); };