databricks_query
Execute read-only SQL queries on Databricks to retrieve data, browse metadata, and monitor Delta Lake tables without performing destructive operations.
Instructions
Execute Databricks SQL query (supports SELECT, SHOW, DESCRIBE, CREATE, ALTER). INSERT, UPDATE, DELETE, DROP and other destructive operations are blocked.
Args: sql_query: SQL query statement (preferred parameter) sql: SQL query statement (fallback for backward compatibility)
Returns: Query results as list of dicts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql_query | No | ||
| sql | No |
Implementation Reference
- tools/query.py:10-36 (handler)The databricks_query function is defined and decorated as an MCP tool, containing logic to validate against destructive SQL operations before calling execute_sql.
@mcp.tool def databricks_query(ctx: Context, sql_query: Optional[str] = None, sql: Optional[str] = None) -> List[Dict[str, Any]]: """ Execute Databricks SQL query (supports SELECT, SHOW, DESCRIBE, CREATE, ALTER). INSERT, UPDATE, DELETE, DROP and other destructive operations are blocked. Args: sql_query: SQL query statement (preferred parameter) sql: SQL query statement (fallback for backward compatibility) Returns: Query results as list of dicts """ query_to_execute = sql_query if sql_query is not None else sql if query_to_execute is None: raise ToolError("Must provide sql_query or sql parameter.") query_upper = query_to_execute.strip().upper() forbidden_keywords = [ "INSERT INTO", "UPDATE ", "DELETE FROM", "DROP TABLE", "DROP VIEW", "DROP SCHEMA", "DROP CATALOG", "TRUNCATE TABLE", "MERGE INTO", "COPY INTO" ] for keyword in forbidden_keywords: if keyword in query_upper: raise ToolError(f"Destructive operation not allowed: {keyword}") return execute_sql(ctx, query_to_execute)