get_task
Retrieve specific task details from Apache Airflow using DAG and task identifiers to monitor and manage workflow execution.
Instructions
Get a task by ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes | ||
| task_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"dag_id": {
"title": "Dag Id",
"type": "string"
},
"task_id": {
"title": "Task Id",
"type": "string"
}
},
"required": [
"dag_id",
"task_id"
],
"type": "object"
}
Implementation Reference
- src/airflow/dag.py:172-177 (handler)The handler function implementing the 'get_task' tool logic. It retrieves the task information from the Airflow DAG API using dag_id and task_id, converts the response to a dictionary, and returns it as MCP TextContent.async def get_task( dag_id: str, task_id: str ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: response = dag_api.get_task(dag_id=dag_id, task_id=task_id) return [types.TextContent(type="text", text=str(response.to_dict()))]
- src/airflow/dag.py:17-33 (registration)The get_all_functions() in dag.py returns a list of tool tuples, including the one for 'get_task' (get_task, "get_task", "Get a task by ID", True), used for registering DAG tools.return [ (get_dags, "fetch_dags", "Fetch all DAGs", True), (get_dag, "get_dag", "Get a DAG by ID", True), (get_dag_details, "get_dag_details", "Get a simplified representation of DAG", True), (get_dag_source, "get_dag_source", "Get a source code", True), (pause_dag, "pause_dag", "Pause a DAG by ID", False), (unpause_dag, "unpause_dag", "Unpause a DAG by ID", False), (get_dag_tasks, "get_dag_tasks", "Get tasks for DAG", True), (get_task, "get_task", "Get a task by ID", True), (get_tasks, "get_tasks", "Get tasks for DAG", True), (patch_dag, "patch_dag", "Update a DAG", False), (patch_dags, "patch_dags", "Update multiple DAGs", False), (delete_dag, "delete_dag", "Delete a DAG", False), (clear_task_instances, "clear_task_instances", "Clear a set of task instances", False), (set_task_instances_state, "set_task_instances_state", "Set a state of task instances", False), (reparse_dag_file, "reparse_dag_file", "Request re-parsing of a DAG file", False), ]
- src/main.py:22-38 (registration)Mapping APIType.DAG to get_dag_functions() which provides the get_task tool among others, enabling its registration.APITYPE_TO_FUNCTIONS = { APIType.CONFIG: get_config_functions, APIType.CONNECTION: get_connection_functions, APIType.DAG: get_dag_functions, APIType.DAGRUN: get_dagrun_functions, APIType.DAGSTATS: get_dagstats_functions, APIType.DATASET: get_dataset_functions, APIType.EVENTLOG: get_eventlog_functions, APIType.IMPORTERROR: get_importerror_functions, APIType.MONITORING: get_monitoring_functions, APIType.PLUGIN: get_plugin_functions, APIType.POOL: get_pool_functions, APIType.PROVIDER: get_provider_functions, APIType.TASKINSTANCE: get_taskinstance_functions, APIType.VARIABLE: get_variable_functions, APIType.XCOM: get_xcom_functions, }
- src/main.py:90-92 (registration)The loop that registers each tool from the functions list by calling app.add_tool, including get_task when DAG API is enabled.for func, name, description, *_ in functions: app.add_tool(func, name=name, description=description)
- src/airflow/dag.py:12-12 (helper)Initialization of the dag_api client used by get_task to interact with Airflow.dag_api = DAGApi(api_client)