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
| Name | Required | Description | Default |
|---|---|---|---|
| contextLines | No | Number of context lines to include around errors | |
| logFormat | No | Format of the log content | auto |
| logText | Yes | Log content to analyze |
Implementation Reference
- src/server.ts:346-367 (handler)MCP tool handler for 'analyze_log': validates input, calls LogAnalyzer.analyzeLogs, formats MCPToolResult responseprivate 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 } }; }
- src/tools/logAnalyzer.ts:19-36 (helper)Core implementation: preprocesses logs, generates AI prompt for Gemini, parses response into structured LogAnalysisasync 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'}`); } }
- src/server.ts:81-101 (schema)Input schema validation for analyze_log tool parametersinputSchema: { 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'] } },