Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

list_databases

Retrieve all databases in a CockroachDB cluster, with options to include or exclude system databases for comprehensive schema discovery.

Instructions

List all databases in the cluster.

Args:
    include_system: Include system databases (postgres, defaultdb, etc.).

Returns:
    List of databases.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_systemNo

Implementation Reference

  • Core handler function that executes the 'SHOW DATABASES' query, filters out blocked and system databases (unless specified), and returns a structured list of databases.
    async def list_databases(include_system: bool = False) -> dict[str, Any]:
        """List all databases in the cluster.
    
        Args:
            include_system: Include system databases.
    
        Returns:
            List of databases.
        """
        conn = await connection_manager.ensure_connected()
    
        try:
            async with conn.cursor() as cur:
                await cur.execute("SHOW DATABASES")
                rows = await cur.fetchall()
    
            databases = []
            system_dbs = {"system", "postgres", "defaultdb", "crdb_internal"}
    
            for row in rows:
                db_name = row.get("database_name", "")
    
                # Skip blocked databases
                if _is_blocked_database(db_name):
                    continue
    
                # Skip system databases unless requested
                is_system = db_name in system_dbs
                if is_system and not include_system:
                    continue
    
                databases.append(
                    {
                        "name": db_name,
                        "is_system": is_system,
                    }
                )
    
            return {
                "databases": databases,
                "count": len(databases),
                "current_database": connection_manager.current_database,
            }
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • MCP tool registration using @mcp.tool() decorator. This wrapper function handles the tool invocation, delegates to the core implementation in tables.py, and provides error handling.
    @mcp.tool()
    async def list_databases(include_system: bool = False) -> dict[str, Any]:
        """List all databases in the cluster.
    
        Args:
            include_system: Include system databases (postgres, defaultdb, etc.).
    
        Returns:
            List of databases.
        """
        try:
            return await tables.list_databases(include_system)
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Helper function used by list_databases to filter out blocked databases based on configuration.
    def _is_blocked_database(db_name: str) -> bool:
        """Check if a database is blocked."""
        return db_name in settings.blocked_databases_list

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/bpamiri/cockroachdb-mcp'

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