adb_shell
Execute shell commands on Android devices through the ADB MCP Server to automate device management, app operations, and system tasks remotely.
Instructions
Execute a shell command on the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Shell command to execute | |
| deviceId | No | Device ID (optional) |
Implementation Reference
- src/tools/shell.ts:6-58 (handler)Main handler function for the 'adb_shell' tool. Performs device connection check, blocks dangerous commands, executes the shell command via ADB client, and formats the response.async executeShellCommand(command: string, deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot execute shell command - device is not connected' }; } // Basic security check - prevent potentially dangerous commands const dangerousCommands = [ 'rm -rf /', 'format', 'factory_reset', 'reboot bootloader', 'fastboot', 'dd if=' ]; const lowerCommand = command.toLowerCase(); for (const dangerous of dangerousCommands) { if (lowerCommand.includes(dangerous)) { return { success: false, error: 'Dangerous command blocked', message: `Command contains potentially dangerous operation: ${dangerous}` }; } } const shellCommand = `shell ${command}`; const result = await this.adbClient.executeCommand(shellCommand, deviceId); return { success: result.success, data: { command, output: result.output, error: result.error, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: result.success ? 'Command executed successfully' : 'Command execution failed' }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to execute shell command' }; } }
- src/index.ts:356-372 (schema)Input schema definition for the 'adb_shell' tool, including parameters for command and optional deviceId.name: 'adb_shell', description: 'Execute a shell command on the device', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Shell command to execute', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: ['command'], }, },
- src/index.ts:473-474 (registration)Registration of the 'adb_shell' tool handler in the switch statement for CallToolRequest, dispatching to ShellTools.executeShellCommand.case 'adb_shell': return await this.handleToolCall(this.shellTools.executeShellCommand(args?.command as string, args?.deviceId as string));