Skip to main content
Glama
aliyun

Hologres MCP Server

Official
by aliyun

create_hg_maxcompute_foreign_table

Create foreign tables in Hologres to query MaxCompute data directly, enabling faster analytics without data movement.

Instructions

Create a MaxCompute foreign table in Hologres database to accelerate queries on MaxCompute data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxcompute_projectYesThe MaxCompute project name (required)
maxcompute_schemaNoThe MaxCompute schema name (optional, default: 'default')default
maxcompute_tablesYesThe MaxCompute table names (required)
local_schemaNoThe local schema name in Hologres (optional, default: 'public')public

Implementation Reference

  • Handler for create_hg_maxcompute_foreign_table: extracts parameters from arguments, validates required fields, constructs the IMPORT FOREIGN SCHEMA SQL statement, and sets it for execution by handle_call_tool.
    elif name == "create_hg_maxcompute_foreign_table":
        maxcompute_project = arguments.get("maxcompute_project")
        maxcompute_schema = arguments.get("maxcompute_schema", "default")
        maxcompute_tables = arguments.get("maxcompute_tables")
        local_schema = arguments.get("local_schema", "public")
        if not all([maxcompute_project, maxcompute_tables]):
            raise ValueError("maxcompute_project and maxcompute_tables are required")
        maxcompute_table_list = ", ".join(maxcompute_tables)
        # 修复 SQL 语句,确保正确拼接项目名称和 schema
        query = f"""
            IMPORT FOREIGN SCHEMA "{maxcompute_project}#{maxcompute_schema}"
            LIMIT TO ({maxcompute_table_list})
            FROM SERVER odps_server
            INTO {local_schema};
        """
  • Input schema defining the parameters for the create_hg_maxcompute_foreign_table tool, including required MaxCompute project and tables, optional schema and local schema.
    inputSchema={
        "type": "object",
        "properties": {
            "maxcompute_project": {
                "type": "string",
                "description": "The MaxCompute project name (required)"
            },
            "maxcompute_schema": {
                "type": "string",
                "default": "default",
                "description": "The MaxCompute schema name (optional, default: 'default')"
            },
            "maxcompute_tables": {
                "type": "array",
                "items": {
                    "type": "string"
                },
                "description": "The MaxCompute table names (required)"
            },
            "local_schema": {
                "type": "string",
                "default": "public",
                "description": "The local schema name in Hologres (optional, default: 'public')"
            }
        },
        "required": ["maxcompute_project", "maxcompute_tables"]
    }
  • Registration of the create_hg_maxcompute_foreign_table tool in the MCP server's list_tools() function.
    Tool(
        name="create_hg_maxcompute_foreign_table",
        description="Create a MaxCompute foreign table in Hologres database to accelerate queries on MaxCompute data.",
        inputSchema={
            "type": "object",
            "properties": {
                "maxcompute_project": {
                    "type": "string",
                    "description": "The MaxCompute project name (required)"
                },
                "maxcompute_schema": {
                    "type": "string",
                    "default": "default",
                    "description": "The MaxCompute schema name (optional, default: 'default')"
                },
                "maxcompute_tables": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    },
                    "description": "The MaxCompute table names (required)"
                },
                "local_schema": {
                    "type": "string",
                    "default": "public",
                    "description": "The local schema name in Hologres (optional, default: 'public')"
                }
            },
            "required": ["maxcompute_project", "maxcompute_tables"]
        }
    ),
  • Generic helper function used by all tools to execute the SQL query on the Hologres database connection, handling SELECT results and DDL/DML success 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?

With no annotations provided, the description carries full burden but offers minimal behavioral disclosure. It mentions the outcome ('accelerate queries') but doesn't cover critical aspects like required permissions, whether this creates a persistent or temporary resource, error conditions, or performance characteristics. For a creation tool with zero annotation coverage, this leaves significant gaps.

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 immediately conveys the core purpose without unnecessary words. It's front-loaded with the main action and benefit, making it easy for an agent to parse quickly.

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?

For a tool with 4 parameters, 100% schema coverage, but no annotations or output schema, the description provides basic purpose but lacks completeness. It doesn't address mutation implications, return values, or error handling. The agent understands what the tool does but not how it behaves or what to expect from its execution.

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%, providing complete parameter documentation. The description adds no additional parameter semantics beyond what's in the schema. It doesn't explain relationships between parameters or provide examples. The baseline score of 3 reflects adequate but not enhanced parameter understanding.

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 ('Create a MaxCompute foreign table'), the resource ('in Hologres database'), and the purpose ('to accelerate queries on MaxCompute data'). It distinguishes itself from sibling tools like 'execute_hg_ddl_sql' by focusing on a specialized operation rather than general SQL execution.

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, performance implications, or compare it to similar tools like 'execute_hg_ddl_sql' which might also create tables. The agent must infer usage from the purpose 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/aliyun/alibabacloud-hologres-mcp-server'

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