adb_push
Transfer base64-encoded files from a system to a specified path on Android devices using ADB commands, with optional device ID targeting for precise operations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | No | Specific device ID (optional) | |
| fileBase64 | Yes | Base64 encoded file content to push | |
| remotePath | Yes | Remote file path on the device |
Implementation Reference
- src/index.ts:627-661 (handler)The handler function that executes the adb_push tool: decodes base64 file content to a temporary file, pushes it to the device using adb push, handles success/error, and cleans up.async (args: z.infer<typeof AdbPushSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Pushing file to device: ${args.remotePath}`); const deviceArgs = buildDeviceArgs(args.device); const tempFilePath = createTempFilePath("adb-mcp", basename(args.remotePath)); try { // Decode the base64 file data and write to temporary file const fileData = Buffer.from(args.fileBase64, 'base64'); await writeFilePromise(tempFilePath, fileData); // Push the temporary file to the device const remotePath = args.remotePath.trim(); if (!remotePath) { throw new Error("Remote path must not be empty"); } const result = await executeAdbCommand([...deviceArgs, "push", tempFilePath, remotePath], "Error pushing file"); if (!result.isError) { log(LogLevel.INFO, `File pushed to device successfully: ${remotePath}`); } return result; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); log(LogLevel.ERROR, `Error pushing file: ${errorMsg}`); return { content: [{ type: "text" as const, text: `Error pushing file: ${errorMsg}` }], isError: true }; } finally { // Clean up the temporary file await cleanupTempFile(tempFilePath); } },
- src/types.ts:68-72 (schema)Zod input schema defining parameters for adb_push: fileBase64 (required), remotePath (required), device (optional).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)") };
- src/types.ts:107-107 (schema)Main schema for adb_push tool created by wrapping adbPushInputSchema with z.object().export const AdbPushSchema = z.object(adbPushInputSchema);
- src/index.ts:624-663 (registration)Registers the adb_push tool on the MCP server with server.tool(), using the tool name, AdbPushSchema.shape for input validation, the handler function, and ADB_PUSH_TOOL_DESCRIPTION.server.tool( "adb_push", AdbPushSchema.shape, async (args: z.infer<typeof AdbPushSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Pushing file to device: ${args.remotePath}`); const deviceArgs = buildDeviceArgs(args.device); const tempFilePath = createTempFilePath("adb-mcp", basename(args.remotePath)); try { // Decode the base64 file data and write to temporary file const fileData = Buffer.from(args.fileBase64, 'base64'); await writeFilePromise(tempFilePath, fileData); // Push the temporary file to the device const remotePath = args.remotePath.trim(); if (!remotePath) { throw new Error("Remote path must not be empty"); } const result = await executeAdbCommand([...deviceArgs, "push", tempFilePath, remotePath], "Error pushing file"); if (!result.isError) { log(LogLevel.INFO, `File pushed to device successfully: ${remotePath}`); } return result; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); log(LogLevel.ERROR, `Error pushing file: ${errorMsg}`); return { content: [{ type: "text" as const, text: `Error pushing file: ${errorMsg}` }], isError: true }; } finally { // Clean up the temporary file await cleanupTempFile(tempFilePath); } }, { description: ADB_PUSH_TOOL_DESCRIPTION } );