Skip to main content

A Model Context Protocol server for dbt CLI

Project description

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
      }
    }
  }
}

⚠️ IMPORTANT: Absolute Project Path Required ⚠️

When using any tool from this MCP server, you MUST specify the FULL ABSOLUTE PATH to your dbt project directory with the project_dir parameter. Relative paths will not work correctly.

// ❌ INCORRECT - Will NOT work
{
  "project_dir": "."
}

// ✅ CORRECT - Will work
{
  "project_dir": "/Users/username/path/to/your/dbt/project"
}

See the complete dbt MCP usage guide for more detailed instructions and examples.

Available Tools

The server provides the following MCP tools:

  • dbt_run: Run dbt models (requires absolute project_dir)
  • dbt_test: Run dbt tests (requires absolute project_dir)
  • dbt_ls: List dbt resources (requires absolute project_dir)
  • dbt_compile: Compile dbt models (requires absolute project_dir)
  • dbt_debug: Debug dbt project setup (requires absolute project_dir)
  • dbt_deps: Install dbt package dependencies (requires absolute project_dir)
  • dbt_seed: Load CSV files as seed data (requires absolute project_dir)
  • dbt_show: Preview model results (requires absolute project_dir)
{ "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 be an absolute path (e.g., /Users/username/project not .) that points to a directory containing 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
    • You provided a relative path instead of an absolute path for project_dir

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

Project details


Download files

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

Source Distribution

iflow_mcp_dbt_cli_mcp-0.1.0.tar.gz (123.2 kB view details)

Uploaded Source

Built Distribution

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

iflow_mcp_dbt_cli_mcp-0.1.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_dbt_cli_mcp-0.1.0.tar.gz.

File metadata

File hashes

Hashes for iflow_mcp_dbt_cli_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b48a3e450e3e4b321e33f51ea089a2d1d57394fcdd322bf5e924ac44ee446a0d
MD5 1f2e891eafc7d7df97840dbc2bd9f3fb
BLAKE2b-256 89823d7d8ff635d7e8ca1179ad749e6dd0aab81b8fe36be5f65878d82f0608e5

See more details on using hashes here.

File details

Details for the file iflow_mcp_dbt_cli_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for iflow_mcp_dbt_cli_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc79d02586d655e05179d1ca09e9fb5d2b9f9ab91bec7386e52d549e824ee600
MD5 3ef93985c85d40f70ef4865d54137b39
BLAKE2b-256 5c185f9484da3a620095488074cbaecdd5746451a9615a28cfc4d07e57ba0dd4

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