DBT CLI MCP Server is a tool that enables AI coding agents to interact with dbt projects through standardized Model Context Protocol (MCP) tools. It wraps the dbt CLI, allowing you to execute dbt commands, manage environment variables, and configure various dbt operations.
uv
tool for Python environment management# 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]"
You can interact with dbt directly through the command line:
# 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
--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)Configure the server using environment variables:
DBT_PATH
: Path to dbt executableENV_FILE
: Path to environment fileLOG_LEVEL
: Logging levelDBT_PROFILES_DIR
: Path to directory containing profiles.yml fileTo use the server with an MCP client like Claude for Desktop:
{
"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
}
}
}
}
The server provides these 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
)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.
// ❌ INCORRECT - Will NOT work
{
"project_dir": "."
}
// ✅ CORRECT - Will work
{
"project_dir": "/Users/username/path/to/your/dbt/project"
}
When using the dbt MCP tools, it's important to understand how dbt profiles are handled:
The project_dir
parameter MUST be an absolute path that points to a directory containing both:
dbt_project.yml
fileprofiles.yml
file with the profile referenced in the projectThe MCP server automatically sets the DBT_PROFILES_DIR
environment variable to the absolute path of the directory specified in project_dir
.
If you encounter a "Could not find profile named 'X'" error, it means either:
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
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.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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.
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.