Skip to main content
Glama
officialpraise

MongoDB MCP Server

list-collections

Retrieve all collections from a specified MongoDB database to view available data structures and organize database content.

Instructions

List all collections for a given database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name

Implementation Reference

  • The execute method implements the core logic of the 'list-collections' tool by ensuring a MongoDB connection, listing collections for the specified database, and returning formatted text results or a no-collections message.
    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", }; }), }; }
  • Defines the input schema for the 'list-collections' tool, requiring a 'database' parameter.
    protected argsShape = { database: DbOperationArgs.database, };
  • Registers the ListCollectionsTool as part of the MongoDbTools array, which collects all MongoDB-related tools.
    export const MongoDbTools = [ ConnectTool, ListCollectionsTool, ListDatabasesTool, CollectionIndexesTool, CreateIndexTool, CollectionSchemaTool, FindTool, InsertManyTool, DeleteManyTool, CollectionStorageSizeTool, CountTool, DbStatsTool, AggregateTool, UpdateManyTool, RenameCollectionTool, DropDatabaseTool, DropCollectionTool, ExplainTool, CreateCollectionTool, LogsTool, ];
  • src/server.ts:141-145 (registration)
    The registerTools method instantiates and registers all tools from MongoDbTools (including ListCollectionsTool) on the MCP server.
    private registerTools() { for (const tool of [...AtlasTools, ...MongoDbTools]) { new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer); } }
  • Sets the tool name to 'list-collections' within the tool class.
    protected name = "list-collections";

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