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
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database 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, };
- src/tools/mongodb/tools.ts:22-43 (registration)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); } }
- src/tools/mongodb/metadata/listCollections.ts:6-6 (registration)Sets the tool name to 'list-collections' within the tool class.protected name = "list-collections";