Skip to main content
Glama

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
NameRequiredDescriptionDefault
asBase64NoReturn file content as base64 (default: true)
deviceNoSpecific device ID (optional)
remotePathYesRemote file path on the device

Implementation Reference

  • 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 } );
  • 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)") };
  • Zod schema object for adb_pull tool, wrapping the input schema for validation.
    export const AdbPullSchema = z.object(adbPullInputSchema);
  • Helper function used in the handler to build device-specific arguments for ADB commands.
    function buildDeviceArgs(device?: string): string[] { return device ? ["-s", device] : []; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/srmorete/adb-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server