Skip to main content
Glama
mongodb-js

MongoDB MCP Server

Official
by mongodb-js

list-databases

Retrieve a list of all available databases for a MongoDB connection using this tool, enabling efficient management and access to database resources.

Instructions

List all databases for a MongoDB connection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool class definition including the unique name 'list-databases', description, input schema (empty), and operation type.
    export class ListDatabasesTool extends MongoDBToolBase { public name = "list-databases"; protected description = "List all databases for a MongoDB connection"; protected argsShape = {}; static operationType: OperationType = "metadata";
  • The handler function that executes the tool: connects to MongoDB, fetches the list of databases, and returns formatted content with database names and sizes.
    protected async execute(): Promise<CallToolResult> { const provider = await this.ensureConnected(); const dbs = (await provider.listDatabases("")).databases as { name: string; sizeOnDisk: bson.Long }[]; return { content: formatUntrustedData( `Found ${dbs.length} databases`, ...dbs.map((db) => `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`) ), }; }
  • Re-exports ListDatabasesTool as part of the MongoDB tools module, enabling its inclusion in the overall tools registry via src/tools/index.ts.
    export { ListDatabasesTool } from "./metadata/listDatabases.js";
  • src/tools/index.ts:7-8 (registration)
    Registers all MongoDB tools, including ListDatabasesTool (via MongoDbTools), into the central AllTools array used for tool registration in the MCP server.
    export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools,

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