Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

list-collections

List all collections within a specified MongoDB database using the MongoDB MCP Server. Ideal for managing and organizing database resources efficiently.

Instructions

List all collections for a given database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name

Implementation Reference

  • Implements the core logic of the 'list-collections' tool: connects to MongoDB, lists collections for the given database, and formats the response as text content.
    protected async execute({ database }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const provider = await this.ensureConnected(); const collections = await provider.listCollections(database); if (collections.length === 0) { return { content: [ { type: "text", text: `Found 0 collections for database "${database}". To create a collection, use the "create-collection" tool.`, }, ], }; } return { content: formatUntrustedData( `Found ${collections.length} collections for database "${database}".`, collections.map((collection) => `"${collection.name}"`).join("\n") ), }; }
  • Defines the input schema for the tool, requiring a 'database' parameter.
    protected argsShape = { database: DbOperationArgs.database, };
  • The ListCollectionsTool class definition, including the tool name 'list-collections', description, args shape, and operation type, serving as the registration point for the tool.
    export class ListCollectionsTool extends MongoDBToolBase { public name = "list-collections"; protected description = "List all collections for a given database"; protected argsShape = { database: DbOperationArgs.database, }; static operationType: OperationType = "metadata";

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/mongodb-js/mongodb-mcp-server'

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