get_index_recommendations
Analyze SQL Server databases to identify missing indexes that improve query performance and optimize database operations based on impact scoring.
Instructions
Get index recommendations for database optimization
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional) | |
| impact_threshold | No | Minimum impact score threshold (0-100, optional) | |
| limit | No | Maximum number of recommendations to return (optional, defaults to 10) | |
| schema | No | Schema name (optional, defaults to dbo) |
Implementation Reference
- index.js:637-656 (handler)Main handler function that executes the tool logic by calling QueryOptimizer.analyzeIndexUsage and formatting the JSON response.async getIndexRecommendations(database) { try { const recommendations = await this.queryOptimizer.analyzeIndexUsage(database); return [ { type: 'text', text: JSON.stringify( { success: true, data: recommendations }, null, 2 ) } ]; } catch (error) { throw new McpError(ErrorCode.InternalError, error.message); } }
- index.js:328-331 (registration)Switch case that registers and dispatches the tool call to the handler method.case 'get_index_recommendations': return { content: await this.getIndexRecommendations(args.database) };
- lib/tools/tool-registry.js:176-194 (schema)Tool definition including name, description, and input schema validation.{ name: 'get_index_recommendations', description: 'Get index recommendations for database optimization', inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' }, limit: { type: 'number', description: 'Maximum number of recommendations to return (optional, defaults to 10)' }, impact_threshold: { type: 'number', description: 'Minimum impact score threshold (0-100, optional)' } } } },
- Supporting function that provides the actual index recommendations (delegated by the handler).async analyzeIndexUsage(database) { // Basic index recommendations - this would normally query SQL Server DMVs return { database, timestamp: new Date().toISOString(), recommendations: [ { type: 'missing_index', priority: 'high', suggestion: 'Consider adding indexes on frequently queried columns', impact: 'Could improve query performance by 50-80%', table: 'example_table', columns: ['column1', 'column2'] } ], unusedIndexes: [], duplicateIndexes: [], fragmentedIndexes: [] }; }