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 },

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