Skip to main content
Glama

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
NameRequiredDescriptionDefault
followNoWhether to follow/tail the logs
linesNoNumber of recent lines to read (default: 100)
logTypeNoType of logs to read

Implementation Reference

  • 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)}`,
        );
      }
    }
  • 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,
    },
  • 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,
      };
    }
  • 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);
          }
        })();
      });
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/halilural/electron-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server