Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

list-collections

Read-only

Retrieve all collections from a specified MongoDB database to view available data structures and manage database organization.

Instructions

List all collections for a given database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name

Implementation Reference

  • The handler function that implements the core logic of the 'list-collections' tool: connects to the MongoDB provider, lists collections for the given database, and formats the response appropriately, handling empty cases.
    protected async execute({ database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
        const provider = await this.ensureConnected();
        const collections = await provider.listCollections(database);
    
        if (collections.length === 0) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Found 0 collections for database "${database}". To create a collection, use the "create-collection" tool.`,
                    },
                ],
            };
        }
    
        return {
            content: formatUntrustedData(
                `Found ${collections.length} collections for database "${database}".`,
                collections.map((collection) => `"${collection.name}"`).join("\n")
            ),
        };
    }
  • Defines the input schema for the tool, requiring a 'database' parameter from DbOperationArgs.
    protected argsShape = {
        database: DbOperationArgs.database,
    };
  • Sets the tool's name to 'list-collections', identifying it in the MCP tool registry.
    public name = "list-collections";
  • Re-exports the ListCollectionsTool class from its implementation file for inclusion in the MongoDB tools module.
    export { ListCollectionsTool } from "./metadata/listCollections.js";
  • Imports the MongoDB tools module (including ListCollectionsTool) and includes it in the AllTools array, which is used by the server to register all available tools.
    import * as MongoDbTools from "./mongodb/tools.js";
    import type { ToolClass } from "./tool.js";
    
    // Export the collection of tools for easier reference
    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 context by specifying it lists 'all collections' for a database, which clarifies scope. However, it doesn't describe behavioral traits like pagination, rate limits, or what happens if the database doesn't exist. With annotations covering safety, a 3 is appropriate as the description adds some value but not rich behavioral context.

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 action ('List all collections') and specifies the context ('for a given database'). There is zero waste or redundancy, making it highly concise and well-structured for quick understanding.

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

Completeness3/5

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

Given the tool's low complexity (one parameter, read-only per annotations) and no output schema, the description is minimally adequate. It states what the tool does but lacks details on return values (e.g., format of the list) or error conditions. With annotations covering safety, it's complete enough for basic use but could be more informative for an agent.

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

Parameters3/5

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

Schema description coverage is 100%, with the single parameter 'database' documented as 'Database name'. The description adds no additional meaning beyond this, such as format examples or constraints. Since the schema fully describes the parameter, the baseline is 3 even without extra param info in the description.

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 verb 'list' and the resource 'collections', specifying it's for a given database. It distinguishes from sibling tools like 'list-databases' which lists databases rather than collections. However, it doesn't explicitly differentiate from tools like 'collection-indexes' or 'collection-schema' that also operate on collections, so it's not a perfect 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. It doesn't mention prerequisites (e.g., needing an existing database), exclusions, or compare to siblings like 'list-databases' (which might be a precursor) or 'collection-storage-size' (which provides different collection data). Usage is implied but not explicitly stated.

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