adb_shell
Execute shell commands on Android devices remotely using ADB functionality, enabling device management, app control, and file operations via the ADB MCP Server.
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)The `executeShellCommand` method in ShellTools class implements the core logic of the `adb_shell` tool. It performs device connectivity checks, blocks dangerous commands, executes the shell command via ADB, and returns structured output including success status, data, and error messages.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)Defines the tool specification including name, description, and input schema for `adb_shell` in the ListTools response.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)Registers the `adb_shell` tool handler in the CallToolRequest switch statement by delegating to ShellTools.executeShellCommand.case 'adb_shell': return await this.handleToolCall(this.shellTools.executeShellCommand(args?.command as string, args?.deviceId as string));