adb_pull
Extract files from Android devices to your computer using ADB commands. Specify the remote file path on the device to transfer data for analysis or backup.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| remotePath | Yes | Remote file path on the device | |
| device | No | Specific device ID (optional) | |
| asBase64 | No | Return file content as base64 (default: true) |
Implementation Reference
- src/index.ts:574-620 (handler)The main execution logic for the adb_pull tool: runs adb pull to fetch remote file to temp local file, returns base64 encoded content by default or stdout, handles cleanup and errors.async (args: z.infer<typeof AdbPullSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Pulling file from device: ${args.remotePath}`); const deviceArgs = buildDeviceArgs(args.device); const tempFilePath = createTempFilePath("adb-mcp", basename(args.remotePath)); try { // Pull the file from the device const remotePath = args.remotePath.trim(); if (!remotePath) { throw new Error("Remote path must not be empty"); } const { stdout, stderr } = await runAdb([...deviceArgs, "pull", remotePath, tempFilePath]); if (stderr) { log(LogLevel.WARN, `adb pull reported stderr: ${stderr}`); } // If asBase64 is true (default), read the file and return as base64 if (args.asBase64 !== false) { const fileData = await readFilePromise(tempFilePath); const base64Data = fileData.toString('base64'); log(LogLevel.INFO, `File pulled from device successfully: ${remotePath}`); return { content: [{ type: "text" as const, text: base64Data }] }; } else { // Otherwise return the pull operation result log(LogLevel.INFO, `File pulled from device successfully: ${remotePath}`); return { content: [{ type: "text" as const, text: stdout }] }; } } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); log(LogLevel.ERROR, `Error pulling file: ${errorMsg}`); return { content: [{ type: "text" as const, text: `Error pulling file: ${errorMsg}` }], isError: true }; } finally { // Clean up the temporary file await cleanupTempFile(tempFilePath); } }, { description: ADB_PULL_TOOL_DESCRIPTION }
- src/index.ts:571-621 (registration)Registers the adb_pull tool on the MCP server with name, input schema, handler function, and description.server.tool( "adb_pull", AdbPullSchema.shape, async (args: z.infer<typeof AdbPullSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Pulling file from device: ${args.remotePath}`); const deviceArgs = buildDeviceArgs(args.device); const tempFilePath = createTempFilePath("adb-mcp", basename(args.remotePath)); try { // Pull the file from the device const remotePath = args.remotePath.trim(); if (!remotePath) { throw new Error("Remote path must not be empty"); } const { stdout, stderr } = await runAdb([...deviceArgs, "pull", remotePath, tempFilePath]); if (stderr) { log(LogLevel.WARN, `adb pull reported stderr: ${stderr}`); } // If asBase64 is true (default), read the file and return as base64 if (args.asBase64 !== false) { const fileData = await readFilePromise(tempFilePath); const base64Data = fileData.toString('base64'); log(LogLevel.INFO, `File pulled from device successfully: ${remotePath}`); return { content: [{ type: "text" as const, text: base64Data }] }; } else { // Otherwise return the pull operation result log(LogLevel.INFO, `File pulled from device successfully: ${remotePath}`); return { content: [{ type: "text" as const, text: stdout }] }; } } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); log(LogLevel.ERROR, `Error pulling file: ${errorMsg}`); return { content: [{ type: "text" as const, text: `Error pulling file: ${errorMsg}` }], isError: true }; } finally { // Clean up the temporary file await cleanupTempFile(tempFilePath); } }, { description: ADB_PULL_TOOL_DESCRIPTION } );
- src/types.ts:62-106 (schema)Zod schema definition for adb_pull tool input validation: remotePath (required), device (opt), asBase64 (opt default true).export const adbPullInputSchema = { remotePath: z.string().describe("Remote file path on the device"), device: z.string().optional().describe("Specific device ID (optional)"), asBase64: z.boolean().optional().default(true).describe("Return file content as base64 (default: true)") }; export const adbPushInputSchema = { fileBase64: z.string().describe("Base64 encoded file content to push"), remotePath: z.string().describe("Remote file path on the device"), device: z.string().optional().describe("Specific device ID (optional)") }; export const dumpImageInputSchema = { device: z.string().optional().describe("Specific device ID (optional)"), asBase64: z.boolean().optional().default(false).describe("Return image as base64 (default: false)") }; export const inspectUiInputSchema = { device: z.string().optional().describe("Specific device ID (optional)"), outputPath: z.string().optional().describe("Custom output path on device (default: /sdcard/window_dump.xml)"), asBase64: z.boolean().optional().default(false).describe("Return XML content as base64 (default: false)") }; // Activity Manager tool schema export const adbActivityManagerSchema = z.object({ amCommand: z.string().describe("Activity Manager subcommand, e.g. 'start', 'broadcast', 'force-stop', etc."), amArgs: z.string().optional().describe("Arguments for the am subcommand, e.g. '-a android.intent.action.VIEW'"), device: z.string().optional().describe("Specific device ID (optional)") }); // Package Manager tool schema export const adbPackageManagerSchema = z.object({ pmCommand: z.string().describe("Package Manager subcommand, e.g. 'list', 'install', 'uninstall', 'grant', 'revoke', etc."), pmArgs: z.string().optional().describe("Arguments for the pm subcommand, e.g. 'packages', 'com.example.app android.permission.CAMERA'"), device: z.string().optional().describe("Specific device ID (optional)") }); // Zod schema objects export const AdbDevicesSchema = z.object(adbDevicesInputSchema); export const AdbShellSchema = z.object(adbShellInputSchema); export const AdbInstallSchema = z.object(adbInstallInputSchema); export const AdbLogcatSchema = z.object(adbLogcatInputSchema); export const AdbPullSchema = z.object(adbPullInputSchema);
- src/types.ts:118-118 (schema)TypeScript type definition inferred from AdbPullSchema for adb_pull inputs.export type AdbPullInput = z.infer<typeof AdbPullSchema>;