Skip to main content
Glama

android-shell

Execute shell commands on Android devices to manage, debug, analyze, and automate device operations through the DroidMind server.

Instructions

Run a shell command on the device.

Args: serial: Device serial number command: Shell command to run max_lines: Maximum lines of output to return (default: 1000) Use positive numbers for first N lines, negative for last N lines Set to None for unlimited (not recommended for large outputs) max_size: Maximum output size in characters (default: 100000) Limits total response size regardless of line count

Returns: Command output

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYes
commandYes
max_linesNo
max_sizeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'android-shell' tool, decorated with @mcp.tool(). It executes shell commands on specified Android devices, handles risk assessment, limits output, and formats the response.
    @mcp.tool("android-shell")
    async def shell_command(
        serial: str, command: str, ctx: Context, max_lines: int | None = 1000, max_size: int | None = 100000
    ) -> str:
        """
        Run a shell command on the device.
    
        Args:
            serial: Device serial number
            command: Shell command to run
            max_lines: Maximum lines of output to return (default: 1000)
                      Use positive numbers for first N lines, negative for last N lines
                      Set to None for unlimited (not recommended for large outputs)
            max_size: Maximum output size in characters (default: 100000)
                      Limits total response size regardless of line count
    
        Returns:
            Command output
        """
        device = await get_device_manager().get_device(serial)
        if device is None:
            return f"Error: Device {serial} not found."
    
        # Assess command risk level
        risk_level = assess_command_risk(command)
    
        # Add warning for high-risk commands
        warning = ""
        if risk_level in (RiskLevel.HIGH, RiskLevel.CRITICAL):
            warning = f"⚠️ WARNING: This command has been assessed as {risk_level.name} risk.\n\n"
            logger.warning("High risk command requested: %s (Risk: %s)", command, risk_level.name)
    
        try:
            result = await device.run_shell(command, max_lines, max_size)
    
            # If the result starts with "Error: Command rejected", it means security validation failed
            if result.startswith("Error: Command rejected"):
                return f"{warning}{result}"
    
            # Format the output to match the expected format in tests
            output = f"# Command Output from {serial}\n\n"
            if warning:
                output += f"{warning}\n\n"
    
            # Add the command output
            output += f"```\n{result}\n```"
    
            return output
        except Exception as e:
            logger.exception("Error executing shell command: %s", e)
            return f"Error executing shell command: {e!s}"
  • Registration of the 'android-shell' tool using the @mcp.tool decorator.
    @mcp.tool("android-shell")
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses output limitations (max_lines, max_size defaults and behavior) which is valuable context, but doesn't mention security implications, permission requirements, potential device impacts, or error handling. The description doesn't contradict annotations since none exist.

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?

Perfectly structured with a clear opening statement followed by organized sections (Args, Returns). Every sentence earns its place by providing essential information without redundancy. The formatting with bullet-like explanations is highly readable and efficient.

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

Completeness4/5

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

Given the complexity of shell command execution (potentially destructive) with no annotations and 4 parameters, the description does well covering parameters and basic behavior. However, it lacks context about Android-specific considerations, safety warnings, or relationship to sibling tools. The existence of an output schema means return values don't need explanation, but more operational context would be beneficial.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate fully. It provides detailed explanations for all 4 parameters beyond their titles: clarifies serial is a device identifier, command is the shell command to execute, and gives comprehensive usage guidance for max_lines (positive/negative values, None for unlimited) and max_size (character limit). This adds significant value beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('Run a shell command') and target resource ('on the device'), distinguishing it from sibling tools like android-app, android-file, or android-screenshot which handle different operations. The verb+resource combination is precise and unambiguous.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like android-app or android-device. The description lacks context about appropriate use cases, prerequisites, or warnings about potential risks associated with shell command execution on Android devices.

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/hyperb1iss/droidmind'

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