mongodb_list_collections
Retrieve all collections in a MongoDB database to manage or analyze data. Part of the MCP-MongoDB-MySQL-Server, this tool supports streamlined database operations and schema insights.
Instructions
List all collections in the MongoDB database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:956-975 (handler)The handler function that ensures MongoDB connection and lists all collections using this.mongoDB!.listCollections().toArray(), returning the JSON stringified collections.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:402-406 (schema)Input schema definition for the tool, which requires no parameters (empty object).inputSchema: { type: 'object', properties: {}, required: [], },
- src/index.ts:399-407 (registration)Tool registration in the tools array passed to server.setTools(), defining name, description, and schema.{ name: 'mongodb_list_collections', description: 'List all collections in the MongoDB database', inputSchema: { type: 'object', properties: {}, required: [], }, },
- src/index.ts:554-555 (registration)Switch case in the CallToolRequestHandler that dispatches calls to the specific handler function.case 'mongodb_list_collections': return await this.handleMongoDBListCollections();