Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

mongodb_list_collections

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

Instructions

List all collections in the MongoDB database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the mongodb_list_collections tool. Ensures MongoDB connection, lists collections using listCollections().toArray(), and returns JSON-formatted list.
    private async handleMongoDBListCollections() {
      await this.ensureMongoConnection();
    
      try {
        const collections = await this.mongoDB!.listCollections().toArray();
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(collections, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to list collections: ${getErrorMessage(error)}`
        );
      }
    }
  • src/index.ts:399-407 (registration)
    Tool registration in the listTools handler, defining name, description, and empty input schema (no parameters required).
    {
      name: 'mongodb_list_collections',
      description: 'List all collections in the MongoDB database',
      inputSchema: {
        type: 'object',
        properties: {},
        required: [],
      },
    },
  • src/index.ts:554-555 (registration)
    Dispatcher case in CallToolRequestHandler that routes calls to the handleMongoDBListCollections method.
    case 'mongodb_list_collections':
      return await this.handleMongoDBListCollections();
  • Input schema definition for the tool: empty object with no required properties.
      inputSchema: {
        type: 'object',
        properties: {},
        required: [],
      },
    },

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/yaoxiaolinglong/mcp-mongodb-mysql-server'

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