list-collections
List all collections within a specified MongoDB database using the MongoDB MCP Server. Ideal for managing and organizing database resources efficiently.
Instructions
List all collections for a given database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name |
Implementation Reference
- Implements the core logic of the 'list-collections' tool: connects to MongoDB, lists collections for the given database, and formats the response as text content.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: `Found 0 collections for database "${database}". To create a collection, use the "create-collection" tool.`, }, ], }; } return { content: formatUntrustedData( `Found ${collections.length} collections for database "${database}".`, collections.map((collection) => `"${collection.name}"`).join("\n") ), }; }
- Defines the input schema for the tool, requiring a 'database' parameter.protected argsShape = { database: DbOperationArgs.database, };
- src/tools/mongodb/metadata/listCollections.ts:6-14 (registration)The ListCollectionsTool class definition, including the tool name 'list-collections', description, args shape, and operation type, serving as the registration point for the tool.export class ListCollectionsTool extends MongoDBToolBase { public name = "list-collections"; protected description = "List all collections for a given database"; protected argsShape = { database: DbOperationArgs.database, }; static operationType: OperationType = "metadata";