Skip to main content
Glama

adb_shell

Execute shell commands on Android devices through ADB to perform device management, debugging, and automation tasks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesShell command to execute on the device
deviceNoSpecific device ID (optional)

Implementation Reference

  • The handler function for the 'adb_shell' tool. It logs the command, builds device-specific arguments, validates the command is not empty, and executes the ADB shell command via executeAdbCommand.
    async (args: z.infer<typeof AdbShellSchema>, _extra: RequestHandlerExtra) => {
      log(LogLevel.INFO, `Executing shell command: ${args.command}`);
      
      const deviceArgs = buildDeviceArgs(args.device);
      const trimmedCommand = args.command.trim();
      if (!trimmedCommand) {
        const message = "Shell command must not be empty";
        log(LogLevel.ERROR, message);
        return {
          content: [{ type: "text" as const, text: message }],
          isError: true
        };
      }
    
      return executeAdbCommand([...deviceArgs, "shell", trimmedCommand], "Error executing shell command");
    },
  • src/index.ts:478-497 (registration)
    Registration of the 'adb_shell' tool using server.tool, specifying name, input schema, handler function, and description.
    server.tool(
      "adb_shell",
      AdbShellSchema.shape,
      async (args: z.infer<typeof AdbShellSchema>, _extra: RequestHandlerExtra) => {
        log(LogLevel.INFO, `Executing shell command: ${args.command}`);
        
        const deviceArgs = buildDeviceArgs(args.device);
        const trimmedCommand = args.command.trim();
        if (!trimmedCommand) {
          const message = "Shell command must not be empty";
          log(LogLevel.ERROR, message);
          return {
            content: [{ type: "text" as const, text: message }],
            isError: true
          };
        }
    
        return executeAdbCommand([...deviceArgs, "shell", trimmedCommand], "Error executing shell command");
      },
      { description: ADB_SHELL_TOOL_DESCRIPTION }
  • Input schema object defining the parameters for the adb_shell tool: command (required string) and device (optional string).
    export const adbShellInputSchema = {
      command: z.string().describe("Shell command to execute on the device"),
      device: z.string().optional().describe("Specific device ID (optional)")
    };
  • Zod schema creation for AdbShellSchema by wrapping the input schema object.
    export const AdbShellSchema = z.object(adbShellInputSchema);
  • Helper function used by the adb_shell handler to execute the actual ADB command, handle errors, and format the response.
    async function executeAdbCommand(args: string[], errorMessage: string) {
      const commandString = ["adb", ...args].join(" ");
      try {
        log(LogLevel.DEBUG, `Executing command: ${commandString}`);
        const { stdout, stderr } = await runAdb(args);
        const stderrText = stderr.trim();
    
        // Some ADB commands output to stderr but are not errors
        if (stderrText && !stdout.includes("List of devices attached") && !stdout.includes("Success")) {
          const nonErrorWarnings = [
            "Warning: Activity not started, its current task has been brought to the front",
            "Warning: Activity not started, intent has been delivered to currently running top-most instance."
          ];
    
          if (nonErrorWarnings.some((warning) => stderrText.includes(warning))) {
            log(LogLevel.WARN, `Command warning (not error): ${stderrText}`);
            return {
              content: [{
                type: "text" as const,
                text: stderrText.replace(/^Error: /, "") // Remove any 'Error: ' prefix if present
              }]
              // Do NOT set isError
            };
          }
          log(LogLevel.ERROR, `Command error: ${stderrText}`);
          return {
            content: [{
              type: "text" as const,
              text: `Error: ${stderrText}`
            }],
            isError: true
          };
        }
    
        log(LogLevel.DEBUG, `Command successful: ${commandString}`);
        const commandSummary = args[0] ? `${args[0]}` : commandString;
        log(LogLevel.INFO, `ADB command executed successfully: ${commandSummary}`);
        return {
          content: [{
            type: "text" as const,
            text: stdout || "Command executed successfully"
          }]
        };
      } catch (error) {
        const errorMsg = error instanceof Error ? error.message : String(error);
        log(LogLevel.ERROR, `${errorMessage}: ${errorMsg}`);
        return {
          content: [{
            type: "text" as const,
            text: `${errorMessage}: ${errorMsg}`
          }],
          isError: true
        };
      }
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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

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