clear-logcat-buffer
Clear Android logcat buffers to prepare for new debugging scenarios by running adb logcat -c command.
Instructions
Run adb logcat -c to clear buffers before a new scenario.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeoutMs | No | Timeout per adb call in milliseconds |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"timeoutMs": {
"default": 5000,
"description": "Timeout per adb call in milliseconds",
"maximum": 15000,
"minimum": 1000,
"type": "integer"
}
},
"type": "object"
}
Implementation Reference
- src/tools/logcatTool.js:313-316 (handler)The inline async handler function for the 'clear-logcat-buffer' tool. It executes 'adb logcat -c' using the runAdbCommand helper with the provided timeout and returns a success message.async params => { await runAdbCommand(['logcat', '-c'], params.timeoutMs); return { content: [{ type: 'text', text: 'Cleared logcat buffers.' }] }; }
- src/tools/logcatTool.js:108-116 (schema)Zod input schema definition for the 'clear-logcat-buffer' tool, specifying an optional timeoutMs parameter (default 5000ms).const clearLogcatInputSchema = z.object({ timeoutMs: z .number() .int() .min(1000) .max(15000) .default(5000) .describe('Timeout per adb call in milliseconds') });
- src/tools/logcatTool.js:306-317 (registration)Registers the 'clear-logcat-buffer' MCP tool on the server using server.registerTool, providing name, metadata (title, description, schema), and handler function.server.registerTool( 'clear-logcat-buffer', { title: 'Clear logcat buffer', description: 'Run adb logcat -c to clear buffers before a new scenario.', inputSchema: clearLogcatInputSchema }, async params => { await runAdbCommand(['logcat', '-c'], params.timeoutMs); return { content: [{ type: 'text', text: 'Cleared logcat buffers.' }] }; } );
- src/tools/logcatTool.js:118-133 (helper)Helper function to run adb shell commands asynchronously with timeout, buffer limits, and comprehensive error handling including stderr capture. Used by the clear-logcat-buffer handler.async function runAdbCommand(args, timeoutMs) { try { const { stdout } = await execFileAsync('adb', args, { timeout: timeoutMs, maxBuffer: 5 * 1024 * 1024 }); return stdout.trimEnd(); } catch (error) { const stderr = error && typeof error.stderr === 'string' ? error.stderr.trim() : ''; const message = [`adb ${args.join(' ')} failed`, error.message].filter(Boolean).join(': '); if (stderr) { throw new Error(`${message} | stderr: ${stderr}`); } throw new Error(message); } }
- src/index.js:21-21 (registration)Top-level call to registerLogcatTool(server) in the main MCP server setup, which invokes the registration of clear-logcat-buffer and other logcat-related tools.registerLogcatTool(server);