Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

get_collection_stats

Retrieve detailed collection statistics for MongoDB, including document count, size, storage metrics, index usage, and average document size. Analyze and optimize data efficiency with actionable insights.

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
collectionYesCollection name
databaseNoDatabase name (optional if default database is configured)

Implementation Reference

  • The handler for the get_collection_stats tool. It extracts the database and collection names from arguments, connects to the appropriate database, runs the MongoDB collStats command, and returns the statistics as JSON.
    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:551-574 (registration)
    Registration of the get_collection_stats tool in the MCP server's list of available tools, including its name, description, and input schema.
    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 the get_collection_stats tool defining parameters for database (optional) and required collection name.
    inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, collection: { type: 'string', description: 'Collection name', }, }, required: ['collection'], },

Other Tools

Related 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