Skip to main content
Glama

android_logcat

Capture Android device logs for debugging and monitoring app behavior. Retrieve logcat output from connected devices or emulators with filtering options to isolate specific log levels or messages.

Instructions

Capture Android logcat output from device or emulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYesDevice serial number
filterNoLog filter (e.g., *:E for errors only)
linesNoNumber of log lines to capture
clearNoClear logcat buffer before capturing

Implementation Reference

  • The main handler function for the 'android_logcat' tool. It validates input parameters using Zod, constructs ADB logcat arguments based on serial, filter, lines, and clear options, executes the command via processExecutor, and returns formatted results or handles clearing the log buffer.
    handler: async (args: any) => {
      const validation = AndroidAdbLogcatSchema.safeParse(args);
      if (!validation.success) {
        throw new Error(`Invalid request: ${validation.error.message}`);
      }
    
      const { serial, filter, lines = 100, clear = false } = validation.data;
    
      const adb_args = ['-s', serial, 'logcat'];
      
      if (clear) {
        adb_args.push('-c');
        const clearResult = await processExecutor.execute('adb', adb_args);
        
        return {
          success: true,
          data: {
            serial,
            action: 'cleared',
            output: 'Logcat cleared successfully',
          },
        };
      }
    
      // Add filter if provided
      if (filter) {
        adb_args.push(filter);
      }
    
      // Add line limit
      adb_args.push('-t', lines.toString());
    
      const result = await processExecutor.execute('adb', adb_args, {
        timeout: 60000, // 1 minute timeout for logcat
      });
    
      return {
        success: true,
        data: {
          serial,
          filter: filter || 'all',
          lines,
          logs: result.stdout,
          exitCode: result.exitCode,
        },
      };
    }
  • Zod validation schema for the android_logcat tool input parameters, defining required serial, optional filter and clear, and lines with defaults and constraints.
    const AndroidAdbLogcatSchema = z.object({
      serial: z.string().min(1),
      filter: z.string().optional(),
      lines: z.number().min(1).max(10000).default(100),
      clear: z.boolean().default(false),
    });
  • Registration of the 'android_logcat' tool in the createAndroidTools function's tools Map, including name, description, inputSchema (JSON schema equivalent), and reference to the handler.
    tools.set('android_logcat', {
      name: 'android_logcat',
      description: 'Capture Android logcat output from device or emulator',
      inputSchema: {
        type: 'object',
        properties: {
          serial: { type: 'string', minLength: 1, description: 'Device serial number' },
          filter: { type: 'string', description: 'Log filter (e.g., *:E for errors only)' },
          lines: { type: 'number', minimum: 1, maximum: 10000, description: 'Number of log lines to capture' },
          clear: { type: 'boolean', description: 'Clear logcat buffer before capturing' }
        },
        required: ['serial']
      },
      handler: async (args: any) => {
        const validation = AndroidAdbLogcatSchema.safeParse(args);
        if (!validation.success) {
          throw new Error(`Invalid request: ${validation.error.message}`);
        }
    
        const { serial, filter, lines = 100, clear = false } = validation.data;
    
        const adb_args = ['-s', serial, 'logcat'];
        
        if (clear) {
          adb_args.push('-c');
          const clearResult = await processExecutor.execute('adb', adb_args);
          
          return {
            success: true,
            data: {
              serial,
              action: 'cleared',
              output: 'Logcat cleared successfully',
            },
          };
        }
    
        // Add filter if provided
        if (filter) {
          adb_args.push(filter);
        }
    
        // Add line limit
        adb_args.push('-t', lines.toString());
    
        const result = await processExecutor.execute('adb', adb_args, {
          timeout: 60000, // 1 minute timeout for logcat
        });
    
        return {
          success: true,
          data: {
            serial,
            filter: filter || 'all',
            lines,
            logs: result.stdout,
            exitCode: result.exitCode,
          },
        };
      }
    });
  • JSON Schema definition for the android_logcat tool input, used for MCP protocol validation, mirroring the Zod schema.
    inputSchema: {
      type: 'object',
      properties: {
        serial: { type: 'string', minLength: 1, description: 'Device serial number' },
        filter: { type: 'string', description: 'Log filter (e.g., *:E for errors only)' },
        lines: { type: 'number', minimum: 1, maximum: 10000, description: 'Number of log lines to capture' },
        clear: { type: 'boolean', description: 'Clear logcat buffer before capturing' }
      },
      required: ['serial']
  • Metadata entry for 'android_logcat' in the tool registry, defining category, platform, dependencies (ADB), and performance expectations.
    'android_logcat': {
      name: 'android_logcat',
      category: ToolCategory.ESSENTIAL,
      platform: 'android',
      requiredTools: [RequiredTool.ADB],
      description: 'Capture Android logcat output for debugging',
      safeForTesting: false,
      performance: { expectedDuration: 0, timeout: 60000 } // Variable duration
    },
Behavior2/5

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

With no annotations, the description carries full burden but provides minimal behavioral context. It mentions capturing output but doesn't disclose what happens during capture (e.g., blocking vs. streaming, timeout behavior, permission requirements, or what 'capture' entails operationally). The description is accurate but insufficient for a mutation-like operation.

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 a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately understandable without unnecessary elaboration.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the captured output looks like, potential side effects (like buffer clearing), error conditions, or dependencies. The context demands more detail for effective 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 parameters are fully documented in the schema. The description adds no additional parameter semantics beyond implying capture action. Baseline 3 is appropriate since the schema handles parameter documentation adequately.

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 verb ('capture') and resource ('Android logcat output'), specifying it works from 'device or emulator'. It distinguishes from obvious non-siblings like screenshot or installation tools, but doesn't explicitly differentiate from other log-related tools (though none appear in the sibling list).

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 on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites (e.g., device must be connected/available), nor does it suggest when other tools might be more appropriate for related tasks.

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/cristianoaredes/mcp-mobile-server'

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