Skip to main content
Glama

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

Implementation Reference

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

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