analyze_honeybadger_issue
Analyze Honeybadger errors to identify root causes and receive actionable fix suggestions for application issues.
Instructions
Comprehensive analysis of a Honeybadger issue with fix suggestions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fault_id | Yes | The ID of the fault to analyze | |
| project_id | No | Optional project ID (uses env var if not provided) | |
| include_context | No | Include request context and parameters in analysis |
Implementation Reference
- src/index.ts:317-342 (handler)Main handler function for 'analyze_honeybadger_issue' tool. Fetches fault details and recent notices from Honeybadger API, then generates analysis using helper.private async analyzeIssue(faultId: string, projectId?: string, includeContext: boolean = true): Promise<any> { const pid = projectId || this.config.projectId; if (!pid) { throw new McpError(ErrorCode.InvalidRequest, 'Project ID is required'); } // Fetch fault details const fault = await this.makeHoneybadgerRequest(`/projects/${pid}/faults/${faultId}`); // Fetch recent notices const notices = await this.makeHoneybadgerRequest(`/projects/${pid}/faults/${faultId}/notices`, { limit: 5, }); // Create comprehensive analysis const analysis = this.generateAnalysis(fault, notices.results || [], includeContext); return { content: [ { type: 'text', text: analysis, }, ], }; }
- src/index.ts:344-504 (helper)Supporting function that generates comprehensive markdown analysis report, including fault overview, error type analysis, stack trace breakdown, context/parameters, and tailored fix suggestions.private generateAnalysis(fault: HoneybadgerFault, notices: HoneybadgerNotice[], includeContext: boolean): string { const latestNotice = notices[0]; let analysis = `# Honeybadger Issue Analysis ## Fault Overview - **ID**: ${fault.id} - **Error Class**: ${fault.klass} - **Message**: ${fault.message} - **Environment**: ${fault.environment} - **Occurrences**: ${fault.notices_count} - **First Seen**: ${fault.created_at} - **Last Seen**: ${fault.last_notice_at} - **Status**: ${fault.resolved ? 'Resolved' : 'Unresolved'} - **URL**: ${fault.url} ## Error Analysis ### Error Type The error "${fault.klass}" suggests:`; // Add error type analysis if (fault.klass.includes('NoMethodError')) { analysis += ` - A method is being called on an object that doesn't respond to it - Possible nil object or wrong object type - Missing method definition or typo in method name`; } else if (fault.klass.includes('NameError')) { analysis += ` - Undefined variable or constant - Typo in variable/constant name - Scope issues`; } else if (fault.klass.includes('ArgumentError')) { analysis += ` - Wrong number of arguments passed to a method - Invalid argument values - Method signature mismatch`; } else if (fault.klass.includes('ActiveRecord')) { analysis += ` - Database-related error - Possible migration issues - Invalid queries or constraints`; } else { analysis += ` - Review the specific error class documentation - Check for common patterns in this error type`; } if (latestNotice) { analysis += ` ### Stack Trace Analysis `; // Analyze backtrace const backtrace = latestNotice.backtrace?.slice(0, 10) || []; backtrace.forEach((frame, index) => { if (index === 0) { analysis += ` **Primary Error Location:** - File: \`${frame.file}\` - Method: \`${frame.method}\` - Line: ${frame.number}`; if (frame.source) { analysis += ` - Context: \`\`\` ${Object.entries(frame.source).map(([line, code]) => `${line}: ${code}`).join('\n')} \`\`\``; } } else if (index < 5) { analysis += ` - ${frame.file}:${frame.number} in \`${frame.method}\``; } }); if (includeContext && latestNotice.context) { analysis += ` ### Request Context \`\`\`json ${JSON.stringify(latestNotice.context, null, 2)} \`\`\``; } if (includeContext && latestNotice.params && Object.keys(latestNotice.params).length > 0) { analysis += ` ### Request Parameters \`\`\`json ${JSON.stringify(latestNotice.params, null, 2)} \`\`\``; } } analysis += ` ## Recommended Fix Strategies ### Immediate Actions 1. **Reproduce the Error** - Use the provided context and parameters - Set up similar conditions in development - Add logging around the error location 2. **Quick Fixes**`; // Add specific fix suggestions based on error type if (fault.klass.includes('NoMethodError')) { analysis += ` - Add nil checks: \`object&.method_name\` - Verify object type before method calls - Check method spelling and availability`; } else if (fault.klass.includes('ArgumentError')) { analysis += ` - Review method signatures - Validate input parameters - Add parameter validation`; } else if (fault.klass.includes('ActiveRecord')) { analysis += ` - Check database migrations - Validate model associations - Review query syntax`; } analysis += ` ### Long-term Solutions 1. **Add Error Handling** - Implement proper exception handling - Add user-friendly error messages - Log detailed error information 2. **Add Tests** - Write unit tests covering the error scenario - Add integration tests for the affected flow - Include edge case testing 3. **Code Review** - Review similar patterns in codebase - Look for related potential issues - Implement defensive programming practices ### Monitoring - Set up alerts for this error pattern - Monitor error frequency after fixes - Track related errors that might emerge ## Next Steps 1. Examine the code at the primary error location 2. Set up local reproduction using the provided context 3. Implement the recommended fixes 4. Add appropriate tests 5. Deploy and monitor the fix effectiveness --- *Analysis generated from Honeybadger fault #${fault.id}*`; return analysis; }
- src/index.ts:162-184 (registration)Tool registration entry in the ListTools handler, defining name, description, and input schema for 'analyze_honeybadger_issue'.{ name: 'analyze_honeybadger_issue', description: 'Comprehensive analysis of a Honeybadger issue with fix suggestions', inputSchema: { type: 'object', properties: { fault_id: { type: 'string', description: 'The ID of the fault to analyze', }, project_id: { type: 'string', description: 'Optional project ID (uses env var if not provided)', }, include_context: { type: 'boolean', description: 'Include request context and parameters in analysis', default: true, }, }, required: ['fault_id'], }, },
- src/index.ts:165-182 (schema)Input schema definition for the tool, specifying parameters like fault_id (required), project_id, and include_context.inputSchema: { type: 'object', properties: { fault_id: { type: 'string', description: 'The ID of the fault to analyze', }, project_id: { type: 'string', description: 'Optional project ID (uses env var if not provided)', }, include_context: { type: 'boolean', description: 'Include request context and parameters in analysis', default: true, }, }, required: ['fault_id'],