Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
listDatabases.ts983 B
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; import { MongoDBToolBase } from "../mongodbTool.js"; import type * as bson from "bson"; import type { OperationType } from "../../tool.js"; import { formatUntrustedData } from "../../tool.js"; export class ListDatabasesTool extends MongoDBToolBase { public name = "list-databases"; protected description = "List all databases for a MongoDB connection"; protected argsShape = {}; public operationType: OperationType = "metadata"; 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`) ), }; } }

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