Skip to main content
Glama

analyze_log

Analyze error logs to identify root causes and provide AI-powered insights for debugging server issues with contextual analysis.

Instructions

Analyze error logs and provide root cause analysis with AI-powered insights

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextLinesNoNumber of context lines to include around errors
logFormatNoFormat of the log contentauto
logTextYesLog content to analyze

Implementation Reference

  • MCP tool handler for 'analyze_log': validates input, calls LogAnalyzer.analyzeLogs, formats MCPToolResult response
    private async handleAnalyzeLog(args: any): Promise<MCPToolResult> {
      const { logText, logFormat = 'auto', contextLines = 50 } = args;
    
      if (!logText || typeof logText !== 'string') {
        throw new Error('logText is required and must be a string');
      }
    
      const analysis = await this.logAnalyzer.analyzeLogs(logText, {
        logFormat,
        contextLines
      });
    
      return {
        success: true,
        data: analysis,
        metadata: {
          processedAt: new Date(),
          logLength: logText.length,
          format: logFormat
        }
      };
    }
  • Core implementation: preprocesses logs, generates AI prompt for Gemini, parses response into structured LogAnalysis
    async analyzeLogs(logText: string, options: LogParsingOptions): Promise<LogAnalysis> {
      // Pre-process the log content
      const processedContent = this.preprocessLogs(logText, options);
      
      // Build analysis prompt
      const prompt = this.buildAnalysisPrompt(processedContent, options);
      
      try {
        // Generate analysis using Gemini
        const result = await this.model.generateContent(prompt);
        const response = await result.response;
        
        // Parse and structure the response
        return this.parseResponse(response.text(), logText);
      } catch (error) {
        throw new Error(`Failed to analyze logs: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Input schema validation for analyze_log tool parameters
    inputSchema: {
      type: 'object',
      properties: {
        logText: {
          type: 'string',
          description: 'Log content to analyze'
        },
        logFormat: {
          type: 'string',
          enum: ['auto', 'json', 'plain'],
          default: 'auto',
          description: 'Format of the log content'
        },
        contextLines: {
          type: 'number',
          default: 50,
          description: 'Number of context lines to include around errors'
        }
      },
      required: ['logText']
    }
  • src/server.ts:78-102 (registration)
    Tool descriptor registration in ListToolsRequestSchema handler, including dispatch case at line 180
    {
      name: 'analyze_log',
      description: 'Analyze error logs and provide root cause analysis with AI-powered insights',
      inputSchema: {
        type: 'object',
        properties: {
          logText: {
            type: 'string',
            description: 'Log content to analyze'
          },
          logFormat: {
            type: 'string',
            enum: ['auto', 'json', 'plain'],
            default: 'auto',
            description: 'Format of the log content'
          },
          contextLines: {
            type: 'number',
            default: 50,
            description: 'Number of context lines to include around errors'
          }
        },
        required: ['logText']
      }
    },

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/ChiragPatankar/loganalyzer-mcp'

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