Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

get_collection_stats

Retrieve detailed statistics about a MongoDB collection including document count, storage metrics, index sizes, and average document size for database analysis and optimization.

Instructions

Get detailed statistics about a collection.

Returns information about:

  • Document count and size

  • Storage metrics

  • Index sizes and usage

  • Average document size

  • Padding factor

Input Schema

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

Implementation Reference

  • Handler for get_collection_stats tool: extracts database and collection from arguments, connects to the database, runs db.command({ collStats: collection }) to get statistics, and returns them as JSON text content.
    case 'get_collection_stats': {
      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 stats = await db.command({ collStats: collection });
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(stats, null, 2),
          },
        ],
      };
    }
  • src/index.ts:550-574 (registration)
    Registration of get_collection_stats tool in the ListTools response, including name, description, and input schema definition.
            {
              name: 'get_collection_stats',
              description: `Get detailed statistics about a collection.
    
    Returns information about:
    - Document count and size
    - Storage metrics
    - Index sizes and usage
    - Average document size
    - Padding factor`,
              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 for get_collection_stats tool defining parameters database (optional string) and collection (required string).
    inputSchema: {
      type: 'object',
      properties: {
        database: {
          type: 'string',
          description: 'Database name (optional if default database is configured)',
        },
        collection: {
          type: 'string',
          description: 'Collection name',
        },
      },
      required: ['collection'],
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what information is returned but doesn't describe whether this is a read-only operation, performance characteristics, permission requirements, error conditions, or response format. The description adds some context about return content but lacks critical behavioral details.

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

Conciseness4/5

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

The description is appropriately sized with two sentences: a clear purpose statement followed by a bulleted list of return information. The structure is front-loaded with the main purpose, though the bulleted list could potentially be more concise. Overall, it's efficient with minimal waste.

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?

For a read operation with 2 parameters and 100% schema coverage but no output schema, the description provides adequate but incomplete context. It explains what statistics are returned but not the format, structure, or units of the response. Given the complexity of statistical data and absence of output schema, more detail about the return format would be beneficial.

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%, so the schema already documents both parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline score of 3 is appropriate since the schema provides complete parameter documentation.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get detailed statistics about a collection' with specific metrics listed. It distinguishes from siblings like 'list_collections' (which lists names) and 'get_schema' (which describes structure), but doesn't explicitly differentiate from all statistical siblings like 'count_documents' or 'get_distinct_values'.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention when this statistical overview is preferable to specific tools like 'count_documents' for document count or 'get_indexes' for index information, nor does it specify prerequisites or exclusions.

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

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