Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

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
NameRequiredDescriptionDefault
databaseYesDatabase 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, };
  • 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";
  • 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";
  • 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, });

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

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