list_collections
Retrieve all collections in a MongoDB database to identify available data sets before querying. Ideal for quickly assessing database structure and content.
Instructions
List all collections in a database.
Start here to understand what collections are available before querying.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional if default database is configured) |
Implementation Reference
- src/index.ts:1024-1043 (handler)Handler for the 'list_collections' tool that connects to the specified database and returns a list of all collections using MongoDB's listCollections() method.case 'list_collections': { const { database } = request.params.arguments as { database?: string }; const dbName = database || this.defaultDatabase; if (!dbName) { throw new McpError( ErrorCode.InvalidRequest, 'Database name is required when no default database is configured' ); } const db = client.db(dbName); const collections = await db.listCollections().toArray(); return { content: [ { type: 'text', text: JSON.stringify(collections, null, 2), }, ], }; }
- src/index.ts:321-334 (registration)Registration of the 'list_collections' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.name: 'list_collections', description: `List all collections in a database. Start here to understand what collections are available before querying.`, inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, }, }, },
- src/index.ts:325-333 (schema)Input schema definition for the 'list_collections' tool, specifying an optional 'database' parameter.inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, }, },