Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

get_table_stats

Retrieve table statistics including row count and size from CockroachDB to analyze data volume and optimize database performance.

Instructions

Get statistics for a table.

Args:
    table: Table name (schema.table or just table).

Returns:
    Table statistics including row count and size.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the tool logic: parses table name, checks schema permissions, queries row count and table size using CockroachDB pg_total_relation_size.
    async def get_table_stats(table: str) -> dict[str, Any]:
        """Get statistics for a table.
    
        Args:
            table: Table name (schema.table or just table).
    
        Returns:
            Table statistics.
        """
        conn = await connection_manager.ensure_connected()
    
        # Parse schema and table name
        if "." in table:
            schema, table_name = table.rsplit(".", 1)
        else:
            schema = "public"
            table_name = table
    
        # Check if schema is allowed
        if not _is_allowed_schema(schema):
            return {"status": "error", "error": f"Schema '{schema}' is not allowed"}
    
        try:
            # Get table size and row count
            async with conn.cursor() as cur:
                # Row count
                await cur.execute(f"SELECT COUNT(*) as count FROM {schema}.{table_name}")
                count_row = await cur.fetchone()
                row_count = count_row["count"] if count_row else 0
    
                # Table size using CockroachDB specific query
                await cur.execute(
                    """
                    SELECT
                        pg_size_pretty(pg_total_relation_size(%s::regclass)) as total_size,
                        pg_total_relation_size(%s::regclass) as total_bytes
                """,
                    (f"{schema}.{table_name}", f"{schema}.{table_name}"),
                )
                size_row = await cur.fetchone()
    
            return {
                "schema": schema,
                "table": table_name,
                "full_name": f"{schema}.{table_name}",
                "row_count": row_count,
                "total_size": size_row.get("total_size") if size_row else None,
                "total_bytes": size_row.get("total_bytes") if size_row else None,
            }
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • MCP tool registration via @mcp.tool() decorator. Thin wrapper that delegates to the core implementation in tables.get_table_stats and handles exceptions.
    @mcp.tool()
    async def get_table_stats(table: str) -> dict[str, Any]:
        """Get statistics for a table.
    
        Args:
            table: Table name (schema.table or just table).
    
        Returns:
            Table statistics including row count and size.
        """
        try:
            return await tables.get_table_stats(table)
        except Exception as e:
            return {"status": "error", "error": str(e)}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves statistics (implying read-only) and mentions return values, but lacks details on permissions, rate limits, error conditions, or whether it's a lightweight operation. For a tool with zero annotation coverage, this is insufficient to guide safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and well-structured: a clear purpose statement followed by dedicated 'Args' and 'Returns' sections. Every sentence earns its place by providing essential information without redundancy, making it easy to parse and front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter) and the presence of an output schema (which handles return values), the description is reasonably complete. It covers purpose, parameter semantics, and return content. However, it lacks behavioral context like error handling or performance implications, which would be beneficial despite the output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context for the single parameter 'table', explaining it can be 'schema.table or just table', which clarifies naming conventions beyond the schema's basic string type. With 0% schema description coverage, this compensates well, though it doesn't detail format constraints (e.g., case sensitivity). Since there's only one parameter, the baseline is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get statistics') and resource ('for a table'), making it immediately understandable. It distinguishes itself from siblings like describe_table (metadata) or show_statements (query stats) by focusing on table-level statistics. However, it doesn't explicitly differentiate from all possible alternatives, keeping it at a 4 rather than a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a connection), exclusions (e.g., not for views), or compare it to siblings like describe_table (for schema) or show_statements (for query performance). Without such context, the agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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