update_task_instance
Modify task instance state in Apache Airflow workflows using DAG ID, DAG run ID, and task ID parameters to manage workflow execution.
Instructions
Update a task instance by DAG ID, DAG run ID, and task ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes | ||
| dag_run_id | Yes | ||
| task_id | Yes | ||
| state | No |
Implementation Reference
- src/airflow/taskinstance.py:88-102 (handler)The async handler function that implements the core logic of the 'update_task_instance' tool by calling the Airflow TaskInstanceApi to patch the task instance state.async def update_task_instance( dag_id: str, dag_run_id: str, task_id: str, state: Optional[str] = None ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: update_request = {} if state is not None: update_request["state"] = state response = task_instance_api.patch_task_instance( dag_id=dag_id, dag_run_id=dag_run_id, task_id=task_id, update_mask=list(update_request.keys()), task_instance_request=update_request, ) return [types.TextContent(type="text", text=str(response.to_dict()))]
- src/airflow/taskinstance.py:11-22 (registration)Module-level function that returns the registration details for task instance tools, including the 'update_task_instance' tool.def get_all_functions() -> list[tuple[Callable, str, str, bool]]: """Return list of (function, name, description, is_read_only) tuples for registration.""" return [ (get_task_instance, "get_task_instance", "Get a task instance by DAG ID, task ID, and DAG run ID", True), (list_task_instances, "list_task_instances", "List task instances by DAG ID and DAG run ID", True), ( update_task_instance, "update_task_instance", "Update a task instance by DAG ID, DAG run ID, and task ID", False, ), ]
- src/main.py:17-35 (registration)Top-level import and mapping of the taskinstance module's get_all_functions for global tool registration in the MCP server.from src.airflow.taskinstance import get_all_functions as get_taskinstance_functions from src.airflow.variable import get_all_functions as get_variable_functions from src.airflow.xcom import get_all_functions as get_xcom_functions from src.enums import APIType 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,
- src/main.py:90-92 (registration)The loop that registers all tools from modules like taskinstance by calling app.add_tool with the function, name, and description.for func, name, description, *_ in functions: app.add_tool(func, name=name, description=description)