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
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional if default database is configured) | |
| collection | Yes | Collection name |
Implementation Reference
- src/index.ts:1191-1214 (handler)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'], }, },
- src/index.ts:560-573 (schema)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'], },