dag_graph
Retrieve the task dependency graph structure for a specific DAG in Apache Airflow. Simplifies DAG inspection by providing clear task and dependency details.
Instructions
[Tool Role]: Retrieves the task dependency graph structure for a specific DAG.
Args: dag_id: The DAG ID to get graph structure for
Returns: DAG graph with tasks and dependencies: dag_id, tasks, dependencies
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes |
Implementation Reference
- The core handler function for the 'dag_graph' tool. It fetches the tasks from the Airflow API endpoint /dags/{dag_id}/tasks, constructs a graph representation with upstream/downstream dependencies, and returns a structured dictionary suitable for graph visualization including nodes and edges.@mcp.tool() async def dag_graph(dag_id: str) -> Dict[str, Any]: """[Tool Role]: Retrieves task graph structure for the specified DAG.""" if not dag_id: raise ValueError("dag_id must not be empty") resp = await airflow_request("GET", f"/dags/{dag_id}/tasks") resp.raise_for_status() tasks_data = resp.json() tasks = tasks_data.get("tasks", []) task_graph = {} for task in tasks: task_id = task.get("task_id") task_graph[task_id] = { "task_id": task_id, "task_type": task.get("class_ref", {}).get("class_name"), "downstream_task_ids": task.get("downstream_task_ids", []), "upstream_task_ids": task.get("upstream_task_ids", []) } return { "dag_id": dag_id, "task_graph": task_graph, "total_tasks": len(tasks), "task_relationships": { "nodes": list(task_graph.keys()), "edges": [(task_id, downstream) for task_id, task_info in task_graph.items() for downstream in task_info["downstream_task_ids"]] } }
- src/mcp_airflow_api/tools/v1_tools.py:19-23 (registration)Registration of common tools (including dag_graph) for Airflow API v1 by setting the v1-specific airflow_request function and calling register_common_tools.# Set the global request function to v1 common_tools.airflow_request = airflow_request_v1 # Register all 56 common tools (includes management tools) common_tools.register_common_tools(mcp)
- src/mcp_airflow_api/tools/v2_tools.py:20-24 (registration)Registration of common tools (including dag_graph) for Airflow API v2 by setting the v2-specific airflow_request function and calling register_common_tools.# Set the global request function to v2 common_tools.airflow_request = airflow_request_v2 # Register all 43 common tools common_tools.register_common_tools(mcp)