Skip to main content
Glama

MongoDB MCP Server for LLMs

import { MongoClient, Db } from "mongodb"; export let client: MongoClient; export let db: Db; export async function connectToMongoDB(databaseUrl: string) { try { console.error("Attempting to connect to MongoDB at:", databaseUrl); client = new MongoClient(databaseUrl); await client.connect(); const resourceBaseUrl = new URL(databaseUrl); const dbName = resourceBaseUrl.pathname.split("/")[1] || "test"; console.error(`Connected successfully to MongoDB. Using database: ${dbName}`); db = client.db(dbName); // Test the connection const collections = await db.listCollections().toArray(); console.error("Available collections:", collections.map(c => c.name)); } catch (error) { console.error("MongoDB connection error:", error); throw error; } } export async function closeMongoDB() { await client?.close(); }

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/nickiiitu/MongoDB-Model-Context-Protocol-MCP-'

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