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)}"

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