db-stats
Retrieve database usage statistics to monitor storage, collections, and performance metrics for MongoDB databases.
Instructions
Returns statistics that reflect the use state of a single database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name |
Implementation Reference
- The main handler function that ensures connection to MongoDB, executes the 'dbStats' command on the specified database with scale:1, formats the result using EJSON and formatUntrustedData, and returns it as tool content.protected async execute({ database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const provider = await this.ensureConnected(); const result = await provider.runCommandWithCheck(database, { dbStats: 1, scale: 1, }); return { content: formatUntrustedData(`Statistics for database ${database}`, EJSON.stringify(result)), }; }
- Zod schema defining the input arguments: requires a 'database' string parameter.protected argsShape = { database: DbOperationArgs.database, };
- src/tools/mongodb/metadata/dbStats.ts:8-15 (registration)Tool metadata definition including name 'db-stats', description, input schema (argsShape), and static operationType 'metadata' used during class instantiation and MCP server registration via ToolBase.register().public name = "db-stats"; protected description = "Returns statistics that reflect the use state of a single database"; protected argsShape = { database: DbOperationArgs.database, }; static operationType: OperationType = "metadata";
- src/tools/mongodb/tools.ts:12-12 (registration)Barrel export of DbStatsTool making it available for inclusion in the AllTools array in src/tools/index.ts, from which the server instantiates and registers all tools.export { DbStatsTool } from "./metadata/dbStats.js";
- src/tools/index.ts:7-11 (registration)Collects all tool classes (including DbStatsTool via MongoDbTools) into AllTools array, which is used by Server.registerTools() to instantiate each tool with session/config/etc. and call register() to add to MCP server.export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });