MCP Server Integration
Documents how to set up and use an MCP server that exposes dbt-toolbox's caching, validation, and build commands to AI assistants and IDEs.
What this file does
Documents how to set up and use an MCP server that exposes dbt-toolbox's caching, validation, and build commands to AI assistants and IDEs.
When to use it
- You want Claude Code or Copilot to run dbt-toolbox commands
- You need an AI assistant to validate and build dbt models
- You are integrating dbt-toolbox into an MCP-compatible editor
- You want to expose dbt-toolbox functionality through a standardized protocol
Assumes this stack
MCP Server Integration
dbt-toolbox provides an MCP (Model Context Protocol) server implementation, enabling integration with AI assistants and external tools. This allows you to leverage dbt-toolbox's intelligent caching, dependency analysis, and validation capabilities from within other applications.
🚀 Quick Start
Installation
# Install dbt-toolbox with MCP support
uv add "dbt-toolbox[mcp]"
# Or with pip
pip install "dbt-toolbox[mcp]"
Claude CLI
Set it up in claude by running:
claude mcp add dbt-toolbox -- uv run dt start-mcp-server
VSCode Copilot
Set it up in Copilot by adding the following to your .vscode/mcp.json and click "start":
{
"servers": {
"dbt-toolbox": {
"type": "stdio",
"command": "uv",
"args": [
"run",
"dt",
"start-mcp-server",
]
}
}
}
Basic Usage
The MCP server exposes dbt-toolbox functionality through standardized MCP tools that can be called by MCP clients like Claude Code, Copilot, and other AI development tools.
# The server is accessible via the FastMCP app
# Location: dbt_toolbox.mcp.mcp:app
🛠️ Available Tools
analyze_models()
Validates all model references, column references, and CTE references in your dbt project.
Purpose: Ensures data lineage integrity and catches broken references before execution.
Returns: JSON object with validation results
Key Features:
- Validates column existence across model dependencies
- Checks CTE reference integrity
- Identifies non-existent table references
- Respects validation ignore lists from configuration
build_models()
Executes dbt build with intelligent cache-based execution and enhanced capabilities.
Parameters:
model(str, optional): Select models to build (dbt selection syntax)full_refresh(bool, default=False): Drop incremental models and rebuildthreads(int, optional): Number of threads to usevars(str, optional): Supply variables to the project (YAML string)target(str, optional): Specify dbt target environmentanalyze_only(bool, default=False): Only analyze which models need executiondisable_smart(bool, default=False): Disable intelligent execution
Returns: JSON object with execution results and performance metrics
Smart Execution Features:
- Cache Analysis: Only rebuilds models with outdated cache or dependency changes
- Lineage Validation: Validates column and model references before execution
- Performance Tracking: Reports time saved by skipping unnecessary model executions
- Optimized Selection: Automatically filters to models that need execution
🔧 Configuration
The MCP server respects the same configuration system as the CLI commands:
Configuration Sources (by precedence):
- Environment Variables (highest priority)
- TOML Configuration (
pyproject.toml) - dbt Profiles (for SQL dialect and connection)
- Auto-detection (for project paths)
- Defaults (lowest priority)
Key Settings for MCP Usage
[tool.dbt_toolbox]
# Core settings
dbt_project_dir = "path/to/your/dbt/project"
cache_path = ".dbt_toolbox"
cache_validity_minutes = 1440 # 24 hours
# Validation settings
enforce_lineage_validation = true
models_ignore_validation = ["legacy_model", "temp_model"]
# Performance settings
debug = false
Environment Variables
# Project configuration
export DBT_PROJECT_DIR="/path/to/dbt/project"
export DBT_PROFILES_DIR="/path/to/profiles"
# dbt-toolbox specific
export DBT_TOOLBOX_ENFORCE_LINEAGE_VALIDATION=true
export DBT_TOOLBOX_MODELS_IGNORE_VALIDATION="legacy_model,temp_model"
export DBT_TOOLBOX_CACHE_VALIDITY_MINUTES=1440
export DBT_TOOLBOX_DEBUG=false
🏗️ Integration Patterns
AI Assistant Integration
Perfect for AI-powered dbt development workflows:
- Pre-execution Validation: Always run
analyze_models()before making changes - Intelligent Builds: Use
build_models()with smart execution for faster iterations - Impact Analysis: Use selection syntax like
+model+to understand dependencies - Performance Monitoring: Track skipped models and time savings
Development Tools Integration
Enable dbt-toolbox in your development environment:
- IDE Extensions: MCP-compatible editors can call tools directly
- CLI Wrappers: Create custom scripts that leverage MCP tools
- Notebooks: Use MCP tools in Jupyter notebooks for exploratory analysis
🔍 Troubleshooting
Common Issues
Connection Errors:
- Ensure dbt profiles are configured correctly
- Check
DBT_PROFILES_DIRenvironment variable - Verify target exists in profiles.yml
Validation Failures:
- Review models listed in validation results
- Add problematic models to
models_ignore_validation - Check for missing sources or macros
Performance Issues:
- Increase
cache_validity_minutesfor longer cache retention - Use targeted model selection instead of full project builds
- Check
debug=trueto understand cache behavior
📊 Benefits
Development Efficiency
- Faster Iterations: Smart caching eliminates unnecessary model rebuilds
- Early Error Detection: Validation catches issues before expensive builds
- Performance Insights: Clear metrics on time saved and models skipped
Code Quality
- Lineage Validation: Ensures data integrity across model dependencies
- Reference Checking: Catches broken table and column references
- CTE Validation: Validates complex SQL patterns and Common Table Expressions
Integration Flexibility
- Standardized Protocol: MCP enables consistent tool integration
- AI-Powered Workflows: Perfect for AI assistant development patterns
- Configuration Consistency: Same settings as CLI commands
🤝 Contributing
The MCP server is part of the main dbt-toolbox codebase. See the main Contributing Guide for development setup and guidelines.
MCP-Specific Development
When working on MCP functionality:
- Consistency: Ensure MCP tools provide same functionality as CLI commands
- Error Handling: Return structured JSON responses for all scenarios
- Documentation: Keep tool docstrings comprehensive for AI assistants
- Testing: Test both CLI and MCP interfaces for feature parity
📚 Additional Resources
What's inside
Quick start, 2 tool descriptions, configuration section, integration patterns, troubleshooting, benefits, contributing notes, and 4 resource links.
Change this for your project
- Replace
erikmunkby/dbt-toolboxwith your own repository URL in the contributing and resource links - Replace
dbt-toolboxwith your package name in the install commands and MCP server name - Replace
dtwith your CLI entry point name in theclaude mcp addandargscommands
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Exposing CLI functionality as MCP tools so AI assistants can call them directly
- Using environment variables and TOML config with the same precedence as CLI commands
Related Documents
WAVS MCP Server
Exposes WAVS platform operations as MCP tools for AI clients, enabling natural-language node queries, component scaffolding, deployment, and simulation.
一次性多版本
Documents setup, build commands, and MCP server tools for the ChYing security testing application.
Heti AI Ökoszisztéma Figyelő
Summarises 23 signals from GitHub and external sources into a weekly AI ecosystem watch with recommendations for the Brunella project.
Datalevin MCP Server
Runs a local Datalevin MCP server over stdio, exposing read-only or read-write database tools to any MCP-compliant client.