get_query_performance
Analyze SQL query performance to identify bottlenecks and optimize database operations by examining execution details and slow queries.
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) | |
| slow_only | No | Only return slow queries (optional, defaults to false) | |
| tool_filter | No | Filter by specific MCP tool name (optional) |
Implementation Reference
- index.js:595-610 (handler)Main handler function for the 'get_query_performance' MCP tool. Retrieves query performance data from the PerformanceMonitor and formats it 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 ) } ]; }
- Core utility method that implements the query performance analysis logic: filters completed queries, groups by tool, computes statistics like average time, error rates, slow query rates, and returns detailed 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) }; }
- lib/tools/tool-registry.js:119-135 (schema)Tool definition including input schema for validation. Defines parameters: limit (number), tool_filter (string), slow_only (boolean). Used by ListTools endpoint.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)Registration/dispatch in the central CallToolRequest handler switch statement that maps the tool name to its execution.case 'get_query_performance': return { content: this.getQueryPerformance(args.limit) };