Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

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
NameRequiredDescriptionDefault
databaseNoDatabase name (optional if default database is configured)

Implementation Reference

  • 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)', }, }, }, },
  • 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)', }, }, },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonfreeland/mongodb-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server