Skip to main content
Glama
CaptainCrouton89

MCP Server Boilerplate

mongo-list-collections

Retrieve all collection names from a specified 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

  • The handler function that ensures connection to the MongoDB database, lists all collections using db.listCollections(), maps to names, and returns a formatted text response with the list of collection names.
    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'}`);
      }
    }
  • Zod schema defining the input parameter 'database' as a required string.
    {
      database: z.string().describe("Database name"),
    },
  • src/index.ts:293-318 (registration)
    Registration of the 'mongo-list-collections' tool with server.tool(), including name, description, schema, and handler.
    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'}`);
        }
      }
    );
  • Helper function used by the tool to establish and cache MongoDB connection and database instance.
    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?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states a read operation ('List'), implying it's non-destructive, but doesn't cover aspects like permissions needed, rate limits, error conditions, or what the output looks like (e.g., format, pagination). This leaves significant gaps for a tool that interacts with a database.

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 function without unnecessary words. It's front-loaded and wastes no space, 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.

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, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavior, usage context, and output, which could be important for database operations. This aligns with a score of 3, indicating clear gaps in completeness despite the simple structure.

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?

The input schema has 100% description coverage, with the 'database' parameter clearly documented. The description adds no additional meaning beyond the schema, such as examples or constraints (e.g., database must exist). This meets the baseline score of 3, as the schema adequately covers parameter semantics without extra value from 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 action ('List all collections') and resource ('in a MongoDB database'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'mongo-find-documents' or 'mongo-aggregate', which operate on documents rather than collections, leaving some room for improvement in sibling distinction.

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 lacks context about prerequisites (e.g., database existence), exclusions, or comparisons to siblings like 'mongo-find-documents' for document-level operations, leaving the agent to infer usage based on tool names 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/CaptainCrouton89/mongo-mcp'

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