Skip to main content
Glama
aliyun

Hologres MCP Server

Official
by aliyun

execute_hg_ddl_sql

Run SQL commands to create, modify, or delete tables, views, procedures, and configurations in Hologres databases via the Hologres MCP Server.

Instructions

Execute (CREATE, ALTER, DROP) SQL statements to CREATE, ALTER, or DROP tables, views, procedures, GUCs etc. in Hologres databse.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe DDL SQL query to execute in Hologres database

Implementation Reference

  • Specific handler logic for execute_hg_ddl_sql tool: validates that the query is a DDL statement (CREATE, ALTER, DROP, COMMENT ON) and extracts the SQL query.
    elif name == "execute_hg_ddl_sql": query = arguments.get("query") if not query: raise ValueError("Query is required") if not any(query.strip().upper().startswith(keyword) for keyword in ["CREATE", "ALTER", "DROP", "COMMENT ON"]): raise ValueError("Query must be a DDL statement (CREATE, ALTER, DROP, COMMENT ON)") elif name == "gather_hg_table_statistics":
  • Core execution helper function that runs the SQL query via psycopg connection. For non-SELECT queries like DDL, returns 'Query executed successfully'.
    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)}"
  • Input schema definition for the execute_hg_ddl_sql tool, specifying the required 'query' parameter.
    Tool( name="execute_hg_ddl_sql", description="Execute (CREATE, ALTER, DROP) SQL statements to CREATE, ALTER, or DROP tables, views, procedures, GUCs etc. in Hologres databse.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The DDL SQL query to execute in Hologres database" } }, "required": ["query"] } ),
  • Registers the execute_hg_ddl_sql tool by including it in the list returned by the MCP server's list_tools method.
    @app.list_tools() async def list_tools() -> list[Tool]: """List available Hologres tools.""" # logger.info("Listing tools...") return [ 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"] } ), # 新增 execute_hg_select_sql_with_serverless 工具 Tool( name="execute_hg_select_sql_with_serverless", description="Use Serverless Computing resources to execute SELECT SQL to query data in Hologres database. When the error like \"Total memory used by all existing queries exceeded memory limitation\" occurs during execute_hg_select_sql execution, you can re-execute the SQL with the tool execute_hg_select_sql_with_serverless.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The (SELECT) SQL query to execute with serverless computing in Hologres database" } }, "required": ["query"] } ), Tool( name="execute_hg_dml_sql", description="Execute (INSERT, UPDATE, DELETE) SQL to insert, update, and delete data in Hologres databse.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The DML SQL query to execute in Hologres database" } }, "required": ["query"] } ), Tool( name="execute_hg_ddl_sql", description="Execute (CREATE, ALTER, DROP) SQL statements to CREATE, ALTER, or DROP tables, views, procedures, GUCs etc. in Hologres databse.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The DDL SQL query to execute in Hologres database" } }, "required": ["query"] } ), Tool( name="gather_hg_table_statistics", description="Execute the ANALYZE TABLE command to have Hologres collect table statistics, enabling QO to generate better query plans", inputSchema={ "type": "object", "properties": { "schema": { "type": "string", "description": "Schema name in Hologres database" }, "table": { "type": "string", "description": "Table name in Hologres database" } }, "required": ["schema", "table"] } ), Tool( name="get_hg_query_plan", description="Get query plan for a SQL query in Hologres database", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The SQL query to analyze in Hologres database" } }, "required": ["query"] } ), Tool( name="get_hg_execution_plan", description="Get actual execution plan with runtime statistics for a SQL query in Hologres database", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The SQL query to analyze in Hologres database" } }, "required": ["query"] } ), Tool( name="call_hg_procedure", description="Call a stored procedure in Hologres database.", inputSchema={ "type": "object", "properties": { "procedure_name": { "type": "string", "description": "The name of the stored procedure to call in Hologres database" }, "arguments": { "type": "array", "items": { "type": "string" }, "description": "The arguments to pass to the stored procedure in Hologres database" } }, "required": ["procedure_name"] } ), 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"] } ), # 新增 list_hg_schemas 工具 Tool( name="list_hg_schemas", description="List all schemas in the current Hologres database, excluding system schemas.", inputSchema={ "type": "object", "properties": {}, "required": [] } ), # 新增 list_hg_tables_in_a_schema 工具 Tool( 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"] } ), # 新增 show_hg_table_ddl 工具 Tool( name="show_hg_table_ddl", description="Show DDL script for a table, view, or foreign table in Hologres database.", inputSchema={ "type": "object", "properties": { "schema": { "type": "string", "description": "Schema name in Hologres database" }, "table": { "type": "string", "description": "Table name in Hologres database" } }, "required": ["schema", "table"] } ) ]

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

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