Skip to main content
Glama
manpreet2000

MCP Database Server

getCollections

Retrieve all collection names from a MongoDB database to understand available data structures and plan database operations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Inline handler function for the 'getCollections' tool. It ensures a connection to MongoDB, lists all collections in the database, and returns their names as a comma-separated string in the MCP response format. Handles connection errors gracefully.
    this.mcpServer.tool("getCollections", async () => { try { let db = mongodbConnection.getDb(); if (!db) { await mongodbConnection.connect(this.MONGODB_URI); db = mongodbConnection.getDb(); if (!db) throw new Error("Failed to connect to database"); } const collections = await db.listCollections().toArray(); return { content: [ { type: "text", text: collections.map((c) => c.name).join(", ") }, ], }; } catch (error) { console.error(error); return { content: [{ type: "text", text: "Error: " + error }], }; } });

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/manpreet2000/mcp-database-server'

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