read_electron_logs
Retrieve and monitor Electron application logs for debugging and behavior analysis. Specify log types, line count, and continuous tailing for real-time insights.
Instructions
Read console logs and output from running Electron applications. Useful for debugging and monitoring app behavior.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| follow | No | Whether to follow/tail the logs | |
| lines | No | Number of recent lines to read (default: 100) | |
| logType | No | Type of logs to read |
Implementation Reference
- src/utils/electron-logs.ts:18-44 (handler)Primary handler function implementing the read_electron_logs tool logic. Connects to Electron via DevTools Protocol for console logs or falls back to system process logs.export async function readElectronLogs( logType: LogType = 'all', lines: number = 100, follow: boolean = false, ): Promise<string> { try { logger.info('[MCP] Looking for running Electron applications for log access...'); try { const target = await findElectronTarget(); // Connect via WebSocket to get console logs if (logType === 'console' || logType === 'all') { return await getConsoleLogsViaDevTools(target, lines, follow); } } catch { logger.info('[MCP] No DevTools connection found, checking system logs...'); } // Fallback to system logs if DevTools not available return await getSystemElectronLogs(lines); } catch (error) { throw new Error( `Failed to read logs: ${error instanceof Error ? error.message : String(error)}`, ); } }
- src/schemas.ts:49-56 (schema)Zod schema defining the input parameters (logType, lines, follow) for the read_electron_logs tool.export const ReadElectronLogsSchema = z.object({ logType: z .enum(['console', 'main', 'renderer', 'all']) .optional() .describe('Type of logs to read'), lines: z.number().optional().describe('Number of recent lines to read (default: 100)'), follow: z.boolean().optional().describe('Whether to follow/tail the logs'), });
- src/tools.ts:63-68 (registration)Tool registration entry in the tools array, specifying name, description, and input schema for read_electron_logs.{ name: ToolName.READ_ELECTRON_LOGS, description: 'Read console logs and output from running Electron applications. Useful for debugging and monitoring app behavior.', inputSchema: zodToJsonSchema(ReadElectronLogsSchema) as ToolInput, },
- src/handlers.ts:155-180 (handler)Dispatch handler in the main tool switch statement that parses inputs, calls the readElectronLogs function, and formats the MCP response.case ToolName.READ_ELECTRON_LOGS: { const { logType, lines, follow } = ReadElectronLogsSchema.parse(args); const logs = await readElectronLogs(logType, lines); if (follow) { return { content: [ { type: 'text', text: `Following logs (${logType}). This is a snapshot of recent logs:\n\n${logs}`, }, ], isError: false, }; } return { content: [ { type: 'text', text: `Electron logs (${logType}):\n\n${logs}`, }, ], isError: false, }; }
- src/utils/electron-logs.ts:49-92 (helper)Helper function to retrieve console logs via Chrome DevTools Protocol WebSocket connection.async function getConsoleLogsViaDevTools( target: any, lines: number, follow: boolean, ): Promise<string> { const logs: string[] = []; return new Promise((resolve, reject) => { (async () => { try { const ws = await connectForLogs(target, (log: string) => { logs.push(log); if (logs.length >= lines && !follow) { ws.close(); resolve(logs.slice(-lines).join('\n')); } }); // For non-follow mode, try to get console history first if (!follow) { // Request console API calls from Runtime ws.send( JSON.stringify({ id: 99, method: 'Runtime.evaluate', params: { expression: `console.log("Reading console history for MCP test"); "History checked"`, includeCommandLineAPI: true, }, }), ); // Wait longer for logs to be captured and history to be available setTimeout(() => { ws.close(); resolve(logs.length > 0 ? logs.slice(-lines).join('\n') : 'No console logs available'); }, 7000); // Increased timeout to 7 seconds } } catch (error) { reject(error); } })(); }); }