get_indexes
Retrieve detailed information about indexes on a MongoDB collection, including names, fields, types, sizes, options, and usage statistics, to optimize database performance and analysis.
Instructions
Get information about indexes on a collection.
Returns details about:
Index names and fields
Index types (single field, compound, text, etc.)
Index sizes
Index options
Usage statistics
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| database | No | Database name (optional if default database is configured) |
Input Schema (JSON Schema)
{
"properties": {
"collection": {
"description": "Collection name",
"type": "string"
},
"database": {
"description": "Database name (optional if default database is configured)",
"type": "string"
}
},
"required": [
"collection"
],
"type": "object"
}
Implementation Reference
- src/index.ts:1216-1239 (handler)The handler function for the 'get_indexes' tool. It connects to the specified database and collection, then calls collection.indexes() to retrieve all index information, returning it as JSON.case 'get_indexes': { const { database, collection } = request.params.arguments as { database?: string; collection: string; }; const dbName = database || this.defaultDatabase; if (!dbName) { throw new McpError( ErrorCode.InvalidRequest, 'Database name is required when no default database is configured' ); } const db = client.db(dbName); const indexes = await db.collection(collection).indexes(); return { content: [ { type: 'text', text: JSON.stringify(indexes, null, 2), }, ], }; }
- src/index.ts:576-598 (registration)Registration of the 'get_indexes' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.name: 'get_indexes', description: `Get information about indexes on a collection. Returns details about: - Index names and fields - Index types (single field, compound, text, etc.) - Index sizes - Index options - Usage statistics`, inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, collection: { type: 'string', description: 'Collection name', }, }, required: ['collection'], },
- src/index.ts:585-598 (schema)Input schema definition for the 'get_indexes' tool, specifying parameters for database and collection.inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, collection: { type: 'string', description: 'Collection name', }, }, required: ['collection'], },