get_logs
Retrieve Android device logs to identify crashes, exceptions, and errors during debugging. Filter by app, log level, time range, or device for targeted analysis.
Instructions
Get device logcat output. Use to find crashes, exceptions, and errors after reproducing a bug.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package_name | No | Filter logs by app package name (e.g., com.example.app) | |
| level | No | Minimum log level: V(erbose), D(ebug), I(nfo), W(arn), E(rror), F(atal) | |
| lines | No | Number of recent log lines to return (default 200) | |
| since | No | Show logs since timestamp (e.g., '2024-01-15 10:30:00.000') | |
| device_id | No | Device ID (optional if only one device) |
Implementation Reference
- src/adb.ts:363-403 (handler)The actual implementation of the getLogcat logic that retrieves logs from the device via ADB.
async getLogcat( options: { packageName?: string; level?: string; lines?: number; since?: string; deviceId?: string; } = {}, ): Promise<string> { const { packageName, level, lines = 200, since, deviceId } = options; const args: string[] = ["logcat", "-d"]; if (since) { args.push("-T", since); } else { args.push("-t", String(lines)); } if (level) { args.push("*:" + level.toUpperCase()); } let output = await this.exec(args, deviceId); if (packageName) { const pidOutput = await this.exec(["shell", "pidof", packageName], deviceId).catch(() => ""); const pids = pidOutput.trim().split(/\s+/).filter(Boolean); if (pids.length > 0) { const pidSet = new Set(pids); output = output .split("\n") .filter((line) => { const pidMatch = line.match(/^\S+\s+\S+\s+(\d+)\s/); return pidMatch && pidSet.has(pidMatch[1]); }) .join("\n"); } } return output; } - src/index.ts:515-540 (registration)The MCP tool 'get_logs' registration and tool handler wrapper.
server.tool( "get_logs", "Get device logcat output. Use to find crashes, exceptions, and errors after reproducing a bug.", { package_name: z.string().optional().describe("Filter logs by app package name (e.g., com.example.app)"), level: z .enum(["V", "D", "I", "W", "E", "F"]) .optional() .describe("Minimum log level: V(erbose), D(ebug), I(nfo), W(arn), E(rror), F(atal)"), lines: z.number().optional().default(200).describe("Number of recent log lines to return (default 200)"), since: z.string().optional().describe("Show logs since timestamp (e.g., '2024-01-15 10:30:00.000')"), device_id: z.string().optional().describe("Device ID (optional if only one device)"), }, async ({ package_name, level, lines, since, device_id }) => { const output = await adb.getLogcat({ packageName: package_name, level, lines, since, deviceId: device_id, }); return { content: [{ type: "text", text: output || "(no log output)" }], }; }, );