Skip to main content
Glama
StarRocks

StarRocks MCP Server

Official

table_overview

View table details, including columns, sample rows, and row count. Use the refresh option to bypass cache and get updated data from the StarRocks database.

Instructions

Get an overview of a specific table: columns, sample rows (up to 5), and total row count. Uses cache unless refresh=true

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
refreshNoSet to true to force refresh, ignoring cache. Defaults to false.
tableYesTable name, optionally prefixed with database name (e.g., 'db_name.table_name'). If database is omitted, uses the default database.

Implementation Reference

  • Handler function for the 'table_overview' tool. Includes registration via @mcp.tool decorator, input schema via Annotated Fields, caching logic, parsing of table parameter, error handling, and invocation of helper function to retrieve table details.
    @mcp.tool(description="Get an overview of a specific table: columns, sample rows (up to 5), and total row count. Uses cache unless refresh=true" + description_suffix)
    def table_overview(
            table: Annotated[str, Field(
                description="Table name, optionally prefixed with database name (e.g., 'db_name.table_name'). If database is omitted, uses the default database.")],
            refresh: Annotated[
                bool, Field(description="Set to true to force refresh, ignoring cache. Defaults to false.")] = False
    ) -> str:
        try:
            logger.info(f"Getting table overview for: {table}, refresh={refresh}")
            if not table:
                logger.error("Table overview called without table name")
                return "Error: Missing 'table' argument."
    
            # Parse table argument: [db.]<table>
            parts = table.split('.', 1)
            db_name = None
            table_name = None
            if len(parts) == 2:
                db_name, table_name = parts[0], parts[1]
            elif len(parts) == 1:
                table_name = parts[0]
                db_name = db_client.default_database  # Use default if only table name is given
    
            if not table_name:  # Should not happen if table_arg exists, but check
                logger.error(f"Invalid table name format: {table}")
                return f"Error: Invalid table name format '{table}'."
            if not db_name:
                logger.error(f"No database specified for table {table_name}")
                return f"Error: Database name not specified for table '{table_name}' and no default database is set."
    
            cache_key = (db_name, table_name)
    
            # Check cache
            if not refresh and cache_key in global_table_overview_cache:
                logger.debug(f"Using cached overview for {db_name}.{table_name}")
                return global_table_overview_cache[cache_key]
    
            logger.debug(f"Fetching fresh overview for {db_name}.{table_name}")
            # Fetch details (will also update cache)
            overview_text = _get_table_details(db_name, table_name, limit=overview_length_limit)
            return overview_text
        except Exception as e:
            # Reset connections on unexpected errors
            logger.exception(f"Unexpected error in table_overview for {table}")
            reset_db_connections()
            stack_trace = traceback.format_exc()
            return f"Unexpected Error executing tool 'table_overview': {type(e).__name__}: {e}\nStack Trace:\n{stack_trace}"
  • Pydantic input schema for 'table_overview' tool parameters: 'table' (string, table name possibly with db prefix) and 'refresh' (boolean, optional, default False).
    def table_overview(
            table: Annotated[str, Field(
                description="Table name, optionally prefixed with database name (e.g., 'db_name.table_name'). If database is omitted, uses the default database.")],
            refresh: Annotated[
                bool, Field(description="Set to true to force refresh, ignoring cache. Defaults to false.")] = False
    ) -> str:
  • Supporting helper function _get_table_details(db_name, table_name, limit) that performs the core queries (COUNT(*), DESCRIBE, SELECT LIMIT 3), formats the overview string, and updates the global cache.
    def _get_table_details(db_name, table_name, limit=None):
        """
        Helper function to get description, sample rows, and count for a table.
        Returns a formatted string. Handles DB errors internally and returns error messages.
        """
        global global_table_overview_cache
        logger.debug(f"Fetching table details for {db_name}.{table_name}")
        output_lines = []
    
        full_table_name = f"`{table_name}`"
        if db_name:
            full_table_name = f"`{db_name}`.`{table_name}`"
        else:
            output_lines.append(
                f"Warning: Database name missing for table '{table_name}'. Using potentially incorrect context.")
            logger.warning(f"Database name missing for table '{table_name}'")
    
        count = 0
        output_lines.append(f"--- Overview for {full_table_name} ---")
    
        # 1. Get Row Count
        query = f"SELECT COUNT(*) FROM {full_table_name}"
        count_result = db_client.execute(query, db=db_name)
        if count_result.success and count_result.rows:
            count = count_result.rows[0][0]
            output_lines.append(f"\nTotal rows: {count}")
            logger.debug(f"Table {full_table_name} has {count} rows")
        else:
            output_lines.append(f"\nCould not determine total row count.")
            if not count_result.success:
                output_lines.append(f"Error: {count_result.error_message}")
                logger.error(f"Failed to get row count for {full_table_name}: {count_result.error_message}")
    
        # 2. Get Columns (DESCRIBE)
        if count > 0:
            query = f"DESCRIBE {full_table_name}"
            desc_result = db_client.execute(query, db=db_name)
            if desc_result.success and desc_result.column_names and desc_result.rows:
                output_lines.append(f"\nColumns:")
                output_lines.append(desc_result.to_string(limit=limit))
            else:
                output_lines.append("(Could not retrieve column information or table has no columns).")
                if not desc_result.success:
                    output_lines.append(f"Error getting columns for {full_table_name}: {desc_result.error_message}")
                    return "\n".join(output_lines)
    
            # 3. Get Sample Rows (LIMIT 3)
            query = f"SELECT * FROM {full_table_name} LIMIT 3"
            sample_result = db_client.execute(query, db=db_name)
            if sample_result.success and sample_result.column_names and sample_result.rows:
                output_lines.append(f"\nSample rows (limit 3):")
                output_lines.append(sample_result.to_string(limit=limit))
            else:
                output_lines.append(f"(No rows found in {full_table_name}).")
                if not sample_result.success:
                    output_lines.append(f"Error getting sample rows for {full_table_name}: {sample_result.error_message}")
    
        overview_string = "\n".join(output_lines)
        # Update cache even if there were partial errors, so we cache the error message too
        cache_key = (db_name, table_name)
        global_table_overview_cache[cache_key] = overview_string
        return overview_string
  • Registration of the 'table_overview' tool via FastMCP @mcp.tool decorator with description.
    @mcp.tool(description="Get an overview of a specific table: columns, sample rows (up to 5), and total row count. Uses cache unless refresh=true" + description_suffix)
  • Global cache dictionary for storing table overview strings, keyed by (db_name, table_name). Used by table_overview and db_overview tools.
    global_table_overview_cache = {}
