The dbt MCP server implements the Model Context Protocol to provide tools for interacting with dbt projects. It enables AI agents to access context from your dbt Core, dbt Fusion, and dbt Platform projects, allowing for powerful automations and insights through various built-in tools.
To get started with the dbt MCP server, follow these steps:
Before installing, ensure you have:
Install the dbt MCP server using pip:
pip install dbt-mcp-server
The dbt MCP server provides a range of tools categorized by functionality. Here's how to use them:
The dbt MCP server is designed to be connected to AI agent products like Claude or Cursor. The connection allows these agents to access your dbt project context.
SQL tools help you execute and generate SQL:
# Execute SQL against your data warehouse
response = mcp_client.execute_sql("SELECT * FROM my_table LIMIT 10")
# Generate SQL from natural language
sql_query = mcp_client.text_to_sql("Show me the top 10 customers by revenue")
Access and query your dbt Semantic Layer:
# List available metrics
metrics = mcp_client.list_metrics()
# Query metrics
results = mcp_client.query_metrics(
metrics=["revenue", "customer_count"],
group_by=["country", "month"],
where="country != 'Unknown'"
)
# Get compiled SQL for metrics
sql = mcp_client.get_metrics_compiled_sql(
metrics=["revenue"],
group_by=["country"]
)
Explore your dbt project structure:
# Get all models in your project
models = mcp_client.get_all_models()
# Search your project
search_results = mcp_client.search("customer revenue")
# Get details about a specific model
model_details = mcp_client.get_model_details("customers")
# Examine model lineage
parents = mcp_client.get_model_parents("customer_orders")
children = mcp_client.get_model_children("customer_orders")
Run dbt commands directly:
# Run a model
run_results = mcp_client.run(select=["my_model"])
# Compile your project
compile_results = mcp_client.compile()
# Test your models
test_results = mcp_client.test(select=["my_model"])
Manage dbt jobs:
# List available jobs
jobs = mcp_client.list_jobs()
# Trigger a job run
run_id = mcp_client.trigger_job_run(job_id=123)
# Get job run details
run_details = mcp_client.get_job_run_details(run_id=456)
Generate dbt code automatically:
# Generate YAML for a model
yaml = mcp_client.generate_model_yaml(model_name="customers")
# Generate a source definition
source = mcp_client.generate_source(schema_name="raw_data")
# Generate a staging model
staging_model = mcp_client.generate_staging_model(source_name="raw", table_name="customers")
If you have questions or need support, create a GitHub Issue or join the community Slack in the #tools-dbt-mcp channel at dbt Community Slack.
For more detailed information, refer to the official documentation.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "dbt-mcp" '{"command":"uvx","args":["--env-file","<path-to-.env-file>","dbt-mcp"]}'
See the official Claude Code MCP documentation for more details.
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 > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"dbt-mcp": {
"command": "uvx",
"args": [
"--env-file",
"<path-to-.env-file>",
"dbt-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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"dbt-mcp": {
"command": "uvx",
"args": [
"--env-file",
"<path-to-.env-file>",
"dbt-mcp"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect