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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:956-975 (handler)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();
- src/index.ts:402-407 (schema)Input schema definition for the tool: empty object with no required properties.inputSchema: { type: 'object', properties: {}, required: [], }, },