Skip to main content
Glama
samhavens

Databricks MCP Server

by samhavens

execute_sql_nonblocking

Execute SQL queries asynchronously on Databricks to avoid blocking while processing large datasets, returning a statement ID for tracking.

Instructions

Start SQL statement execution and return immediately with statement_id (non-blocking)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
statementYes
warehouse_idYes
catalogNo
schema_nameNo

Implementation Reference

  • The primary handler function for the 'execute_sql_nonblocking' tool, registered via @mcp.tool() decorator. It invokes the sql.execute_statement helper, adds user-friendly notes, and serializes the response to JSON.
    @mcp.tool()
    async def execute_sql_nonblocking(
        statement: str,
        warehouse_id: str,
        catalog: Optional[str] = None,
        schema_name: Optional[str] = None
    ) -> str:
        """Start SQL statement execution and return immediately with statement_id (non-blocking)"""
        logger.info(f"Executing SQL statement (non-blocking): {statement[:100]}...")
        try:
            result = await sql.execute_statement(statement, warehouse_id, catalog, schema_name)
            
            # Add helpful info about checking status
            status = result.get("status", {}).get("state", "")
            if status == "PENDING":
                result["note"] = "Query started. Use get_sql_status with the statement_id to check progress."
                
            return json.dumps(result)
        except Exception as e:
            logger.error(f"Error executing SQL: {str(e)}")
            return json.dumps({"error": str(e)})
  • Supporting utility function that constructs the API request payload and calls the Databricks SQL Statements API (non-blocking execution with wait_timeout=0s). Handles fallback to alternative endpoint if needed.
    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 = 26214400,  # 25MB max allowed
    ) -> 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",  # Return immediately, don't wait
            "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
            
        # Try the classic SQL API first (works on most workspaces)
        try:
            return make_api_request("POST", "/api/2.0/sql/statements", data=request_data)
        except Exception as e:
            # If that fails, try the newer SQL execution API
            logger.warning(f"Classic SQL API failed: {e}. Trying newer SQL execution API...")
            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?

No annotations are provided, so the description carries the full burden. It discloses the non-blocking behavior and immediate return of a statement_id, which is useful. However, it lacks critical behavioral details such as execution timeouts, error handling, authentication requirements, or how to retrieve results later (e.g., using 'get_sql_status'). For a tool with no annotations, this is a significant gap.

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

Conciseness5/5

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

The description is a single, well-structured sentence that front-loads the key action and outcome. It wastes no words and efficiently communicates the core functionality. Every part of the sentence earns its place by specifying the action, behavior, and return value.

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 a SQL execution tool with no annotations, no output schema, and 4 parameters (2 required), the description is incomplete. It covers the high-level behavior but misses details on parameter usage, result retrieval (e.g., via 'get_sql_status'), error scenarios, and integration with sibling tools. For such a tool, more context is needed to guide 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?

Schema description coverage is 0%, so the description must compensate. It doesn't mention any parameters or their semantics (e.g., what 'warehouse_id' refers to, the format of 'statement', or the purpose of 'catalog' and 'schema_name'). With 4 parameters and no schema descriptions, the description adds no value beyond what the bare schema provides, failing to clarify usage.

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

Purpose4/5

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

The description clearly states the action ('Start SQL statement execution') and the resource (SQL statement), and specifies the non-blocking behavior with immediate return of a statement_id. It distinguishes from the sibling 'execute_sql' by highlighting the non-blocking aspect, though it doesn't explicitly name the sibling. The purpose is specific and actionable.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for asynchronous SQL execution where immediate results aren't needed, contrasting with the blocking 'execute_sql' sibling. However, it doesn't explicitly state when to use this tool versus alternatives like 'execute_sql' or provide context on prerequisites (e.g., warehouse availability). The guidance is implied but not detailed.

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

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