Skip to main content
Glama
JustTryAI

Databricks MCP Server

execute_sql

Execute SQL queries on Databricks with parameter support for warehouses, catalogs, and schemas to retrieve and manage data.

Instructions

Execute a SQL statement with parameters: statement (required), warehouse_id (required), catalog (optional), schema (optional)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Registration of the execute_sql tool using the @self.tool decorator, including input parameter descriptions serving as schema.
    @self.tool(
        name="execute_sql",
        description="Execute a SQL statement with parameters: statement (required), warehouse_id (required), catalog (optional), schema (optional)",
    )
  • The handler function that implements the core logic of the execute_sql tool: parses input params and calls the sql module's execute_sql function.
    async def execute_sql(params: Dict[str, Any]) -> List[TextContent]:
        logger.info(f"Executing SQL with params: {params}")
        try:
            statement = params.get("statement")
            warehouse_id = params.get("warehouse_id")
            catalog = params.get("catalog")
            schema = params.get("schema")
            
            result = await sql.execute_sql(statement, warehouse_id, catalog, schema)
            return [{"text": json.dumps(result)}]
        except Exception as e:
            logger.error(f"Error executing SQL: {str(e)}")
            return [{"text": json.dumps({"error": str(e)})}]
  • Supporting function execute_statement in sql.py that likely implements the SQL execution logic called from the handler (note: handler calls execute_sql, which may be a naming mismatch).
    async def execute_statement(
        statement: str,
        warehouse_id: str,
        catalog: Optional[str] = None,
        schema: Optional[str] = None,
        parameters: Optional[Dict[str, Any]] = None,
        row_limit: int = 10000,
        byte_limit: int = 100000000,  # 100MB
    ) -> Dict[str, Any]:
        """
        Execute a SQL statement.
        
        Args:
            statement: The SQL statement to execute
            warehouse_id: ID of the SQL warehouse to use
            catalog: Optional catalog to use
            schema: Optional schema to use
            parameters: Optional statement parameters
            row_limit: Maximum number of rows to return
            byte_limit: Maximum number of bytes to return
            
        Returns:
            Response containing query results
            
        Raises:
            DatabricksAPIError: If the API request fails
        """
        logger.info(f"Executing SQL statement: {statement[:100]}...")
        
        request_data = {
            "statement": statement,
            "warehouse_id": warehouse_id,
            "wait_timeout": "0s",  # Wait indefinitely
            "row_limit": row_limit,
            "byte_limit": byte_limit,
        }
        
        if catalog:
            request_data["catalog"] = catalog
            
        if schema:
            request_data["schema"] = schema
            
        if parameters:
            request_data["parameters"] = parameters
            
        return make_api_request("POST", "/api/2.0/sql/statements/execute", data=request_data)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Execute a SQL statement') but doesn't cover critical traits like whether it's read-only or destructive, authentication needs, rate limits, error handling, or output format. This leaves significant gaps for an agent to understand the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action and lists parameters concisely. There's no wasted text, making it easy to parse, though it could benefit from more structured detail.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing SQL (a potentially destructive operation), no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks information on behavior, results, error cases, and how it fits with sibling tools, making it inadequate for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, and the description lists parameters (statement, warehouse_id, catalog, schema) but doesn't explain their semantics beyond being required or optional. It adds some value by naming parameters, but fails to detail their meanings, formats, or constraints, which is insufficient given the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Execute a SQL statement with parameters', which provides a clear verb ('Execute') and resource ('SQL statement'), but it's somewhat vague about the exact purpose (e.g., what database or system it targets) and doesn't distinguish it from potential siblings like 'run_job' or 'export_notebook'. It's adequate but lacks specificity.

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 mentions parameters but offers no guidance on when to use this tool versus alternatives like 'run_job' or 'list_jobs', nor does it specify prerequisites or contexts for SQL execution. It's a basic statement of function without usage context.

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/JustTryAI/databricks-mcp-server'

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