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
144 lines • 5.82 kB
JavaScript
import { BaseToolHandler } from '../base-handler.js';
import { AIStackDetector } from '../../ai-stack-detector.js';
import { LocalDebugEngine } from '../../local-debug-engine.js';
import { AIExtractionUtils } from './ai-utils.js';
export class AIRAGHandler extends BaseToolHandler {
detector;
tools = [
{
name: 'debug_document_processing',
description: 'Debug document parsing, chunking, and processing pipelines',
inputSchema: {
type: 'object',
properties: {
sessionId: { type: 'string', description: 'Debug session ID' },
documentType: { type: 'string', description: 'Filter by document type (e.g., PDF, DOCX)' }
},
required: ['sessionId']
}
},
{
name: 'debug_rag_pipeline',
description: 'Debug end-to-end RAG pipeline flow and performance',
inputSchema: {
type: 'object',
properties: {
sessionId: { type: 'string', description: 'Debug session ID' },
traceId: { type: 'string', description: 'Optional trace ID to follow specific request' }
},
required: ['sessionId']
}
}
];
constructor() {
super();
this.detector = new AIStackDetector();
}
async handle(toolName, args, sessions) {
const session = sessions.get(args.sessionId);
if (!session) {
return {
content: [{ type: 'text', text: `Session not found: ${args.sessionId}` }]
};
}
try {
switch (toolName) {
case 'debug_document_processing':
return await this.debugDocumentProcessing(args, session);
case 'debug_rag_pipeline':
return await this.debugRAGPipeline(args, session);
default:
throw new Error(`Unknown tool: ${toolName}`);
}
}
catch (error) {
return {
content: [{
type: 'text',
text: `Error in ${toolName}: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
async debugDocumentProcessing(args, session) {
const engine = session.engine || new LocalDebugEngine();
const networkRequests = engine.getNetworkRequests();
const documentProcessing = AIExtractionUtils.extractDocumentProcessing(networkRequests);
const filteredDocs = args.documentType
? documentProcessing.filter(doc => doc.type === args.documentType)
: documentProcessing;
if (filteredDocs.length === 0) {
return {
content: [{
type: 'text',
text: '## Document Processing Debug\n\nNo document processing detected.'
}]
};
}
let report = '## Document Processing Debug\n\n';
for (const doc of filteredDocs) {
report += `### ${doc.type} Processing\n`;
report += `- **Type:** ${doc.type}\n`;
report += `- **Endpoint:** ${doc.endpoint}\n`;
if (doc.response) {
if (doc.response.pages) {
report += `- **Pages:** ${doc.response.pages}\n`;
}
if (doc.response.chunks) {
report += `- **Chunks Generated:** ${doc.response.chunks}\n`;
}
if (doc.response.averageChunkSize) {
report += `- **Average Chunk Size:** ${doc.response.averageChunkSize}\n`;
}
if (doc.response.processingTime) {
report += `- **Processing Time:** ${doc.response.processingTime}ms\n`;
}
}
report += '\n';
}
return {
content: [{ type: 'text', text: report }]
};
}
async debugRAGPipeline(args, session) {
const engine = session.engine || new LocalDebugEngine();
// Detect AI stack
const [llmProviders, vectorDBs, frameworks] = await Promise.all([
this.detector.detectLLMProviders(engine),
this.detector.detectVectorDBs(engine),
this.detector.detectFrameworks(session.page)
]);
let report = '## RAG Pipeline Debug\n\n';
// Stack detection
report += '### Stack Detected\n';
if (llmProviders.length > 0) {
report += `- **LLM:** ${llmProviders.map(p => p.name).join(', ')}\n`;
}
if (vectorDBs.length > 0) {
report += `- **Vector DB:** ${vectorDBs.map(v => v.name).join(', ')}\n`;
}
if (frameworks.length > 0) {
report += `- **Framework:** ${frameworks.map(f => `${f.name} v${f.version}`).join(', ')}\n`;
}
report += '\n';
// Pipeline flow analysis
const networkRequests = engine.getNetworkRequests();
const pipelineSteps = AIExtractionUtils.analyzePipelineFlow(networkRequests);
report += '### Pipeline Flow\n\n';
for (const step of pipelineSteps) {
report += `${step.order}. **${step.name}**\n`;
report += ` - Timestamp: ${step.timestamp.toISOString()}\n`;
if (step.duration) {
report += ` - Duration: ${step.duration}ms\n`;
}
if (step.details) {
report += ` - ${step.details}\n`;
}
report += '\n';
}
return {
content: [{ type: 'text', text: report }]
};
}
}
//# sourceMappingURL=ai-rag-handler.js.map