Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

list_collections

Retrieve all collection names in a MongoDB database to identify available data structures before executing queries.

Instructions

List all collections in a database.

Start here to understand what collections are available before querying.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (optional if default database is configured)

Implementation Reference

  • The handler function for the 'list_collections' tool. It extracts the optional database name from arguments, connects to the specified or default database, lists all collections using db.listCollections().toArray(), and returns the result as JSON-formatted text content.
    case 'list_collections': {
      const { database } = request.params.arguments as { database?: string };
      const dbName = database || this.defaultDatabase;
      if (!dbName) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'Database name is required when no default database is configured'
        );
      }
      const db = client.db(dbName);
      const collections = await db.listCollections().toArray();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(collections, null, 2),
          },
        ],
      };
    }
  • Input schema definition for the 'list_collections' tool, specifying an optional 'database' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        database: {
          type: 'string',
          description: 'Database name (optional if default database is configured)',
        },
      },
    },
  • src/index.ts:320-334 (registration)
    Registration of the 'list_collections' tool in the list of tools provided by the ListToolsRequestSchema handler, including name, description, and input schema.
            {
              name: 'list_collections',
              description: `List all collections in a database.
              
    Start here to understand what collections are available before querying.`,
              inputSchema: {
                type: 'object',
                properties: {
                  database: {
                    type: 'string',
                    description: 'Database name (optional if default database is configured)',
                  },
                },
              },
            },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool lists collections but doesn't describe behavioral traits like whether it requires authentication, has rate limits, returns paginated results, or what happens if the database doesn't exist. For a tool with zero annotation coverage, this leaves significant gaps in understanding its operation.

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 concise and well-structured with two sentences: the first states the purpose, and the second provides usage guidance. Every sentence adds value without redundancy, and it's front-loaded with the core functionality. There's no wasted text or unnecessary elaboration.

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 optional parameter, no output schema), the description is minimally adequate. It covers purpose and usage but lacks behavioral details due to no annotations. For a simple list operation, this might suffice, but without output schema or annotations, it doesn't fully prepare an agent for invocation (e.g., missing info on return format or error handling).

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 documented as optional if a default is configured. The description doesn't add any parameter-specific information beyond what the schema provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't need to.

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 tool's purpose: 'List all collections in a database.' It specifies the verb ('List') and resource ('collections'), and distinguishes it from siblings like 'list_databases' by focusing on collections within a database. However, it doesn't explicitly differentiate from other collection-related tools like 'get_collection_stats' or 'get_schema'.

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

Usage Guidelines4/5

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

The description provides clear usage context: 'Start here to understand what collections are available before querying.' This indicates when to use the tool (as a preliminary step before querying) and implies it's for discovery rather than data retrieval. However, it doesn't explicitly state when not to use it or name alternatives like 'list_databases' for broader scope.

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

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