Skip to main content
Glama

android-log

Retrieve Android device logs including logcat, app logs, ANR, crash logs, and battery stats. Filter by package, lines, buffer, or format for targeted debugging.

Instructions

Perform various log retrieval operations on an Android device.

This single tool consolidates various log-related actions. The 'action' parameter determines the operation.

Args: serial: Device serial number. action: The specific log operation to perform. ctx: MCP Context for logging and interaction. package (Optional[str]): Package name for get_app_logs action. lines (int): Number of lines to fetch for logcat actions (default: 1000). filter_expr (Optional[str]): Logcat filter expression for get_device_logcat. buffer (Optional[str]): Logcat buffer for get_device_logcat (default: "main"). format_type (Optional[str]): Logcat output format for get_device_logcat (default: "threadtime"). max_size (Optional[int]): Max output size for get_device_logcat (default: 100KB).

Returns: A string message containing the requested logs or status.


Available Actions and their specific argument usage:

  1. action="get_device_logcat"

    • Optional: lines, filter_expr, buffer, format_type, max_size.

  2. action="get_app_logs"

    • Requires: package.

    • Optional: lines.

  3. action="get_anr_logs"

    • No specific arguments beyond serial and ctx.

  4. action="get_crash_logs"

    • No specific arguments beyond serial and ctx.

  5. action="get_battery_stats"

    • No specific arguments beyond serial and ctx.


Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYes
actionYes
packageNo
linesNo
filter_exprNo
bufferNomain
format_typeNothreadtime
max_sizeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function decorated with @mcp.tool(name='android-log'). Dispatches to implementation functions based on the 'action' parameter (get_device_logcat, get_app_logs, get_anr_logs, get_crash_logs, get_battery_stats).
    @mcp.tool(name="android-log")
    async def android_log(
        serial: str,
        action: LogAction,
        ctx: Context,
        package: str | None = None,
        lines: int = 1000,
        filter_expr: str = "",
        buffer: str = "main",
        format_type: str = "threadtime",
        max_size: int | None = 100000,
    ) -> str:
        """
        Perform various log retrieval operations on an Android device.
    
        This single tool consolidates various log-related actions.
        The 'action' parameter determines the operation.
    
        Args:
            serial: Device serial number.
            action: The specific log operation to perform.
            ctx: MCP Context for logging and interaction.
            package (Optional[str]): Package name for `get_app_logs` action.
            lines (int): Number of lines to fetch for logcat actions (default: 1000).
            filter_expr (Optional[str]): Logcat filter expression for `get_device_logcat`.
            buffer (Optional[str]): Logcat buffer for `get_device_logcat` (default: "main").
            format_type (Optional[str]): Logcat output format for `get_device_logcat` (default: "threadtime").
            max_size (Optional[int]): Max output size for `get_device_logcat` (default: 100KB).
    
        Returns:
            A string message containing the requested logs or status.
    
        ---
        Available Actions and their specific argument usage:
    
        1.  `action="get_device_logcat"`
            - Optional: `lines`, `filter_expr`, `buffer`, `format_type`, `max_size`.
        2.  `action="get_app_logs"`
            - Requires: `package`.
            - Optional: `lines`.
        3.  `action="get_anr_logs"`
            - No specific arguments beyond `serial` and `ctx`.
        4.  `action="get_crash_logs"`
            - No specific arguments beyond `serial` and `ctx`.
        5.  `action="get_battery_stats"`
            - No specific arguments beyond `serial` and `ctx`.
        ---
        """
        try:
            if action == LogAction.GET_APP_LOGS and package is None:
                return "❌ Error: 'package' is required for action 'get_app_logs'."
    
            if action == LogAction.GET_DEVICE_LOGCAT:
                return await _get_device_logcat_impl(serial, ctx, lines, filter_expr, buffer, format_type, max_size)
            if action == LogAction.GET_APP_LOGS:
                return await _get_app_logs_impl(serial, package, ctx, lines)  # type: ignore
            if action == LogAction.GET_ANR_LOGS:
                return await _get_anr_logs_impl(serial, ctx)
            if action == LogAction.GET_CRASH_LOGS:
                return await _get_crash_logs_impl(serial, ctx)
            if action == LogAction.GET_BATTERY_STATS:
                return await _get_battery_stats_impl(serial, ctx)
    
            valid_actions = ", ".join([la.value for la in LogAction])
            logger.error("Invalid log action '%s' received. Valid actions are: %s.", action, valid_actions)
            return f"❌ Error: Unknown log action '{action}'. Valid actions are: {valid_actions}."
    
        except Exception as e:
            logger.exception("Unexpected error during log operation %s for serial '%s': %s", action, serial, e)
            return f"❌ Error: An unexpected error occurred during '{action.value}': {e!s}"
  • LogAction enum defining the valid sub-actions for the android-log tool: get_device_logcat, get_app_logs, get_anr_logs, get_crash_logs, get_battery_stats.
    class LogAction(str, Enum):
        """Defines the available sub-actions for the 'android-log' tool."""
    
        GET_DEVICE_LOGCAT = "get_device_logcat"
        GET_APP_LOGS = "get_app_logs"
        GET_ANR_LOGS = "get_anr_logs"
        GET_CRASH_LOGS = "get_crash_logs"
        GET_BATTERY_STATS = "get_battery_stats"
  • Registration of the tool via @mcp.tool(name='android-log') decorator on the FastMCP instance.
    @mcp.tool(name="android-log")
  • Re-export of android_log from droidmind.tools.logs for the tools package.
    from droidmind.tools.logs import (
        android_log,
    )
  • Helper function _get_filtered_logcat used by multiple action implementations to retrieve filtered logcat output.
    async def _get_filtered_logcat(
        device: Any,
        filter_expr: str,
        lines: int = 1000,
        buffer: str = "main",
        format_type: str = "threadtime",
        max_size: int | None = 100000,
    ) -> str:
        """
        Helper function to get filtered logcat output in a consistent format.
    
        Args:
            device: Device instance
            filter_expr: Optional filter expression for logcat
            lines: Number of recent lines to fetch
            buffer: Logcat buffer to use (main, system, crash, etc.)
            format_type: Format for logcat output
            max_size: Maximum output size in characters
    
        Returns:
            Formatted logcat output
        """
        try:
            # Build logcat command
            cmd = ["logcat", "-d", "-v", format_type]
    
            # Specify buffer if not main
            if buffer != "main":
                cmd.extend(["-b", buffer])
    
            # Add line limit if specified
            if lines > 0:
                cmd.extend(["-t", str(lines)])
    
            # Add filter if specified
            if filter_expr:
                cmd.extend(filter_expr.split())
    
            # Join command parts
            logcat_cmd = " ".join(cmd)
    
            # Get logcat output
            output = await device.run_shell(logcat_cmd)
    
            # Truncate if needed
            if max_size and len(output) > max_size:
                output = output[:max_size] + "\n... [Output truncated due to size limit]"
    
            return output
        except Exception as e:
            logger.exception("Error getting logcat output")
            return f"Error retrieving logcat output: {e!s}"
Behavior3/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 describes each action and its parameters, but lacks details on performance implications, error conditions, or prerequisites (e.g., USB debugging enabled). For a read-heavy tool, this is adequate but not comprehensive.

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

Conciseness4/5

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

The description is somewhat lengthy but well-structured with bullet points for each action, front-loading the purpose. Every sentence adds value, though a slightly more succinct summary of all actions could improve conciseness.

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 tool's complexity (8 parameters, 5 actions), the description covers all necessary usage details. The output schema is not described, but the return type ('string message') is mentioned. This is largely sufficient for an agent to decide and execute.

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%, yet the description adds significant meaning: it maps each parameter to specific actions, explains optional vs required, and provides defaults. This fully compensates for the schema's lack of descriptions.

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 it performs 'various log retrieval operations on an Android device' and lists five specific actions via the 'action' parameter. This distinguishes it from siblings like android-app, android-device, etc., which handle different domains.

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

Usage Guidelines4/5

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

The description explains that the 'action' parameter determines the operation and details which arguments are required or optional for each action. While it does not explicitly contrast with siblings, the context is sufficient for an agent to choose and invoke the tool correctly.

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