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
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "mongodb_list_collections"
}
}Input 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: [], }, },