Skip to main content
Glama
jonfreeland

MongoDB MCP Server

by jonfreeland

list_collections

Retrieve all collection names in a MongoDB database to identify available data structures before executing queries.

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

  • The handler function for the 'list_collections' tool. It extracts the optional database name from arguments, connects to the specified or default database, lists all collections using db.listCollections().toArray(), and returns the result as JSON-formatted text content.
    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), }, ], }; }
  • Input schema definition for the 'list_collections' tool, specifying an optional 'database' string parameter.
    inputSchema: { type: 'object', properties: { database: { type: 'string', description: 'Database name (optional if default database is configured)', }, }, },
  • src/index.ts:320-334 (registration)
    Registration of the 'list_collections' tool in the list of tools provided by the ListToolsRequestSchema handler, including name, description, and input schema.
    { 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)', }, }, }, },

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