Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

get_indexes

Retrieve detailed information about MongoDB collection indexes, including names, fields, types, sizes, options, and usage statistics to optimize database performance.

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

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (optional if default database is configured)
collectionYesCollection name

Implementation Reference

  • Handler for 'get_indexes' tool: connects to the specified database, retrieves the indexes for the given collection using MongoDB's indexes() method, and returns the results as formatted JSON text content.
    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 list_tools response, 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'],
              },
  • Input schema definition for the 'get_indexes' tool, specifying parameters for database (optional) and required collection name.
              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'],
              },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonfreeland/mongodb-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server