Skip to main content
Glama
aliyun

Hologres MCP Server

Official
by aliyun

list_hg_tables_in_a_schema

Retrieve all tables, views, and foreign tables from a specified Hologres database schema to analyze database structure and metadata.

Instructions

List all tables in a specific schema in the current Hologres database, including their types (table, view, foreign table, partitioned table).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYesSchema name to list tables from in Hologres database

Implementation Reference

  • Handler logic for the 'list_hg_tables_in_a_schema' tool: extracts schema from arguments, validates it, and constructs a complex SQL query to list tables in the schema, annotating types (view, foreign table, partitioned table) while excluding system schemas and non-top-level partitioned tables.
    elif name == "list_hg_tables_in_a_schema":
        schema = arguments.get("schema")
        if not schema:
            raise ValueError("Schema name is required")
        query = f"""
            SELECT
                tab.table_name,
                CASE WHEN tab.table_type = 'VIEW' THEN ' (view)'
                    WHEN tab.table_type = 'FOREIGN' THEN ' (foreign table)'
                    WHEN p.partrelid IS NOT NULL THEN ' (partitioned table)'
                    ELSE ''
                END AS table_type_info
            FROM
                information_schema.tables AS tab
            LEFT JOIN pg_class AS cls ON tab.table_name = cls.relname
            LEFT JOIN pg_namespace AS ns ON tab.table_schema = ns.nspname
            LEFT JOIN pg_inherits AS inh ON cls.oid = inh.inhrelid
            LEFT JOIN pg_partitioned_table AS p ON cls.oid = p.partrelid
            WHERE
                tab.table_schema NOT IN ('pg_catalog', 'information_schema', 'hologres', 'hologres_statistic', 'hologres_streaming_mv')
                AND tab.table_schema = '{schema}'
                AND (inh.inhrelid IS NULL OR NOT EXISTS (
                    SELECT 1
                    FROM pg_inherits
                    WHERE inh.inhrelid = pg_inherits.inhrelid
                ))
            ORDER BY
                tab.table_name;
        """
  • Registers the tool in the list_tools() decorator response with name, description, and input schema.
        name="list_hg_tables_in_a_schema",
        description="List all tables in a specific schema in the current Hologres database, including their types (table, view, foreign table, partitioned table).",
        inputSchema={
            "type": "object",
            "properties": {
                "schema": {
                    "type": "string",
                    "description": "Schema name to list tables from in Hologres database"
                }
            },
            "required": ["schema"]
        }
    ),
  • Pydantic-like input schema definition for the tool, requiring a single 'schema' string parameter.
        "type": "object",
        "properties": {
            "schema": {
                "type": "string",
                "description": "Schema name to list tables from in Hologres database"
            }
        },
        "required": ["schema"]
    }
  • Generic helper function that executes the SQL query prepared by tool handlers, handles connection retries, sets serverless mode if needed, formats SELECT results as CSV, and returns success/error messages.
    def handle_call_tool(tool_name, query, serverless = False):
        """Handle callTool method."""
        config = get_db_config()
        try:
            with connect_with_retry() as conn:
                with conn.cursor() as cursor:
    
                    # 特殊处理 serverless computing 查询
                    if serverless:
                        cursor.execute("set hg_computing_resource='serverless'")
                    
                    # Execute the query
                    cursor.execute(query)
                    
                    # 特殊处理 ANALYZE 命令
                    if tool_name == "gather_hg_table_statistics":
                        return f"Successfully {query}"
                    
                    # 处理其他有返回结果的查询
                    if cursor.description:  # SELECT query
                        columns = [desc[0] for desc in cursor.description]
                        rows = cursor.fetchall()
                        result = [",".join(map(str, row)) for row in rows]
                        return "\n".join([",".join(columns)] + result)
                    elif tool_name == "execute_dml_sql":  # Non-SELECT query
                        row_count = cursor.rowcount
                        return f"Query executed successfully. {row_count} rows affected."
                    else:
                        return "Query executed successfully"
        except Exception as e:
            return f"Error executing query: {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 full burden. It describes the action and output format (table types), but does not disclose behavioral traits such as permissions required, rate limits, pagination, error handling, or whether it's read-only. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 a single, efficient sentence that front-loads the core purpose ('List all tables in a specific schema') and adds necessary detail ('including their types'). There is no wasted verbiage, and it directly communicates the tool's function.

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

Completeness3/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 (1 parameter, no output schema, no annotations), the description is adequate but incomplete. It covers the purpose and output format, but lacks details on behavioral aspects like permissions or error handling. Without annotations or output schema, more context on what the tool returns would be helpful for completeness.

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%, with the single parameter 'schema' well-described in the schema. The description adds no additional parameter semantics beyond implying the schema is for listing tables, which aligns with the schema's description. Baseline 3 is appropriate as the schema handles the parameter documentation.

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 verb ('List all tables') and resource ('in a specific schema in the current Hologres database'), specifying the scope and what information is included ('including their types'). It distinguishes from siblings like 'list_hg_schemas' (which lists schemas, not tables) and 'show_hg_table_ddl' (which shows DDL for a specific table).

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

Usage Guidelines3/5

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

The description implies usage by specifying 'in a specific schema' and 'current Hologres database', but does not explicitly state when to use this tool versus alternatives like executing SQL queries directly. It lacks explicit exclusions or named alternatives, though the context suggests it's for listing tables rather than other operations.

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/aliyun/alibabacloud-hologres-mcp-server'

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