dag_code
Retrieve the source code for a specific Apache Airflow DAG by providing its DAG ID, enabling developers to inspect and manage workflows directly within the MCP-Airflow-API environment.
Instructions
[Tool Role]: Retrieves the source code for a specific DAG.
Args: dag_id: The DAG ID to get source code for
Returns: DAG source code: dag_id, file_token, source_code
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes |
Implementation Reference
- The main handler function for the 'dag_code' tool. It fetches the source code of a specified DAG using the Airflow API endpoint /dagSources/{dag_id}.async def dag_code(dag_id: str) -> Dict[str, Any]: """[Tool Role]: Retrieves the source code for the specified DAG.""" if not dag_id: raise ValueError("dag_id must not be empty") resp = await airflow_request("GET", f"/dagSources/{dag_id}") resp.raise_for_status() return resp.json()
- src/mcp_airflow_api/tools/v1_tools.py:23-23 (registration)Registration of common tools (including dag_code) for Airflow API v1 by calling register_common_tools.common_tools.register_common_tools(mcp)
- src/mcp_airflow_api/tools/v2_tools.py:24-24 (registration)Registration of common tools (including dag_code) for Airflow API v2 by calling register_common_tools.common_tools.register_common_tools(mcp)
- src/mcp_airflow_api/mcp_main.py:384-385 (registration)Calls v1_tools.register_tools which registers dag_code for v1 API.from mcp_airflow_api.tools import v1_tools v1_tools.register_tools(mcp)
- src/mcp_airflow_api/mcp_main.py:387-388 (registration)Calls v2_tools.register_tools which registers dag_code for v2 API.logger.info("Loading Airflow API v2 tools (Airflow 3.0+)") from mcp_airflow_api.tools import v2_tools