dbt MCP server

Provides a bridge between dbt (data build tool) resources and natural language interfaces, enabling execution of CLI commands, discovery of model metadata, and querying of the Semantic Layer for data transformation management.
Back to servers
Setup instructions
Provider
dbt Labs
Release date
Apr 28, 2025
Language
Python
Package
Stats
105.8K downloads
434 stars

The dbt MCP server implements the Model Context Protocol to provide tools for interacting with dbt projects. It enables AI agents to access context from your dbt Core, dbt Fusion, and dbt Platform projects, allowing for powerful automations and insights through various built-in tools.

Installation and Setup

To get started with the dbt MCP server, follow these steps:

Prerequisites

Before installing, ensure you have:

  • A dbt project
  • Python installed on your system

Installation

Install the dbt MCP server using pip:

pip install dbt-mcp-server

Usage

The dbt MCP server provides a range of tools categorized by functionality. Here's how to use them:

Connecting to an Agent

The dbt MCP server is designed to be connected to AI agent products like Claude or Cursor. The connection allows these agents to access your dbt project context.

Available Tools

SQL Tools

SQL tools help you execute and generate SQL:

# Execute SQL against your data warehouse
response = mcp_client.execute_sql("SELECT * FROM my_table LIMIT 10")

# Generate SQL from natural language
sql_query = mcp_client.text_to_sql("Show me the top 10 customers by revenue")

Semantic Layer Tools

Access and query your dbt Semantic Layer:

# List available metrics
metrics = mcp_client.list_metrics()

# Query metrics
results = mcp_client.query_metrics(
    metrics=["revenue", "customer_count"],
    group_by=["country", "month"],
    where="country != 'Unknown'"
)

# Get compiled SQL for metrics
sql = mcp_client.get_metrics_compiled_sql(
    metrics=["revenue"],
    group_by=["country"]
)

Discovery Tools

Explore your dbt project structure:

# Get all models in your project
models = mcp_client.get_all_models()

# Search your project
search_results = mcp_client.search("customer revenue")

# Get details about a specific model
model_details = mcp_client.get_model_details("customers")

# Examine model lineage
parents = mcp_client.get_model_parents("customer_orders")
children = mcp_client.get_model_children("customer_orders")

dbt CLI Tools

Run dbt commands directly:

# Run a model
run_results = mcp_client.run(select=["my_model"])

# Compile your project
compile_results = mcp_client.compile()

# Test your models
test_results = mcp_client.test(select=["my_model"])

Admin API Tools

Manage dbt jobs:

# List available jobs
jobs = mcp_client.list_jobs()

# Trigger a job run
run_id = mcp_client.trigger_job_run(job_id=123)

# Get job run details
run_details = mcp_client.get_job_run_details(run_id=456)

dbt Codegen Tools

Generate dbt code automatically:

# Generate YAML for a model
yaml = mcp_client.generate_model_yaml(model_name="customers")

# Generate a source definition
source = mcp_client.generate_source(schema_name="raw_data")

# Generate a staging model
staging_model = mcp_client.generate_staging_model(source_name="raw", table_name="customers")

Getting Help

If you have questions or need support, create a GitHub Issue or join the community Slack in the #tools-dbt-mcp channel at dbt Community Slack.

For more detailed information, refer to the official documentation.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "dbt-mcp" '{"command":"uvx","args":["--env-file","<path-to-.env-file>","dbt-mcp"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "dbt-mcp": {
            "command": "uvx",
            "args": [
                "--env-file",
                "<path-to-.env-file>",
                "dbt-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "dbt-mcp": {
            "command": "uvx",
            "args": [
                "--env-file",
                "<path-to-.env-file>",
                "dbt-mcp"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later