adb_logcat
Capture and manage Android device logs using logcat. Specify filters, device IDs, and line counts to extract relevant debugging information for app development and troubleshooting.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | No | Specific device ID (optional) | |
| filter | No | Logcat filter expression (optional) | |
| lines | No | Number of lines to return (default: 50) |
Implementation Reference
- src/index.ts:532-568 (handler)Full handler implementation and registration for the 'adb_logcat' tool. Executes 'adb logcat -d' on the specified device with optional filter expression (parsed into arguments) and limits the output to the last N lines (default 50). Handles errors and returns log text or error message.// Add adb logcat tool server.tool( "adb_logcat", AdbLogcatSchema.shape, async (args: z.infer<typeof AdbLogcatSchema>, _extra: RequestHandlerExtra) => { const lines = args.lines || 50; const filterExpr = args.filter ? args.filter : ""; log(LogLevel.INFO, `Reading logcat (${lines} lines, filter: ${filterExpr || 'none'})`); const deviceArgs = buildDeviceArgs(args.device); const filterArgs = filterExpr ? splitCommandArguments(filterExpr) : []; const adbArgs = [...deviceArgs, "logcat", "-d", ...filterArgs]; try { const { stdout, stderr } = await runAdb(adbArgs); if (stderr) { log(LogLevel.WARN, `logcat returned stderr: ${stderr}`); } const logLines = stdout.split(/\r?\n/); const limitedLines = lines > 0 ? logLines.slice(-lines) : logLines; const text = limitedLines.join("\n"); return { content: [{ type: "text" as const, text }] }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); log(LogLevel.ERROR, `Error reading logcat: ${errorMsg}`); return { content: [{ type: "text" as const, text: `Error reading logcat: ${errorMsg}` }], isError: true }; } }, { description: ADB_LOGCAT_TOOL_DESCRIPTION } );
- src/types.ts:56-60 (schema)Object literal defining the input parameters schema for adb_logcat tool using Zod descriptions.export const adbLogcatInputSchema = { filter: z.string().optional().describe("Logcat filter expression (optional)"), device: z.string().optional().describe("Specific device ID (optional)"), lines: z.number().optional().default(50).describe("Number of lines to return (default: 50)") };
- src/types.ts:105-105 (schema)Zod schema creation for adb_logcat tool by wrapping the input schema object.export const AdbLogcatSchema = z.object(adbLogcatInputSchema);
- src/index.ts:113-120 (registration)Tool description constant used in the registration of the adb_logcat tool.* Tool description for adb-logcat */ const ADB_LOGCAT_TOOL_DESCRIPTION = "Retrieves Android system and application logs from a connected device. " + "Ideal for debugging app behavior, monitoring system events, and identifying errors. " + "Supports filtering by log tags or expressions to narrow down relevant information. " + "Results can be limited to a specific number of lines, making it useful for both brief checks and detailed analysis. " + "Use when troubleshooting crashes, unexpected behavior, or performance issues.";