android_execute_command
Execute custom ADB commands on Android devices to perform device management, debugging, and automation tasks through the Android MCP Server.
Instructions
Execute a generic ADB command with custom arguments. Allows agents to run any ADB command with their own parameters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes | Array of ADB command arguments (e.g., ["shell", "pm", "list", "packages"] or ["logcat", "-d", "-s", "MyTag"]) | |
| deviceSerial | No | Specific device serial number to target (optional) |
Implementation Reference
- src/handlers.ts:724-749 (handler)Main handler function for 'android_execute_command' tool. Validates input args, executes the ADB command via ADBWrapper.executeCommand, and formats stdout/stderr as response content.export async function handleExecuteCommand(adb: ADBWrapper, args: ExecuteCommandArgs): Promise<{ content: Array<{ type: string; text: string }> }> { const { args: adbArgs, deviceSerial } = args; if (!adbArgs || !Array.isArray(adbArgs) || adbArgs.length === 0) { throw new Error('args parameter is required and must be a non-empty array'); } try { const { stdout, stderr } = await adb.executeCommand(adbArgs, deviceSerial); let output = ''; if (stdout) output += `stdout:\n${stdout}`; if (stderr) output += `${output ? '\n\n' : ''}stderr:\n${stderr}`; return { content: [ { type: 'text', text: output || 'Command executed successfully (no output)', }, ], }; } catch (error) { throw new Error(`Failed to execute ADB command: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:435-454 (schema)JSON schema definition for the 'android_execute_command' tool input, including required 'args' array and optional 'deviceSerial'.name: 'android_execute_command', description: 'Execute a generic ADB command with custom arguments. Allows agents to run any ADB command with their own parameters.', inputSchema: { type: 'object', properties: { args: { type: 'array', items: { type: 'string', }, description: 'Array of ADB command arguments (e.g., ["shell", "pm", "list", "packages"] or ["logcat", "-d", "-s", "MyTag"])', }, deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, required: ['args'], }, },
- src/index.ts:506-507 (registration)Registration of the tool handler in the MCP server's CallToolRequestSchema switch statement, dispatching to handleExecuteCommand.case 'android_execute_command': return await handleExecuteCommand(this.adb, args as any);
- src/adb-wrapper.ts:416-419 (helper)Helper method in ADBWrapper that executes the generic ADB command by calling the private exec method, handling device targeting.async executeCommand(args: string[], deviceSerial?: string): Promise<{ stdout: string; stderr: string }> { const device = deviceSerial ? await this.getTargetDevice(deviceSerial) : undefined; return await this.exec(args, device); }
- src/handlers.ts:719-722 (schema)TypeScript interface defining the input arguments for the handleExecuteCommand function.interface ExecuteCommandArgs { args: string[]; deviceSerial?: string; }