db-stats
Retrieve usage statistics for a specific MongoDB database to monitor its state and performance. Input the database name to analyze key metrics.
Instructions
Returns statistics that reflect the use state of a single database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"database": {
"description": "Database name",
"type": "string"
}
},
"required": [
"database"
],
"type": "object"
}
Implementation Reference
- The execute method implements the core logic of the 'db-stats' tool: connects to MongoDB, runs the dbStats command on the specified database, and returns the statistics as text 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: [ { text: `Statistics for database ${database}`, type: "text", }, { text: EJSON.stringify(result), type: "text", }, ], }; }
- Defines the input schema for the tool, requiring a 'database' parameter.protected argsShape = { database: DbOperationArgs.database, };
- src/server.ts:141-145 (registration)Registers all tools including DbStatsTool (via MongoDbTools) by instantiating and calling register on the MCP server.private registerTools() { for (const tool of [...AtlasTools, ...MongoDbTools]) { new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer); } }
- src/tools/mongodb/tools.ts:22-43 (registration)DbStatsTool is included in the MongoDbTools array, which collects all MongoDB-related tools for registration.export const MongoDbTools = [ ConnectTool, ListCollectionsTool, ListDatabasesTool, CollectionIndexesTool, CreateIndexTool, CollectionSchemaTool, FindTool, InsertManyTool, DeleteManyTool, CollectionStorageSizeTool, CountTool, DbStatsTool, AggregateTool, UpdateManyTool, RenameCollectionTool, DropDatabaseTool, DropCollectionTool, ExplainTool, CreateCollectionTool, LogsTool, ];
- Full DbStatsTool class definition, including name, description, schema, and handler implementation.export class DbStatsTool extends MongoDBToolBase { protected name = "db-stats"; protected description = "Returns statistics that reflect the use state of a single database"; protected argsShape = { database: DbOperationArgs.database, }; protected operationType: OperationType = "metadata"; 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: [ { text: `Statistics for database ${database}`, type: "text", }, { text: EJSON.stringify(result), type: "text", }, ], }; } }