Skip to main content
Glama

MongoDB MCP Server

list-collections

Retrieve all collections within a specified database for MongoDB, enabling efficient database management and exploration via the MongoDB MCP Server.

Instructions

List all collections for a given database

Input Schema

NameRequiredDescriptionDefault
databaseYesDatabase name

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "database": { "description": "Database name", "type": "string" } }, "required": [ "database" ], "type": "object" }

Implementation Reference

  • The main handler function that executes the tool logic: connects to the MongoDB provider, lists collections for the given database, and returns formatted text results or a message if none found.
    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: `No collections found for database "${database}". To create a collection, use the "create-collection" tool.`, }, ], }; } return { content: collections.map((collection) => { return { text: `Name: "${collection.name}"`, type: "text", }; }), }; }
  • Tool metadata including name, description, input schema (requires 'database' parameter), and operation type.
    protected name = "list-collections"; protected description = "List all collections for a given database"; protected argsShape = { database: DbOperationArgs.database, }; protected operationType: OperationType = "metadata";
  • Registers the ListCollectionsTool (imported earlier) within the array of all MongoDB tools, which is later used in server.ts to add tools to the MCP server.
    export const MongoDbTools = [ ConnectTool, ListCollectionsTool, ListDatabasesTool, CollectionIndexesTool, CreateIndexTool, CollectionSchemaTool, FindTool, InsertManyTool, DeleteManyTool, CollectionStorageSizeTool, CountTool, DbStatsTool, AggregateTool, UpdateManyTool, RenameCollectionTool, DropDatabaseTool, DropCollectionTool, ExplainTool, CreateCollectionTool, LogsTool, ];

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/officialpraise/mcp'

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