Skip to main content
Glama

MongoDB MCP Server

mongoCollectionOps.tsβ€’1.56 kB
/** * Provides collection management operations for MongoDB. */ import { MongoConnection } from "./mongoClient.js"; export class MongoCollectionOps { /** * Constructs a new MongoCollectionOps instance. * @param connection - The MongoDB connection instance */ constructor(private connection: MongoConnection) {} /** * Lists all collections in the specified database. * @param dbName - The database name * @returns An array of collection info objects */ async listCollections(dbName: string) { const client = this.connection.getClient(); const db = client.db(dbName); return await db.listCollections().toArray(); } /** * Creates a new collection in the specified database. * @param dbName - The database name * @param collectionName - The collection name * @returns A message indicating success */ async createCollection(dbName: string, collectionName: string) { const client = this.connection.getClient(); const db = client.db(dbName); await db.createCollection(collectionName); return { message: `Collection '${collectionName}' created in database '${dbName}'.` }; } /** * Drops a collection from the specified database. * @param dbName - The database name * @param collectionName - The collection name * @returns The result of the drop operation */ async dropCollection(dbName: string, collectionName: string) { const client = this.connection.getClient(); const db = client.db(dbName); return await db.collection(collectionName).drop(); } }

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/franciscorojas27/McpServerMongodb'

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