Behavior4/5

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

With no annotations provided, the description carries full burden and discloses key behavioral traits: it uses caching by default and explains how to bypass it with 'refresh=true'. However, it lacks details on permissions, rate limits, or error handling, which would be valuable for a tool accessing data.

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 front-loaded with the core purpose in the first sentence, followed by a concise behavioral note. Every sentence earns its place by adding essential information without redundancy, making it efficient and well-structured.

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 moderate complexity (2 parameters, no output schema), the description is mostly complete: it covers purpose, usage context, and caching behavior. However, without annotations or output schema, it could benefit from more details on return format or error cases to be fully comprehensive.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds minimal value by mentioning the cache behavior tied to 'refresh', but does not provide additional syntax or format details beyond what the schema specifies.

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

Purpose5/5

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

The description clearly states the specific action ('Get an overview') and resource ('a specific table'), listing the exact components returned (columns, sample rows up to 5, total row count). It distinguishes from siblings like 'db_overview' (database-level) and 'analyze_query' (query-focused) by specifying table-level metadata retrieval.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool—to obtain table metadata including structure and sample data. It implicitly suggests alternatives like 'db_overview' for database-level info or 'read_query' for full data retrieval, but does not explicitly name them or state when not to use this tool.

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

Related 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/StarRocks/mcp-server-starrocks'

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