adb_pull
Extract files from Android devices via ADB by specifying the remote file path, optional device ID, and base64 encoding preference for efficient file retrieval.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asBase64 | No | Return file content as base64 (default: true) | |
| device | No | Specific device ID (optional) | |
| remotePath | Yes | Remote file path on the device |
Implementation Reference
- src/index.ts:574-619 (handler)The handler function that implements the core logic for the adb_pull tool. It executes 'adb pull' to transfer a file from the device to a temporary local file, then returns the file content as base64-encoded string (default) or the command stdout, with proper error handling and temp file cleanup.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); } },
- src/index.ts:571-621 (registration)Registration of the 'adb_pull' tool with the MCP server using server.tool(), specifying the tool 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-66 (schema)Zod input schema definition for the adb_pull tool parameters.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)") };
- src/types.ts:106-106 (schema)Zod schema object for adb_pull tool, wrapping the input schema for validation.export const AdbPullSchema = z.object(adbPullInputSchema);
- src/index.ts:285-287 (helper)Helper function used in the handler to build device-specific arguments for ADB commands.function buildDeviceArgs(device?: string): string[] { return device ? ["-s", device] : []; }