Skip to main content
Glama
ChrisChoTW

databricks-mcp

by ChrisChoTW

get_run_task_metrics

Retrieve detailed task execution metrics for Databricks job runs, including setup, execution, and cleanup times to monitor performance and identify bottlenecks.

Instructions

Get job run task execution time details

Args: run_id: Job Run ID

Returns: Task setup/execute/cleanup times (time in local timezone)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
run_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The implementation of the get_run_task_metrics tool, which retrieves and formats execution metrics for tasks within a specific job run.
    def get_run_task_metrics(ctx: Context, run_id: int) -> Dict[str, Any]:
        """
        Get job run task execution time details
    
        Args:
            run_id: Job Run ID
    
        Returns:
            Task setup/execute/cleanup times (time in local timezone)
        """
        w = get_workspace_client()
        ctx.info(f"Querying run {run_id} task metrics...")
    
        run = w.jobs.get_run(run_id=run_id)
        run_dict = run.as_dict()
    
        def ms_to_local(ms):
            if not ms:
                return None
            local_time = datetime.utcfromtimestamp(ms / 1000) + timedelta(hours=8)
            return local_time.strftime("%Y-%m-%d %H:%M:%S")
    
        tasks = []
        total_duration = 0
    
        if run_dict.get("tasks"):
            for t in run_dict["tasks"]:
                setup_ms = t.get("setup_duration", 0) or 0
                exec_ms = t.get("execution_duration", 0) or 0
                cleanup_ms = t.get("cleanup_duration", 0) or 0
                total_ms = setup_ms + exec_ms + cleanup_ms
                total_duration += total_ms
    
                tasks.append({
                    "task_key": t.get("task_key"),
                    "state": t.get("state", {}).get("result_state") or t.get("state", {}).get("life_cycle_state"),
                    "setup_sec": round(setup_ms / 1000, 1),
                    "execution_sec": round(exec_ms / 1000, 1),
                    "cleanup_sec": round(cleanup_ms / 1000, 1),
                    "total_sec": round(total_ms / 1000, 1),
                    "cluster_id": t.get("existing_cluster_id") or t.get("cluster_instance", {}).get("cluster_id")
                })
    
        tasks.sort(key=lambda x: x["execution_sec"], reverse=True)
    
        start_ms = run_dict.get("start_time")
        end_ms = run_dict.get("end_time")
        duration_min = round((end_ms - start_ms) / 1000 / 60, 2) if start_ms and end_ms else None
    
        return {
            "run_id": run_id,
            "job_id": run_dict.get("job_id"),
            "state": run_dict.get("state", {}).get("result_state"),
            "start_time_local": ms_to_local(start_ms),
            "end_time_local": ms_to_local(end_ms),
            "duration_min": duration_min,
            "total_task_duration_sec": round(total_duration / 1000, 1),
            "tasks": tasks,
            "slowest_task": tasks[0]["task_key"] if tasks else None
        }
  • Registration of the get_run_task_metrics tool using the @mcp.tool decorator.
    @mcp.tool
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions returning 'Task setup/execute/cleanup times' but lacks behavioral details such as authentication requirements, rate limits, error conditions, or whether this is a read-only operation. The description adds minimal context beyond the basic function.

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 appropriately sized and front-loaded, with the core purpose stated first. The Args and Returns sections are structured but slightly verbose; every sentence earns its place by clarifying inputs and outputs, though it could be more streamlined.

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

Completeness4/5

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

Given the tool has an output schema, the description doesn't need to detail return values extensively. It covers the purpose and parameter semantics adequately for a single-parameter query tool. However, with no annotations and minimal behavioral transparency, it could improve by adding context like authentication or error handling.

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

Parameters3/5

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

Schema description coverage is 0%, but the description compensates by explaining the single parameter 'run_id' as 'Job Run ID'. This adds meaning beyond the schema's type definition. However, it doesn't provide format details (e.g., where to obtain run_id) or constraints, keeping it at a baseline level.

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 verb ('Get') and resource ('job run task execution time details'), making the purpose understandable. It distinguishes from siblings like 'get_job_run' by specifying task-level timing metrics rather than general run information. However, it doesn't explicitly contrast with all similar siblings like 'get_cluster_metrics'.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing a valid run_id from another operation), exclusions, or comparisons to sibling tools like 'get_job_run' or 'list_job_runs'. Usage is implied but not explicitly defined.

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