get_task_instance
Retrieve a specific task instance from an Airflow DAG run by providing the DAG ID, task ID, and DAG run ID to access execution details and status.
Instructions
Get a task instance by DAG ID, task ID, and DAG run ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes | ||
| dag_run_id | Yes | ||
| task_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"dag_id": {
"title": "Dag Id",
"type": "string"
},
"dag_run_id": {
"title": "Dag Run Id",
"type": "string"
},
"task_id": {
"title": "Task Id",
"type": "string"
}
},
"required": [
"dag_id",
"task_id",
"dag_run_id"
],
"type": "object"
}
Implementation Reference
- src/airflow/taskinstance.py:25-29 (handler)The async handler function implementing the 'get_task_instance' tool logic. It calls the Airflow TaskInstanceApi to fetch the task instance by dag_id, task_id, and dag_run_id, then returns the response as text content.async def get_task_instance( dag_id: str, task_id: str, dag_run_id: str ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: response = task_instance_api.get_task_instance(dag_id=dag_id, dag_run_id=dag_run_id, task_id=task_id) return [types.TextContent(type="text", text=str(response.to_dict()))]
- src/airflow/taskinstance.py:14-14 (registration)The registration tuple for the 'get_task_instance' tool, including the function reference, name, description, and read-only flag, provided by get_all_functions().(get_task_instance, "get_task_instance", "Get a task instance by DAG ID, task ID, and DAG run ID", True),
- src/main.py:90-91 (registration)The generic registration code in main.py that adds each tool (including get_task_instance) to the MCP app using app.add_tool during server startup.for func, name, description, *_ in functions: app.add_tool(func, name=name, description=description)
- src/main.py:17-17 (registration)Import of get_all_functions from taskinstance.py in main.py, aliased and used to load the tool registrations.from src.airflow.taskinstance import get_all_functions as get_taskinstance_functions