Skip to main content
Glama

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
NameRequiredDescriptionDefault
argsYesArray of ADB command arguments (e.g., ["shell", "pm", "list", "packages"] or ["logcat", "-d", "-s", "MyTag"])
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • 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)}`); } }
  • 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);
  • 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); }
  • TypeScript interface defining the input arguments for the handleExecuteCommand function.
    interface ExecuteCommandArgs { args: string[]; deviceSerial?: 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/jduartedj/android-mcp-server'

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