Skip to main content
Glama
aliyun

Hologres MCP Server

Official
by aliyun

execute_hg_select_sql

Query data from Hologres databases using SELECT SQL statements to retrieve specific information for analysis and decision-making.

Instructions

Execute SELECT SQL to query data from Hologres database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe (SELECT) SQL query to execute in Hologres database.

Implementation Reference

  • Core handler function that executes the SQL query for the execute_hg_select_sql tool (and others). Connects to Hologres database, executes the query, formats SELECT results as CSV-like text with columns and rows.
    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)}"
  • Registration of the execute_hg_select_sql tool in the MCP server's list_tools() function, including name, description, and input schema.
    Tool(
        name="execute_hg_select_sql",
        description="Execute SELECT SQL to query data from Hologres database.",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The (SELECT) SQL query to execute in Hologres database."
                }
            },
            "required": ["query"]
        }
    ),
  • Specific dispatching and input validation logic for the execute_hg_select_sql tool within the call_tool handler, ensuring it's a SELECT query before passing to execution utility.
    if name == "execute_hg_select_sql":
        query = arguments.get("query")
        if not query:
            raise ValueError("Query is required")
        if not re.match(r"^\s*WITH\s+.*?SELECT\b", query, re.IGNORECASE) and not re.match(r"^\s*SELECT\b", query, re.IGNORECASE):
            raise ValueError("Query must be a SELECT statement or start with WITH followed by a SELECT statement")
  • Helper function used by the handler to establish a reliable database connection to Hologres with retries.
    def connect_with_retry(retries=3):
        attempt = 0
        err_msg = ""
        while attempt <= retries:
            try:
                config = get_db_config()
                conn = psycopg.connect(**config)
                conn.autocommit = True
                with conn.cursor() as cursor:
                    cursor.execute("SELECT 1;")
                    cursor.fetchone()
                return conn
            except psycopg.Error as e:
                err_msg = f"Connection failed: {e}"
                attempt += 1
                if attempt <= retries:
                    print(f"Retrying connection (attempt {attempt + 1} of {retries + 1})...")
                    time.sleep(5)  # 等待 2 秒后再次尝试连接
        raise psycopg.Error(f"Failed to connect to Hologres database after retrying: {err_msg}")
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 executes SELECT SQL queries, implying read-only operations, but does not cover critical aspects such as authentication requirements, rate limits, error handling, or output format. For a database query tool with zero annotation coverage, this is a significant gap in transparency.

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: 'Execute SELECT SQL to query data from Hologres database.' It is front-loaded with the core purpose, has no redundant information, and every word contributes to understanding the tool's function. This makes it highly concise and well-structured for quick comprehension.

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

Completeness2/5

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

Given the complexity of database querying, lack of annotations, and no output schema, the description is incomplete. It does not explain what the tool returns (e.g., result sets, error messages), performance implications, or security considerations. For a tool that interacts with a database, more context is needed to ensure safe and effective use by an AI agent.

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?

The input schema has 100% description coverage, with the 'query' parameter documented as 'The (SELECT) SQL query to execute in Hologres database.' The description adds no additional parameter semantics beyond this, such as query syntax examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the schema adequately handles parameter documentation.

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: 'Execute SELECT SQL to query data from Hologres database.' It specifies the verb ('Execute SELECT SQL'), resource ('Hologres database'), and action ('query data'), which is precise. However, it does not explicitly distinguish this tool from its sibling 'execute_hg_select_sql_with_serverless', which likely serves a similar purpose but with different execution context, so it misses full sibling differentiation.

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 does not mention any prerequisites, constraints, or comparisons to sibling tools like 'execute_hg_select_sql_with_serverless' or 'execute_hg_dml_sql', leaving the agent without context for selection. This lack of usage instructions reduces its effectiveness in guiding tool invocation.

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