Skip to main content
Glama
ricleedo

MCP Server Boilerplate

by ricleedo

mongo-list-collections

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

Instructions

List all collections in a MongoDB database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name

Implementation Reference

  • src/index.ts:293-318 (registration)
    Registration of the 'mongo-list-collections' tool using server.tool(), including name, description, input schema, and inline handler function.
    server.tool(
      "mongo-list-collections",
      "List all collections in a MongoDB database",
      {
        database: z.string().describe("Database name"),
      },
      async ({ database: dbName }) => {
        try {
          const db = await ensureConnection(dbName);
          
          const collections = await db.listCollections().toArray();
          const collectionNames = collections.map(col => col.name);
          
          return {
            content: [
              {
                type: "text",
                text: `Collections in database '${dbName}':\n${collectionNames.join('\n')}`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to list collections: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    );
  • The core handler function that ensures a connection to the specified database, lists collections using db.listCollections(), extracts names, and returns formatted text output.
    async ({ database: dbName }) => {
      try {
        const db = await ensureConnection(dbName);
        
        const collections = await db.listCollections().toArray();
        const collectionNames = collections.map(col => col.name);
        
        return {
          content: [
            {
              type: "text",
              text: `Collections in database '${dbName}':\n${collectionNames.join('\n')}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to list collections: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Input schema using Zod, requiring a 'database' string parameter.
    {
      database: z.string().describe("Database name"),
    },
  • Helper function to establish and cache MongoDB connection and database instance, called by the handler.
    async function ensureConnection(dbName: string): Promise<Db> {
      if (!mongoClient) {
        const uri = getMongoUri();
        mongoClient = new MongoClient(uri);
        await mongoClient.connect();
      }
      
      if (!databases.has(dbName)) {
        databases.set(dbName, mongoClient.db(dbName));
      }
      
      return databases.get(dbName)!;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. While 'List all collections' implies a read-only operation, it doesn't disclose important behavioral traits like whether this requires specific permissions, what format the output takes (e.g., array of collection names), or any rate limits. The description is minimal and lacks operational 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 directly states the tool's purpose without unnecessary words. It's appropriately sized for a simple tool and front-loads the essential information. Every word earns its place.

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?

For a simple read operation with 1 parameter and no output schema, the description is minimally adequate but lacks completeness. It doesn't explain what the output looks like (e.g., list of collection names) or mention any constraints. While the tool is straightforward, the description could benefit from slightly more operational context given the absence of annotations.

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%, so the schema already documents the single 'database' parameter. The description doesn't add any parameter-specific information beyond what's in the schema, such as format examples or constraints. With complete schema coverage, the baseline score of 3 is appropriate.

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 all collections') and resource ('in a MongoDB database'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'mongo-find-documents' which also lists data but at a document level rather than collection level.

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 that this is for listing collections (not documents) or compare it to sibling tools like 'mongo-find-documents' which operates at a different level of granularity. No context about prerequisites or exclusions is provided.

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/ricleedo/mongo-boilerplate-mcp'

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