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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions executing commands but lacks details on behavioral traits like permissions required, error handling, safety risks (e.g., destructive commands), or output format. This is a significant gap for a tool that could perform arbitrary operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded and concise, with two sentences that directly state the purpose and flexibility. Every sentence earns its place by clarifying the tool's role without unnecessary elaboration, making it efficient for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing arbitrary ADB commands, no annotations, and no output schema, the description is incomplete. It doesn't address critical aspects like command safety, expected outputs, or integration with sibling tools, leaving gaps that could hinder effective agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond stating it's for 'custom arguments,' which aligns with the schema but doesn't provide extra context like common use cases or constraints. Baseline 3 is appropriate here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Execute a generic ADB command with custom arguments.' It specifies the verb ('Execute') and resource ('ADB command'), distinguishing it from sibling tools that perform specific actions like screenshot or input. However, it doesn't explicitly differentiate from all siblings, as some might also involve ADB commands indirectly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by stating it 'Allows agents to run any ADB command with their own parameters,' suggesting it's for custom or unsupported commands. It doesn't provide explicit when-to-use vs. alternatives, such as preferring specific sibling tools for common tasks, leaving usage context somewhat implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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