Skip to main content

DataHub Agent Context - MCP Tools for AI Agents

Project description

DataHub Agent Context

DataHub Agent Context provides a collection of tools and utilities for building AI agents that interact with DataHub metadata. This package contains MCP (Model Context Protocol) tools that enable AI agents to search, retrieve, and manipulate metadata in DataHub. These can be used directly to create an agent, or be included in an MCP server such as Datahub's open source MCP server.

Features

Installation

Base Installation

python3 -m pip install --upgrade pip wheel setuptools
python3 -m pip install --upgrade datahub-agent-context

With LangChain Support

For building LangChain agents with pre-built tools:

python3 -m pip install --upgrade "datahub-agent-context[langchain]"

Prerequisites

This package requires:

  • Python 3.9 or higher
  • acryl-datahub package

Quick Start

Basic Example

These tools are designed to be used with an AI agent and have the responses passed directly to an LLM, so the return schema is a simple dict, but they can be used independently if desired.

from datahub.ingestion.graph.client import DataHubGraph
from datahub_agent_context.mcp_tools.search import search
from datahub_agent_context.mcp_tools.entities import get_entities

# Initialize DataHub graph client
client = DataHubClient.from_env()

# Search for datasets
with client.graph as graph:
    results = search(
        query="user_data",
        filters={"entity_type": ["dataset"]},
        num_results=10
    )

# Get detailed entity information
with client.graph as graph:
    entities = get_entities(
        urns=[result["entity"]["urn"] for result in results["searchResults"]]
    )

LangChain Integration

Build AI agents with pre-built LangChain tools:

from datahub.sdk.main_client import DataHubClient
from datahub_agent_context.langchain_tools import build_langchain_tools
from langchain.agents import create_agent

# Initialize DataHub client
client = DataHubClient.from_env()

# Build all tools (read-only by default)
tools = build_langchain_tools(client, include_mutations=False)

# Or include mutation tools for tagging, descriptions, etc.
tools = build_langchain_tools(client, include_mutations=True)

# Create agent
agent = create_agent(model, tools=tools, system_prompt="...")

See examples/langchain/ for complete LangChain agent examples including:

Available Tools

Search Tools

  • search() - Search across all entity types with filters and sorting
  • search_documents() - Search specifically for Document entities
  • grep_documents() - Grep for patterns in document content

Entity Tools

  • get_entities() - Get detailed information about entities by URN
  • list_schema_fields() - List and filter schema fields for datasets

Lineage Tools

  • get_lineage() - Get upstream or downstream lineage
  • get_lineage_paths_between() - Get detailed paths between two entities

Query Tools

  • get_dataset_queries() - Get SQL queries for datasets or columns

Mutation Tools

  • add_tags(), remove_tags() - Manage tags
  • update_description() - Update entity descriptions
  • set_domains(), remove_domains() - Manage domains
  • add_owners(), remove_owners() - Manage owners
  • add_glossary_terms(), remove_glossary_terms() - Manage glossary terms
  • add_structured_properties(), remove_structured_properties() - Manage structured properties

User Tools

  • get_me() - Get information about the authenticated user

Architecture

The package is organized into the following modules:

  • mcp_tools/ - Core MCP tool implementations
    • base.py - Base GraphQL execution and response cleaning
    • search.py - Search functionality
    • documents.py - Document search and grep
    • entities.py - Entity retrieval
    • lineage.py - Lineage querying
    • queries.py - Query retrieval
    • tags.py, descriptions.py, domains.py, etc. - Mutation tools
    • helpers.py - Shared utility functions
    • gql/ - GraphQL query definitions

Development

Setup

# Clone the repository
git clone https://github.com/datahub-project/datahub.git
cd datahub/datahub-agent-context

# Set up development environment
./gradlew :datahub-agent-context:installDev

# Run tests
./gradlew :datahub-agent-context:testQuick

# Run linting
./gradlew :datahub-agent-context:lintFix

Testing

The package includes comprehensive unit tests for all tools:

# Run quick tests
./gradlew :datahub-agent-context:testQuick

# Run full test suite
./gradlew :datahub-agent-context:testFull

Support

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datahub_agent_context-1.3.1.10.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datahub_agent_context-1.3.1.10-py3-none-any.whl (68.6 kB view details)

Uploaded Python 3

File details

Details for the file datahub_agent_context-1.3.1.10.tar.gz.

File metadata

  • Download URL: datahub_agent_context-1.3.1.10.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for datahub_agent_context-1.3.1.10.tar.gz
Algorithm Hash digest
SHA256 492516aba3880df542939c862d02a659b4248d471c444f3a424c3c1e79dc1672
MD5 b571cf2c71a4ad5e80b3c28cef2c0484
BLAKE2b-256 5d0222134953ba2ac830907ee2ac3aeeb827898472ac91e248a40cace2febc0a

See more details on using hashes here.

File details

Details for the file datahub_agent_context-1.3.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for datahub_agent_context-1.3.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cec57b408fae780dc270f4a25a4f4f875cb791cef9bc33a2c772470e7f35aec5
MD5 8ba9f2d323d90fce00b3c6d9ec79b3df
BLAKE2b-256 3722030d860bff40423783f3bd2084024e31f26b1395fdccddc18df74d2df1ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page