Skip to main content
Glama

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
NameRequiredDescriptionDefault
commandYesShell command to execute
deviceIdNoDevice ID (optional)

Implementation Reference

  • 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' }; } }
  • 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));

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/richard0913/adb-mcp'

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