Skip to main content
Glama
astronomer

astro-airflow-mcp

Official
by astronomer

get_upstream_asset_events

Retrieve the asset events that triggered a specific DAG run, helping you understand why the pipeline started and which data changes caused the execution.

Instructions

Get asset events that triggered a specific DAG run.

Use this tool when the user asks about:

  • "What triggered this DAG run?"

  • "Which asset events caused this run to start?"

  • "Why did DAG X start running?"

  • "Show me the upstream triggers for this run"

  • "What data changes triggered this pipeline run?"

This is useful for understanding causation in data-aware scheduling. When a DAG is scheduled based on asset updates, this tool shows which specific asset events triggered the run.

Returns information including:

  • dag_id: The DAG that was triggered

  • dag_run_id: The specific run

  • triggered_by_events: List of asset events that caused this run

  • event_count: Number of triggering events

Each event includes:

  • asset_uri or dataset_uri: The asset that was updated

  • source_dag_id: The DAG that produced the event

  • source_run_id: The run that produced the event

  • timestamp: When the event occurred

Args: dag_id: The ID of the DAG dag_run_id: The ID of the DAG run (e.g., "scheduled__2024-01-01T00:00:00+00:00")

Returns: JSON with the asset events that triggered this DAG run

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dag_idYes
dag_run_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The internal implementation function _get_upstream_asset_events_impl that executes the tool logic. It calls adapter.get_dag_run_upstream_asset_events() and formats the response with dag_id, dag_run_id, triggered_by_events, and event_count.
    def _get_upstream_asset_events_impl(
        dag_id: str,
        dag_run_id: str,
    ) -> str:
        """Internal implementation for getting upstream asset events for a DAG run.
    
        Args:
            dag_id: The DAG ID
            dag_run_id: The DAG run ID
    
        Returns:
            JSON string containing the asset events that triggered this run
        """
        try:
            adapter = _get_adapter()
            data = adapter.get_dag_run_upstream_asset_events(dag_id, dag_run_id)
    
            if "asset_events" in data:
                return json.dumps(
                    {
                        "dag_id": dag_id,
                        "dag_run_id": dag_run_id,
                        "triggered_by_events": data["asset_events"],
                        "event_count": len(data["asset_events"]),
                    },
                    indent=2,
                )
            return json.dumps(data, indent=2)
        except Exception as e:
            return str(e)
  • The MCP tool registration via @mcp.tool() decorator with docstring describing usage for getting upstream asset events that triggered a DAG run. Calls _get_upstream_asset_events_impl.
    @mcp.tool()
    def get_upstream_asset_events(
        dag_id: str,
        dag_run_id: str,
    ) -> str:
        """Get asset events that triggered a specific DAG run.
    
        Use this tool when the user asks about:
        - "What triggered this DAG run?"
        - "Which asset events caused this run to start?"
        - "Why did DAG X start running?"
        - "Show me the upstream triggers for this run"
        - "What data changes triggered this pipeline run?"
    
        This is useful for understanding causation in data-aware scheduling.
        When a DAG is scheduled based on asset updates, this tool shows which
        specific asset events triggered the run.
    
        Returns information including:
        - dag_id: The DAG that was triggered
        - dag_run_id: The specific run
        - triggered_by_events: List of asset events that caused this run
        - event_count: Number of triggering events
    
        Each event includes:
        - asset_uri or dataset_uri: The asset that was updated
        - source_dag_id: The DAG that produced the event
        - source_run_id: The run that produced the event
        - timestamp: When the event occurred
    
        Args:
            dag_id: The ID of the DAG
            dag_run_id: The ID of the DAG run (e.g., "scheduled__2024-01-01T00:00:00+00:00")
    
        Returns:
            JSON with the asset events that triggered this DAG run
        """
        return _get_upstream_asset_events_impl(dag_id, dag_run_id)
  • Abstract method definition in the base AirflowAdapter class defining the interface for get_dag_run_upstream_asset_events.
    def get_dag_run_upstream_asset_events(
        self,
        dag_id: str,
        dag_run_id: str,
    ) -> dict[str, Any]:
        """Get asset events that triggered a specific DAG run.
    
        This is used to verify causation - which asset events caused this
        DAG run to be scheduled (data-aware scheduling).
    
        Args:
            dag_id: The DAG ID
            dag_run_id: The DAG run ID
    
        Returns:
            Dict with 'asset_events' list showing which events triggered this run
        """
  • Airflow 2.x implementation of get_dag_run_upstream_asset_events. Calls the 'upstreamDatasetEvents' endpoint and normalizes field names (dataset_events->asset_events, dataset_uri->uri, dataset_id->asset_id).
    def get_dag_run_upstream_asset_events(
        self,
        dag_id: str,
        dag_run_id: str,
    ) -> dict[str, Any]:
        """Get upstream dataset events that triggered a DAG run (Airflow 2.x).
    
        Normalizes field names for consistency with Airflow 3:
        - 'dataset_events' -> 'asset_events'
        - 'dataset_uri' -> 'uri'
        - 'dataset_id' -> 'asset_id'
        """
        try:
            data = self._call(f"dags/{dag_id}/dagRuns/{dag_run_id}/upstreamDatasetEvents")
    
            # Normalize field names
            if "dataset_events" in data:
                data["asset_events"] = data.pop("dataset_events")
                for event in data.get("asset_events", []):
                    if "dataset_uri" in event:
                        event["uri"] = event.pop("dataset_uri")
                    if "dataset_id" in event:
                        event["asset_id"] = event.pop("dataset_id")
    
            return data
        except NotFoundError:
            return self._handle_not_found(
                "upstreamDatasetEvents",
                alternative="This endpoint requires Airflow 2.4+ and a dataset-triggered run",
            )
  • Airflow 3.x implementation of get_dag_run_upstream_asset_events. Calls the 'upstreamAssetEvents' endpoint and normalizes asset_uri to uri for consistency.
    def get_dag_run_upstream_asset_events(
        self,
        dag_id: str,
        dag_run_id: str,
    ) -> dict[str, Any]:
        """Get upstream asset events that triggered a DAG run (Airflow 3.x).
    
        Normalizes field names for consistency:
        - 'asset_uri' -> 'uri'
        """
        try:
            data = self._call(f"dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents")
    
            # Normalize field names
            if "asset_events" in data:
                for event in data.get("asset_events", []):
                    if "asset_uri" in event:
                        event["uri"] = event.pop("asset_uri")
    
            return data
        except NotFoundError:
            return self._handle_not_found(
                "upstreamAssetEvents",
                alternative="This endpoint requires an asset-triggered DAG run",
            )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description compensates by detailing the return structure (fields like dag_id, triggered_by_events, event_count, etc.) and explains the context of data-aware scheduling. It implies a read-only operation but does not explicitly state idempotency or lack of side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with bullet points and sections, covering key aspects without being overly verbose. Slightly more concise phrasing could be used, but it remains clear and scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 params, no nested objects) and presence of an output schema, the description fully addresses purpose, usage, parameters, and return information. It also provides operational context (data-aware scheduling) which enhances understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 0% description coverage, but the description provides clear explanations for both required parameters: dag_id and dag_run_id, including an example format for dag_run_id. This adds significant meaning beyond the schema's type definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'asset events that triggered a specific DAG run'. It distinguishes this tool from siblings like list_asset_events and get_dag_run by focusing on causation for a specific run.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use guidance with example user queries ('What triggered this DAG run?', 'Why did DAG X start running?'), making it easy for an agent to select this tool for traceability questions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/astronomer/astro-airflow-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server