Skip to main content
Glama
ChrisChoTW

databricks-mcp

by ChrisChoTW

get_table_lineage

Retrieve table lineage to identify upstream and downstream dependencies, including related notebooks and jobs in Databricks environments.

Instructions

Get table lineage (upstream/downstream tables and related notebooks/jobs)

Args: catalog: Catalog name schema: Schema name table: Table name include_notebooks: Include notebook/job associations (slower) limit: Max rows to return (default 50)

Returns: Dict with upstream, downstream tables and optionally notebook/job info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
catalogYes
schemaYes
tableYes
include_notebooksNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'get_table_lineage' function handles retrieving and classifying table lineage (upstream/downstream tables and associated notebook/job information) from the system.access.table_lineage table. It is registered as an MCP tool using the @mcp.tool decorator.
    def get_table_lineage(
        ctx: Context,
        catalog: str,
        schema: str,
        table: str,
        include_notebooks: bool = False,
        limit: int = 50
    ) -> Dict[str, Any]:
        """
        Get table lineage (upstream/downstream tables and related notebooks/jobs)
    
        Args:
            catalog: Catalog name
            schema: Schema name
            table: Table name
            include_notebooks: Include notebook/job associations (slower)
            limit: Max rows to return (default 50)
    
        Returns:
            Dict with upstream, downstream tables and optionally notebook/job info
        """
        cat = safe_identifier(catalog, "catalog")
        sch = safe_identifier(schema, "schema")
        tbl = safe_identifier(table, "table")
        full_name = f"{cat}.{sch}.{tbl}"
    
        # Query system.access.table_lineage
        sql_query = f"""
        SELECT DISTINCT
            source_table_full_name,
            target_table_full_name,
            entity_type,
            entity_metadata
        FROM system.access.table_lineage
        WHERE source_table_full_name = '{full_name}'
           OR target_table_full_name = '{full_name}'
        ORDER BY source_table_full_name, target_table_full_name
        LIMIT {limit}
        """
    
        rows = execute_sql(ctx, sql_query)
    
        # Classify upstream/downstream
        upstream: Set[str] = set()
        downstream: Set[str] = set()
        notebook_reads: Dict[str, Dict] = {}
        notebook_writes: Dict[str, Dict] = {}
    
        # Collect job/notebook pairs for resolution
        job_notebook_pairs: List[Dict] = []
    
        for row in rows:
            source = row.get("source_table_full_name")
            target = row.get("target_table_full_name")
            metadata_str = row.get("entity_metadata")
    
            # Classify tables
            if source == full_name and target and target != full_name:
                downstream.add(target)
            elif target == full_name and source and source != full_name:
                upstream.add(source)
    
            # Parse notebook/job info if requested
            if include_notebooks and metadata_str:
                try:
                    metadata = json.loads(metadata_str) if isinstance(metadata_str, str) else metadata_str
                    notebook_id = metadata.get("notebook_id")
                    job_info = metadata.get("job_info", {})
                    job_id = job_info.get("job_id") if job_info else None
    
                    if notebook_id and job_id:
                        job_notebook_pairs.append({
                            "notebook_id": notebook_id,
                            "job_id": job_id,
                            "source": source,
                            "target": target
                        })
                except (json.JSONDecodeError, TypeError):
                    pass
    
        result = {
            "table": full_name,
            "upstream": sorted(upstream),
            "downstream": sorted(downstream),
            "upstream_count": len(upstream),
            "downstream_count": len(downstream)
        }
    
        # Resolve notebook/job details if requested
        if include_notebooks and job_notebook_pairs:
            ctx.info(f"Resolving {len(job_notebook_pairs)} notebook/job associations...")
            w = get_workspace_client()
    
            for pair in job_notebook_pairs:
                key = f"{pair['job_id']}:{pair['notebook_id']}"
                info = _resolve_job_info(w, pair["job_id"], pair["notebook_id"])
    
                if pair["source"] == full_name:
                    notebook_reads[key] = info
                elif pair["target"] == full_name:
                    notebook_writes[key] = info
    
            result["notebooks_reading"] = list(notebook_reads.values())
            result["notebooks_writing"] = list(notebook_writes.values())
    
        return result
Behavior3/5

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

With no annotations provided, the description carries full burden. It mentions that including notebooks/jobs is 'slower', which is useful behavioral context about performance trade-offs. However, it doesn't disclose other important traits like authentication requirements, rate limits, error conditions, or whether this is a read-only operation.

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?

Well-structured with clear sections (Args, Returns) and front-loaded purpose statement. The description is appropriately sized with no wasted sentences, though the performance note about 'slower' could be more precisely worded.

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

Completeness4/5

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

Given the tool's moderate complexity (5 parameters, lineage analysis), no annotations, but with an output schema present, the description provides good coverage. It explains parameters well and outlines the return structure. The main gap is lack of usage context relative to sibling tools.

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

Parameters4/5

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

The schema has 0% description coverage, so the description must compensate. It provides clear explanations for all 5 parameters in the Args section, including the purpose of each parameter and default values. The only minor gap is not explaining format expectations for catalog/schema/table names.

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 specific action ('Get table lineage') and resources involved ('upstream/downstream tables and related notebooks/jobs'). It distinguishes this tool from siblings like get_table_detail or get_table_schema by focusing on lineage relationships rather than metadata or structure.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. While siblings like get_table_detail or search_tables exist, the description doesn't explain when lineage information is needed versus other table metadata or how this tool complements them.

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/ChrisChoTW/databricks-mcp'

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