execute_hg_dml_sql
Execute INSERT, UPDATE, and DELETE SQL queries to manage data within a Hologres database, enabling efficient data manipulation and modification.
Instructions
Execute (INSERT, UPDATE, DELETE) SQL to insert, update, and delete data in Hologres databse.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The DML SQL query to execute in Hologres database |
Implementation Reference
- Specific dispatch and validation handler for the 'execute_hg_dml_sql' tool within the @app.call_tool() function. Extracts the SQL query and ensures it is a valid DML statement (INSERT, UPDATE, or DELETE). Then passes to handle_call_tool for execution.elif name == "execute_hg_dml_sql": query = arguments.get("query") if not query: raise ValueError("Query is required") if not any(query.strip().upper().startswith(keyword) for keyword in ["INSERT", "UPDATE", "DELETE"]): raise ValueError("Query must be a DML statement (INSERT, UPDATE, DELETE)") elif name == "execute_hg_ddl_sql":
- Core execution helper function called by the tool handler. Establishes database connection, optionally sets serverless mode, executes the SQL query, and formats results or reports success/rowcount/error.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)}"
- src/hologres_mcp_server/server.py:376-389 (registration)Registration of the 'execute_hg_dml_sql' tool in the list_tools() function, including name, description, and input schema definition.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"] } ),
- Input schema definition for the 'execute_hg_dml_sql' tool, specifying a required 'query' string parameter.inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The DML SQL query to execute in Hologres database" } }, "required": ["query"] }