Skip to main content
Glama
ChrisChoTW

databricks-mcp

by ChrisChoTW

list_query_history

Retrieve and filter SQL query execution records from Databricks. Use parameters like warehouse, user, time range, and result limit to monitor and analyze query performance.

Instructions

List SQL query history

Args: warehouse_id: (Optional) Filter by specific warehouse user_id: (Optional) Filter by specific user start_time: (Optional) Start time in local format "YYYY-MM-DD HH:MM:SS" end_time: (Optional) End time in local format "YYYY-MM-DD HH:MM:SS" limit: Number of results to return

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
warehouse_idNo
user_idNo
start_timeNo
end_timeNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Implementation of the list_query_history MCP tool handler.
    @mcp.tool
    def list_query_history(
        ctx: Context,
        warehouse_id: str = None,
        user_id: str = None,
        start_time: str = None,
        end_time: str = None,
        limit: int = 20
    ) -> List[Dict[str, Any]]:
        """
        List SQL query history
    
        Args:
            warehouse_id: (Optional) Filter by specific warehouse
            user_id: (Optional) Filter by specific user
            start_time: (Optional) Start time in local format "YYYY-MM-DD HH:MM:SS"
            end_time: (Optional) End time in local format "YYYY-MM-DD HH:MM:SS"
            limit: Number of results to return
        """
        from databricks.sdk.service.sql import QueryFilter, TimeRange
    
        w = get_workspace_client()
    
        # Build filter
        filter_kwargs = {}
    
        if warehouse_id:
            filter_kwargs["warehouse_ids"] = [warehouse_id]
    
        if user_id:
            filter_kwargs["user_ids"] = [int(user_id)]
    
        # Time range (local time to Unix timestamp ms)
        if start_time or end_time:
            time_range_kwargs = {}
            if start_time:
                dt = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
                time_range_kwargs["start_time_ms"] = int(dt.timestamp() * 1000)
            if end_time:
                dt = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
                time_range_kwargs["end_time_ms"] = int(dt.timestamp() * 1000)
            filter_kwargs["query_start_time_range"] = TimeRange(**time_range_kwargs)
    
        if filter_kwargs:
            filter_by = QueryFilter(**filter_kwargs)
            response = w.query_history.list(filter_by=filter_by, max_results=limit)
        else:
            response = w.query_history.list(max_results=limit)
    
        queries_list = response.res if response and response.res else []
    
        results = []
        for q in queries_list:
            q_dict = q.as_dict()
            start_ms = q_dict.get("query_start_time_ms")
            start_time_local = None
            if start_ms:
                dt_local = datetime.fromtimestamp(start_ms / 1000)
                start_time_local = dt_local.strftime("%Y-%m-%d %H:%M:%S")
    
            results.append({
                "query_id": q_dict.get("query_id"),
                "query_text": q_dict.get("query_text"),
                "status": q_dict.get("status"),
                "statement_type": q_dict.get("statement_type"),
                "user_name": q_dict.get("user_name"),
                "duration": q_dict.get("duration"),
                "start_time_ms": start_ms,
                "start_time_local": start_time_local
            })
        return results
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 of behavioral disclosure. It describes a read operation ('List') but lacks details on permissions, rate limits, pagination, or what the output contains. The mention of 'limit' hints at result truncation, but it doesn't explain default ordering or if results are sorted by time. This is inadequate for a tool with no annotation coverage.

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 well-structured with a brief purpose statement followed by a parameter list. Each parameter explanation is concise and to the point. There's no redundant information, and the formatting makes it easy to scan. However, the lack of usage context slightly reduces efficiency.

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

Completeness3/5

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

Given the tool's moderate complexity (5 parameters, no annotations, but has an output schema), the description is partially complete. It covers parameter semantics well but lacks behavioral context and usage guidelines. The presence of an output schema means the description doesn't need to explain return values, but it should still address when and how to use the tool effectively.

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

Parameters4/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 provides clear semantics for all 5 parameters, explaining their optional nature, filtering purposes, and format details (e.g., 'local format "YYYY-MM-DD HH:MM:SS"' for time parameters). This adds significant value beyond the bare schema, though it doesn't cover edge cases like timezone handling.

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 tool's purpose: 'List SQL query history' specifies the verb ('List') and resource ('SQL query history'). It distinguishes from some siblings like 'list_tables' or 'list_warehouses' by focusing on query history, though it doesn't explicitly differentiate from all potential alternatives like 'databricks_query' which might have overlapping functionality.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, context for usage, or comparisons with sibling tools like 'databricks_query' or 'search_tables'. The agent must infer usage based solely on the tool name and parameters.

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

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