get_query_performance
Analyze SQL query performance to identify slow queries and optimize database operations. Filter by specific tools and set limits for targeted performance breakdown.
Instructions
Get detailed query performance breakdown by tool
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of queries to analyze (optional, defaults to 50) | |
| tool_filter | No | Filter by specific MCP tool name (optional) | |
| slow_only | No | Only return slow queries (optional, defaults to false) |
Implementation Reference
- index.js:595-610 (handler)The main handler function for the 'get_query_performance' tool. It retrieves query performance statistics from the PerformanceMonitor instance and returns them formatted as a JSON text response.getQueryPerformance(limit = 50) { const queryStats = this.performanceMonitor.getQueryStats(limit); return [ { type: 'text', text: JSON.stringify( { success: true, data: queryStats }, null, 2 ) } ]; }
- lib/tools/tool-registry.js:118-135 (schema)The tool schema definition including name, description, and input schema for validation.{ name: 'get_query_performance', description: 'Get detailed query performance breakdown by tool', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of queries to analyze (optional, defaults to 50)' }, tool_filter: { type: 'string', description: 'Filter by specific MCP tool name (optional)' }, slow_only: { type: 'boolean', description: 'Only return slow queries (optional, defaults to false)' } } } },
- index.js:318-321 (registration)The switch case registration/dispatch that maps the tool name to its handler function during tool call handling.case 'get_query_performance': return { content: this.getQueryPerformance(args.limit) };
- The core helper function getQueryStats in PerformanceMonitor class that processes query metrics, groups by tool, calculates statistics like average time, error rates, and returns detailed performance breakdown.getQueryStats(limit = 50) { if (!this.config.enabled) { return { enabled: false }; } const completedQueries = this.metrics.queries .filter(q => q.status === 'completed' || q.status === 'error') .sort((a, b) => b.startTime - a.startTime) .slice(0, limit); // Group by tool const byTool = {}; completedQueries.forEach(query => { if (!byTool[query.tool]) { byTool[query.tool] = { count: 0, totalTime: 0, errors: 0, slowQueries: 0 }; } byTool[query.tool].count++; byTool[query.tool].totalTime += query.duration; if (query.status === 'error') { byTool[query.tool].errors++; } if (query.duration > this.config.slowQueryThreshold) { byTool[query.tool].slowQueries++; } }); // Calculate averages Object.keys(byTool).forEach(tool => { const stats = byTool[tool]; stats.avgTime = stats.totalTime / stats.count; stats.errorRate = (stats.errors / stats.count) * 100; stats.slowQueryRate = (stats.slowQueries / stats.count) * 100; }); return { enabled: true, queries: completedQueries.map(q => ({ tool: q.tool, duration: q.duration, status: q.status, rowCount: q.rowCount, streaming: q.streaming, timestamp: q.startTime })), byTool, slowQueries: completedQueries.filter(q => q.duration > this.config.slowQueryThreshold) }; }