Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

collection-indexes

Read-only

Describe indexes for a MongoDB collection to understand query performance and optimize database operations by analyzing index structure and usage.

Instructions

Describe the indexes for a collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name
collectionYesCollection name

Implementation Reference

  • The main handler function that connects to MongoDB, fetches regular indexes and optional search indexes, formats them as JSON strings in the tool response.
    protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
        const provider = await this.ensureConnected();
        const indexes = await provider.getIndexes(database, collection);
        const indexDefinitions: IndexStatus[] = indexes.map((index) => ({
            name: index.name as string,
            key: index.key as Document,
        }));
    
        const searchIndexDefinitions: SearchIndexStatus[] = [];
        if (this.isFeatureEnabled("search") && (await this.session.isSearchSupported())) {
            const searchIndexes = await provider.getSearchIndexes(database, collection);
            searchIndexDefinitions.push(...this.extractSearchIndexDetails(searchIndexes));
        }
    
        return {
            content: [
                ...formatUntrustedData(
                    `Found ${indexDefinitions.length} indexes in the collection "${collection}":`,
                    ...indexDefinitions.map((i) => JSON.stringify(i))
                ),
                ...(searchIndexDefinitions.length > 0
                    ? formatUntrustedData(
                          `Found ${searchIndexDefinitions.length} search and vector search indexes in the collection "${collection}":`,
                          ...searchIndexDefinitions.map((i) => JSON.stringify(i))
                      )
                    : []),
            ],
        };
  • Zod schema defining the input arguments 'database' and 'collection' used by the collection-indexes tool and other MongoDB tools.
    export const DbOperationArgs = {
        database: z.string().describe("Database name"),
        collection: z.string().describe("Collection name"),
    };
  • Tool class definition including the unique name 'collection-indexes', description, input schema reference, and operation type.
    export class CollectionIndexesTool extends MongoDBToolBase {
        public name = "collection-indexes";
        protected description = "Describe the indexes for a collection";
        protected argsShape = DbOperationArgs;
        static operationType: OperationType = "metadata";
  • Re-export of the CollectionIndexesTool class from the MongoDB tools barrel file for easy import and registration.
    export { CollectionIndexesTool } from "./metadata/collectionIndexes.js";
  • Helper method to extract relevant details from search index definitions, simplifying status, queryability, and definition for the response.
    protected extractSearchIndexDetails(indexes: Record<string, unknown>[]): SearchIndexStatus[] {
        return indexes.map((index) => ({
            name: (index["name"] ?? "default") as string,
            type: (index["type"] ?? "UNKNOWN") as string,
            status: (index["status"] ?? "UNKNOWN") as string,
            queryable: (index["queryable"] ?? false) as boolean,
            latestDefinition: index["latestDefinition"] as Document,
        }));
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=true and destructiveHint=false, so the agent knows this is a safe read operation. The description adds no behavioral context beyond this, such as rate limits, authentication needs, or what 'Describe' entails (e.g., returns index details). It does not contradict annotations, but offers minimal value beyond them.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It is front-loaded, immediately stating the tool's purpose without unnecessary elaboration. Every part of the sentence earns its place by conveying essential information directly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (2 parameters, no output schema) and rich annotations (read-only, non-destructive), the description is minimally adequate. It states what the tool does but lacks details on output format or usage context. For a simple read tool, this is acceptable but leaves gaps in guiding the agent fully.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for 'database' and 'collection' parameters. The description does not add meaning beyond the schema, such as explaining parameter relationships or constraints. With high schema coverage, the baseline score of 3 is appropriate, as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Describe the indexes for a collection' states the tool's purpose clearly with a verb ('Describe') and resource ('indexes for a collection'), but it does not differentiate from siblings like 'collection-schema' or 'collection-storage-size', which also describe collection metadata. It avoids tautology by specifying what is described (indexes), but lacks specificity on scope or format.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, such as needing an existing database and collection, or compare it to siblings like 'list-collections' for broader metadata. Without explicit when/when-not instructions, the agent must infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mongodb-js/mongodb-mcp-server'

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