Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

show_ranges

Display range distribution across a CockroachDB cluster to analyze data partitioning and storage layout, with optional table filtering for targeted insights.

Instructions

Show range distribution in the cluster.

Args:
    table: Optional table to filter ranges.
    limit: Maximum ranges to return.

Returns:
    Range distribution information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNo
limitNo

Implementation Reference

  • Core handler function that executes the show_ranges tool logic by querying CockroachDB's crdb_internal.ranges_no_leases table for range distribution information.
    async def show_ranges(table: str | None = None, limit: int = 50) -> dict[str, Any]:
        """Show range distribution in the cluster.
    
        Args:
            table: Optional table to filter ranges.
            limit: Maximum ranges to return.
    
        Returns:
            Range distribution information.
        """
        conn = await connection_manager.ensure_connected()
    
        try:
            if table:
                # Parse table name (schema ignored - CockroachDB ranges use just table_name)
                if "." in table:
                    _schema, table_name = table.rsplit(".", 1)
                else:
                    table_name = table
    
                query = f"""
                    SELECT
                        range_id,
                        start_pretty,
                        end_pretty,
                        lease_holder,
                        replicas,
                        range_size_mb
                    FROM crdb_internal.ranges_no_leases
                    WHERE table_name = '{table_name}'
                    LIMIT {limit}
                """
            else:
                query = f"""
                    SELECT
                        range_id,
                        database_name,
                        table_name,
                        start_pretty,
                        end_pretty,
                        lease_holder,
                        replicas,
                        range_size_mb
                    FROM crdb_internal.ranges_no_leases
                    LIMIT {limit}
                """
    
            async with conn.cursor() as cur:
                await cur.execute(query)
                rows = await cur.fetchall()
    
            ranges = []
            for row in rows:
                range_info: dict[str, Any] = {
                    "range_id": row.get("range_id"),
                    "start": row.get("start_pretty"),
                    "end": row.get("end_pretty"),
                    "lease_holder": row.get("lease_holder"),
                    "replicas": row.get("replicas"),
                    "size_mb": row.get("range_size_mb"),
                }
                if not table:
                    range_info["database"] = row.get("database_name")
                    range_info["table"] = row.get("table_name")
                ranges.append(range_info)
    
            return {"ranges": ranges, "count": len(ranges), "table_filter": table}
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Registration of the show_ranges tool via @mcp.tool() decorator. This thin wrapper delegates execution to the core handler in cluster.py.
    @mcp.tool()
    async def show_ranges(table: str | None = None, limit: int = 50) -> dict[str, Any]:
        """Show range distribution in the cluster.
    
        Args:
            table: Optional table to filter ranges.
            limit: Maximum ranges to return.
    
        Returns:
            Range distribution information.
        """
        try:
            return await cluster.show_ranges(table, limit)
        except Exception as e:
            return {"status": "error", "error": str(e)}

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