Navigation
DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics - MCP Implementation

DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics

DBT CLI MCP Server: Accelerate data transformations, streamline workflows, and unlock real-time analytics insights at scale.

Developer Tools
4.4(141 reviews)
211 saves
98 comments

37% of users reported increased productivity after just one week

About DBT CLI MCP Server

What is DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics?

DBT CLI MCP Server acts as a bridge between AI coding agents and dbt projects, leveraging the Model Context Protocol (MCP) to standardize interactions. This server encapsulates the dbt CLI tool, enabling automated workflows and seamless integration with AI-driven platforms. By abstracting core dbt operations into MCP-compliant tools, it empowers developers to execute transformations, validate data pipelines, and analyze results with enhanced efficiency.

How to Use DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics?

Implementing the server involves three core steps: installation, configuration, and execution. Begin by setting up Python 3.10+, the uv tool, and dbt CLI. Clone the repository with submodules, initialize a virtual environment, and install dependencies via uv pip. To run commands, utilize the CLI interface with flags like --models and --project-dir, or integrate directly into MCP clients like Claude for Desktop by specifying server paths and environment variables. For advanced use, adjust logging levels or override default executable paths via config files.

DBT CLI MCP Server Features

Key Features of DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics?

  • Unified Command Execution: Execute dbt operations (run, test, compile) through standardized MCP tools.
  • Environment Control: Manage dbt profiles and environment variables via CLI flags or .env files.
  • Flexible Path Configuration: Override default dbt executable and profiles directories for multi-environment setups.
  • Development-Ready: Includes integration tests using the jaffle_shop_duckdb submodule and supports dev dependencies for extensibility.

Use Cases of DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics?

Automate data workflows by:

  • Integrating dbt into AI-driven development pipelines to validate models in real time.
  • Enabling teams to share project configurations securely via environment variable management.
  • Streamlining CI/CD processes by wrapping dbt commands in reproducible MCP tool invocations.
  • Debugging complex setups using the built-in dbt_debug tool to diagnose profile mismatches.

DBT CLI MCP Server FAQ

FAQ from DBT CLI MCP Server: Accelerate Transformations, Streamline Analytics?

  • Q: How do I resolve "profile not found" errors?
    Ensure profiles.yml exists in the project directory and matches the name in dbt_project.yml.
  • Q: Can I customize the dbt executable path?
    Yes, use the DBT_PATH environment variable or --dbt-path CLI flag.
  • Q: What tools are MCP-compliant?
    Includes dbt_run, dbt_test, dbt_compile, and others listed in the official documentation.
  • Q: How do I run integration tests?
    Navigate to the integration_tests directory and execute run_all.py to validate against the jaffle_shop project.

Content

DBT CLI MCP Server

A Model Context Protocol (MCP) server that wraps the dbt CLI tool, enabling AI coding agents to interact with dbt projects through standardized MCP tools.

Features

  • Execute dbt commands through MCP tools
  • Support for all major dbt operations (run, test, compile, etc.)
  • Command-line interface for direct interaction
  • Environment variable management for dbt projects
  • Configurable dbt executable path
  • Flexible profiles.yml location configuration

Installation

Prerequisites

  • Python 3.10 or higher
  • uv tool for Python environment management
  • dbt CLI installed

Setup

# Clone the repository with submodules
git clone --recurse-submodules https://github.com/yourusername/dbt-cli-mcp.git
cd dbt-cli-mcp

# If you already cloned without --recurse-submodules, initialize the submodule
# git submodule update --init

# Create and activate a virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
uv pip install -e .

# For development, install development dependencies
uv pip install -e ".[dev]"

Usage

Command Line Interface

The package provides a command-line interface for direct interaction with dbt:

# Run dbt models
dbt-mcp run --models customers --project-dir /path/to/project

# Run dbt models with a custom profiles directory
dbt-mcp run --models customers --project-dir /path/to/project --profiles-dir /path/to/profiles

# List dbt resources
dbt-mcp ls --resource-type model --output-format json

# Run dbt tests
dbt-mcp test --project-dir /path/to/project

# Get help
dbt-mcp --help
dbt-mcp run --help

You can also use the module directly:

python -m src.cli run --models customers --project-dir /path/to/project

Command Line Options

  • --dbt-path: Path to dbt executable (default: "dbt")
  • --env-file: Path to environment file (default: ".env")
  • --log-level: Logging level (default: "INFO")
  • --profiles-dir: Path to directory containing profiles.yml file (defaults to project-dir if not specified)

Environment Variables

The server can also be configured using environment variables:

  • DBT_PATH: Path to dbt executable
  • ENV_FILE: Path to environment file
  • LOG_LEVEL: Logging level
  • DBT_PROFILES_DIR: Path to directory containing profiles.yml file

Using with MCP Clients

To use the server with an MCP client like Claude for Desktop, add it to the client's configuration:

{
  "mcpServers": {
    "dbt": {
      "command": "uv",
      "args": ["--directory", "/path/to/dbt-cli-mcp", "run", "src/server.py"],
      "env": {
        "DBT_PATH": "/absolute/path/to/dbt",
        "ENV_FILE": ".env"
        // You can also set DBT_PROFILES_DIR here for a server-wide default
      }
    }
  }
}

Available Tools

The server provides the following MCP tools:

  • dbt_run: Run dbt models

  • dbt_test: Run dbt tests

  • dbt_ls: List dbt resources

  • dbt_compile: Compile dbt models

  • dbt_debug: Debug dbt project setup

  • dbt_deps: Install dbt package dependencies

  • dbt_seed: Load CSV files as seed data

  • dbt_show: Preview model results { "models": "customers", "project_dir": "/path/to/dbt/project", "limit": 10 }

    dbt Profiles Configuration

    When using the dbt MCP tools, it's important to understand how dbt profiles are handled:

    1. The project_dir parameter must point to a directory that contains both:

      • A valid dbt_project.yml file
      • A valid profiles.yml file with the profile referenced in the project
    2. The MCP server automatically sets the DBT_PROFILES_DIR environment variable to the absolute path of the directory specified in project_dir. This tells dbt where to look for the profiles.yml file.

    3. If you encounter a "Could not find profile named 'X'" error, it means either:

      • The profiles.yml file is missing from the project directory
      • The profiles.yml file doesn't contain the profile referenced in dbt_project.yml

    Example of a valid profiles.yml file:

    jaffle_shop:  # This name must match the profile in dbt_project.yml
      target: dev
      outputs:
        dev:
          type: duckdb
          path: 'jaffle_shop.duckdb'
          threads: 24
    

When running commands through the MCP server, ensure your project directory is structured correctly with both configuration files present.

Development

Integration Tests

The project includes integration tests that verify functionality against a real dbt project:

# Run all integration tests
python integration_tests/run_all.py

# Run a specific integration test
python integration_tests/test_dbt_run.py

Test Project Setup

The integration tests use the jaffle_shop_duckdb project which is included as a Git submodule in the dbt_integration_tests directory. When you clone the repository with --recurse-submodules as mentioned in the Setup section, this will automatically be initialized.

If you need to update the test project to the latest version from the original repository:

git submodule update --remote dbt_integration_tests/jaffle_shop_duckdb

If you're seeing errors about missing files in the jaffle_shop_duckdb directory, you may need to initialize the submodule:

git submodule update --init

License

MIT

Related MCP Servers & Clients