adb_get_logcat
Retrieve Android device logcat output for debugging and monitoring system events, with options to filter by tag, specify device, and control line count.
Instructions
Get logcat output from the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lines | No | Number of lines to retrieve (default: 100) | |
| tag | No | Filter by tag (optional) | |
| deviceId | No | Device ID (optional) |
Implementation Reference
- src/tools/shell.ts:168-211 (handler)The handler function that executes the ADB logcat command, checks device connection, builds the logcat command with optional lines and tag filters, executes it via adbClient, and returns formatted log output or error.async getLogcat(lines: number = 100, tag?: string, deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot get logcat - device is not connected' }; } let command = `shell logcat -d -t ${lines}`; if (tag) { command += ` -s ${tag}`; } const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to get logcat' }; } return { success: true, data: { logs: result.output, lines, tag, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: `Retrieved ${lines} logcat lines${tag ? ` for tag: ${tag}` : ''}` }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to get logcat' }; } }
- src/index.ts:404-421 (schema)Input schema definition for the adb_get_logcat tool, specifying optional parameters for lines, tag, and deviceId.inputSchema: { type: 'object', properties: { lines: { type: 'number', description: 'Number of lines to retrieve (default: 100)', }, tag: { type: 'string', description: 'Filter by tag (optional)', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: [], },
- src/index.ts:401-422 (registration)Registration of the adb_get_logcat tool in the tools list, including name, description, and input schema.{ name: 'adb_get_logcat', description: 'Get logcat output from the device', inputSchema: { type: 'object', properties: { lines: { type: 'number', description: 'Number of lines to retrieve (default: 100)', }, tag: { type: 'string', description: 'Filter by tag (optional)', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: [], }, },
- src/index.ts:479-480 (registration)Switch case that dispatches the adb_get_logcat tool call to the shellTools.getLogcat handler.case 'adb_get_logcat': return await this.handleToolCall(this.shellTools.getLogcat(args?.lines as number, args?.tag as string, args?.deviceId as string));