Skip to main content
Glama

mongodb_list_databases

Retrieve a list of all databases in MongoDB to manage data storage and organization within the MCP Mac Apps Server environment.

Instructions

Получает список всех баз данных в MongoDB

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function that connects to MongoDB, lists all databases via admin().listDatabases(), filters out system databases (admin, config, local), and returns a formatted text response.
    private async mongodbListDatabases() { const client = await this.getMongoClient(); try { const adminDb = client.db().admin(); const { databases } = await adminDb.listDatabases(); const dbNames = databases .map((db) => db.name) .filter((name) => !["admin", "config", "local"].includes(name)); return { content: [ { type: "text", text: `Базы данных:\n${dbNames.length > 0 ? dbNames.join("\n") : "Базы данных не найдены"}`, }, ], }; } catch (error) { throw new Error( `Ошибка получения списка баз данных: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); } }
  • Tool schema definition in the ListTools response, specifying name, description, and empty input schema (no parameters required).
    name: "mongodb_list_databases", description: "Получает список всех баз данных в MongoDB", inputSchema: { type: "object", properties: {}, }, },
  • src/index.ts:341-342 (registration)
    Dispatch/registration in the CallToolRequestHandler switch statement that routes the tool call to the mongodbListDatabases method.
    case "mongodb_list_databases": return await this.mongodbListDatabases();
  • Python implementation of the handler function using pymongo to list databases, filtering system ones, returning formatted text. Note: dispatch case is commented out.
    def mongodb_list_databases() -> str: """Gets list of databases""" client = MongoClient(MONGODB_URI) try: admin_db = client.admin databases = admin_db.command("listDatabases") db_names = [ db["name"] for db in databases["databases"] if db["name"] not in ["admin", "config", "local"] ] result = "Databases:\n" + ( "\n".join(db_names) if db_names else "No databases found" ) return result except Exception as e: raise Exception(f"Error getting list of databases: {str(e)}") finally: client.close()
  • Helper method to create and connect a MongoClient instance, reused by all MongoDB tools.
    private async getMongoClient(): Promise<MongoClient> { const client = new MongoClient(MONGODB_URI); await client.connect(); return client; }

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/TrueOleg/MCP-expirements'

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