check-anr-state
Check recent ANR logs and monitor traces.txt to identify application not responding issues on Android devices, using ADB integration for debugging.
Instructions
Check recent ActivityManager ANR logs and tail /data/anr/traces.txt when accessible (best-effort, may require root/debuggable).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxLines | No | Tail line count from ActivityManager:E | |
| timeoutMs | No | Timeout per adb call in milliseconds |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"maxLines": {
"default": 400,
"description": "Tail line count from ActivityManager:E",
"maximum": 2000,
"minimum": 50,
"type": "integer"
},
"timeoutMs": {
"default": 5000,
"description": "Timeout per adb call in milliseconds",
"maximum": 15000,
"minimum": 1000,
"type": "integer"
}
},
"type": "object"
}
Implementation Reference
- src/tools/logcatTool.js:264-303 (handler)The main handler function that implements the logic for 'check-anr-state' tool. It fetches recent ActivityManager ANR logs and attempts to read status and tail of /data/anr/traces.txt, combining results with error handling.async params => { const sections = []; try { const amLogs = await runAdbCommand( ['logcat', '-d', '-t', String(params.maxLines), 'ActivityManager:E', '*:S'], params.timeoutMs ); if (amLogs) { sections.push('ActivityManager (recent):\n' + amLogs); } else { sections.push('ActivityManager (recent): no entries.'); } } catch (error) { sections.push(`ActivityManager: ${error.message}`); } try { const stat = await runAdbCommand(['shell', 'ls', '-l', '/data/anr/traces.txt'], params.timeoutMs); sections.push('traces.txt stat:\n' + stat); } catch (error) { sections.push(`traces.txt stat: ${error.message}`); } try { const tail = await runAdbCommand( ['shell', 'tail', '-n', '200', '/data/anr/traces.txt'], params.timeoutMs ); if (tail) { sections.push('traces.txt tail (200 lines):\n' + tail); } else { sections.push('traces.txt tail: empty.'); } } catch (error) { sections.push(`traces.txt tail: ${error.message}`); } return { content: [{ type: 'text', text: sections.join('\n\n') }] }; }
- src/tools/logcatTool.js:91-106 (schema)Zod input schema defining parameters for the 'check-anr-state' tool: maxLines for log tailing and timeoutMs.const anrStateInputSchema = z.object({ maxLines: z .number() .int() .min(50) .max(2000) .default(400) .describe('Tail line count from ActivityManager:E'), timeoutMs: z .number() .int() .min(1000) .max(15000) .default(5000) .describe('Timeout per adb call in milliseconds') });
- src/tools/logcatTool.js:256-304 (registration)The server.registerTool call that registers the 'check-anr-state' tool, providing its title, description, input schema, and handler function.server.registerTool( 'check-anr-state', { title: 'Check ANR state (ActivityManager + traces)', description: 'Check recent ActivityManager ANR logs and tail /data/anr/traces.txt when accessible (best-effort, may require root/debuggable).', inputSchema: anrStateInputSchema }, async params => { const sections = []; try { const amLogs = await runAdbCommand( ['logcat', '-d', '-t', String(params.maxLines), 'ActivityManager:E', '*:S'], params.timeoutMs ); if (amLogs) { sections.push('ActivityManager (recent):\n' + amLogs); } else { sections.push('ActivityManager (recent): no entries.'); } } catch (error) { sections.push(`ActivityManager: ${error.message}`); } try { const stat = await runAdbCommand(['shell', 'ls', '-l', '/data/anr/traces.txt'], params.timeoutMs); sections.push('traces.txt stat:\n' + stat); } catch (error) { sections.push(`traces.txt stat: ${error.message}`); } try { const tail = await runAdbCommand( ['shell', 'tail', '-n', '200', '/data/anr/traces.txt'], params.timeoutMs ); if (tail) { sections.push('traces.txt tail (200 lines):\n' + tail); } else { sections.push('traces.txt tail: empty.'); } } catch (error) { sections.push(`traces.txt tail: ${error.message}`); } return { content: [{ type: 'text', text: sections.join('\n\n') }] }; } );