Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

list-databases

Read-only

Retrieve a list of all databases available in a MongoDB connection to identify and access database resources.

Instructions

List all databases for a MongoDB connection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
databasesYes
totalCountYes

Implementation Reference

  • The `execute` method implements the core logic of the 'list-databases' tool, connecting to MongoDB, fetching databases with sizes, and returning formatted text and structured content.
    protected async execute(): Promise<CallToolResult> {
        const provider = await this.ensureConnected();
        const dbs = (await provider.listDatabases("")).databases as { name: string; sizeOnDisk: bson.Long }[];
        const databases = dbs.map((db) => ({
            name: db.name,
            size: Number(db.sizeOnDisk),
        }));
    
        return {
            content: formatUntrustedData(
                `Found ${dbs.length} databases`,
                ...dbs.map((db) => `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`)
            ),
            structuredContent: {
                databases,
                totalCount: databases.length,
            },
        };
    }
  • Zod schema defining the structured output for the list-databases tool, including an array of database names and sizes, and total count.
    export const ListDatabasesOutputSchema = {
        databases: z.array(
            z.object({
                name: z.string(),
                size: z.number(),
            })
        ),
        totalCount: z.number(),
    };
  • Exports the ListDatabasesTool class, making it available for inclusion in the AllTools array used by the server for tool registration.
    export { ListDatabasesTool } from "./metadata/listDatabases.js";
  • The full ListDatabasesTool class definition, including name, description, schemas, and execute handler for the 'list-databases' tool.
    export class ListDatabasesTool extends MongoDBToolBase {
        public name = "list-databases";
        protected description = "List all databases for a MongoDB connection";
        protected argsShape = {};
        protected override outputSchema = ListDatabasesOutputSchema;
        static operationType: OperationType = "metadata";
    
        protected async execute(): Promise<CallToolResult> {
            const provider = await this.ensureConnected();
            const dbs = (await provider.listDatabases("")).databases as { name: string; sizeOnDisk: bson.Long }[];
            const databases = dbs.map((db) => ({
                name: db.name,
                size: Number(db.sizeOnDisk),
            }));
    
            return {
                content: formatUntrustedData(
                    `Found ${dbs.length} databases`,
                    ...dbs.map((db) => `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`)
                ),
                structuredContent: {
                    databases,
                    totalCount: databases.length,
                },
            };
        }
    }
  • AllTools array construction that includes MongoDbTools (which exports ListDatabasesTool), used by server.ts for registering all tools including 'list-databases'.
    export const AllTools: ToolClass[] = Object.values({
        ...MongoDbTools,
        ...AtlasTools,
        ...AtlasLocalTools,
    });
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and destructiveHint=false, so the agent knows this is a safe read operation. The description adds minimal behavioral context beyond that, as it doesn't specify details like output format, pagination, or error handling. With annotations covering safety, a 3 is appropriate—the description adds some value but not rich behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It's appropriately sized for a simple tool with no parameters, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, read-only per annotations, and an output schema exists), the description is mostly complete. It states what the tool does, but lacks usage guidelines or differentiation from siblings. The output schema handles return values, so the description doesn't need to explain those, keeping it adequate for the context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are 0 parameters, and schema description coverage is 100%, so the schema fully documents the input (none). The description doesn't need to add parameter details, but it implicitly confirms no inputs are required by focusing on the action. Baseline for 0 params is 4, as the description aligns with the schema's emptiness.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List') and resource ('all databases for a MongoDB connection'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'list-collections' or 'atlas-list-clusters', which would require more specificity about scope or context to earn a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list-collections' (for collections within a database) or 'atlas-list-clusters' (for MongoDB Atlas clusters). It lacks any context about prerequisites, such as needing an active connection, or exclusions, leaving the agent to infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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