ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
138 lines (134 loc) • 6.1 kB
JavaScript
/**
* Handler for automatic problem detection
* Identifies common web app issues like hydration errors, large bundles, poor caching, etc.
*/
export class ProblemHandler {
localEngine;
tools = [
{
name: 'detect_problems',
description: 'Automatically detect common web app problems: hydration errors, large bundles, slow routes, poor caching, and more.',
inputSchema: {
type: 'object',
properties: {
sessionId: {
type: 'string',
description: 'Debug session ID'
}
},
required: ['sessionId']
}
}
];
constructor(localEngine) {
this.localEngine = localEngine;
}
async handle(toolName, args, sessions) {
if (toolName !== 'detect_problems') {
throw new Error(`Unknown tool: ${toolName}`);
}
const { sessionId } = args;
const session = sessions.get(sessionId);
if (!session) {
throw new Error(`Debug session ${sessionId} not found`);
}
try {
const analysis = await this.localEngine.detectCommonProblems();
// Format problem detection report
let report = `## Problem Detection Results\n\n`;
if (analysis.problems.length === 0) {
report += `✅ **No Problems Detected**
Your application appears to be running smoothly! Here are some areas we checked:
- ✓ No hydration mismatches found
- ✓ Bundle sizes are reasonable
- ✓ Routes are loading quickly
- ✓ Caching headers are properly configured
- ✓ No console errors detected
- ✓ Performance metrics are within acceptable ranges
### Best Practices to Maintain:
1. **Keep bundle sizes small** - Continue code splitting
2. **Monitor performance** - Regular lighthouse audits
3. **Test across browsers** - Ensure compatibility
4. **Update dependencies** - Security and performance
5. **Review console regularly** - Catch issues early\n`;
}
else {
// Show problem summary
const icon = analysis.summary.critical > 0 ? '🚨' : '⚠️';
const problemText = analysis.problems.length === 1 ? 'Problem' : 'Problems';
report += `${icon} **${analysis.problems.length} ${problemText} Detected**\n\n`;
// Show severity breakdown
report += `### Summary:\n`;
if (analysis.summary.critical > 0) {
report += `- **Critical: ${analysis.summary.critical}** 🔴\n`;
}
if (analysis.summary.warning > 0) {
report += `- **Warning: ${analysis.summary.warning}** 🟡\n`;
}
if (analysis.summary.info > 0) {
report += `- **Info: ${analysis.summary.info}** 🔵\n`;
}
report += '\n';
// Group problems by severity
const criticalProblems = analysis.problems.filter(p => p.severity === 'critical');
const warningProblems = analysis.problems.filter(p => p.severity === 'warning');
const infoProblems = analysis.problems.filter(p => p.severity === 'info');
// Show critical problems first
if (criticalProblems.length > 0) {
report += `### 🔴 Critical Issues:\n\n`;
criticalProblems.forEach((problem, index) => {
report += this.formatProblem(problem, index + 1);
});
}
// Show warnings
if (warningProblems.length > 0) {
report += `### 🟡 Warnings:\n\n`;
warningProblems.forEach((problem, index) => {
report += this.formatProblem(problem, index + 1);
});
}
// Show info
if (infoProblems.length > 0) {
report += `### 🔵 Information:\n\n`;
infoProblems.forEach((problem, index) => {
report += this.formatProblem(problem, index + 1);
});
}
// Add quick fix guide
report += `### Quick Fix Guide:\n\n`;
report += `1. **Address Critical Issues First** - These are blocking user experience\n`;
report += `2. **Review Warnings** - These impact performance or maintainability\n`;
report += `3. **Consider Info Items** - These are best practices and optimizations\n\n`;
// Add resources
report += `### Debugging Resources:\n\n`;
report += `- **Performance**: https://web.dev/performance/\n`;
report += `- **React DevTools**: https://react.dev/learn/react-developer-tools\n`;
report += `- **Chrome DevTools**: https://developer.chrome.com/docs/devtools/\n`;
report += `- **Lighthouse**: https://developers.google.com/web/tools/lighthouse\n`;
}
return {
content: [{
type: 'text',
text: report
}]
};
}
catch (error) {
throw new Error(`Failed to detect problems: ${error.message}`);
}
}
formatProblem(problem, index) {
let formatted = `#### ${index}. ${problem.title}\n\n`;
formatted += `- **Type:** \`${problem.type}\`\n`;
formatted += `- **Location:** ${problem.location}\n`;
formatted += `- **Description:** ${problem.description}\n`;
formatted += `- **Impact:** ${problem.impact}\n`;
formatted += `- **Solution:** ${problem.solution}\n`;
if (problem.framework) {
formatted += `- **Framework:** ${problem.framework}\n`;
}
formatted += '\n';
return formatted;
}
}
//# sourceMappingURL=problem-handler.js.map