
DBT CLI MCP 服务器
概览
一个模型上下文协议(MCP)服务器可以包接dbt CLI工具,使AI编码代理通过标准化的MCP工具与dbt项目交互. - 通过 MCP 工具执行 dbt 命令 - 支持所有主要 dbt 操作(运行,测试,编译等) - 直接交互的命令行接口 - dbt 项目的环境变量管理 - 可配置 dbt 可执行路径 - 灵活配置.yml 位置配置 - Python 3.10或更高 -- -- Python环境管理的uv工具 -- -- dbt CLI已安装 该软件包为直接与 dbt 交互提供了命令行接口: --dbt-path: dbt可执行文件的路径(默认为"dbt") ---env-file:环境文件的路径(默认为".env") ---log-level:日志级别(默认为"INFO") --profiles-dir:包含配置的目录路径.
概述(AI 翻译)
一个模型上下文协议(MCP)服务器可以包接dbt CLI工具,使AI编码代理通过标准化的MCP工具与dbt项目交互.
□ 特性
- 通过 MCP 工具执行 dbt 命令
- 支持所有主要 dbt 操作(运行、测试、编译等)
- 直接互动的命令线接口
- dbt项目的环境可变管理
- 可配置 dbt 可执行路径
- 灵活配置.yml 位置配置
□ 安装
· 先决条件
- Python 3.10 或 更高级
- [T0]用于Python环境管理的工具
- 安装dbt CLI
QQ 设置
□ 使用量
QQ 命令行接口
该软件包为直接与 dbt 交互提供了命令行接口:
您也可以直接使用模块 :
QQ 命令行选项
- [[T1]: dbt 可执行文件的路径( 默认为 “dbt” )
- [[T2]: 环境文件路径( 默认 : “. env”)
- [[T3]: 日志级别( 默认为“ INFO ”)
- [[T4]: 包含 project.yml 文件的目录路径( 如果未指定默认为工程目录)
环境变量
服务器也可以使用环境变量配置:
- [[T5]: dbt 可执行文件的路径
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
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
uvtool 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 executableENV_FILE: Path to environment fileLOG_LEVEL: Logging levelDBT_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 ⚠️
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"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
}
}
}
}