iflow-mcp_niclasolofsson-dbt-core-mcp 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. dbt_core_mcp/__init__.py +18 -0
  2. dbt_core_mcp/__main__.py +436 -0
  3. dbt_core_mcp/context.py +459 -0
  4. dbt_core_mcp/cte_generator.py +601 -0
  5. dbt_core_mcp/dbt/__init__.py +1 -0
  6. dbt_core_mcp/dbt/bridge_runner.py +1361 -0
  7. dbt_core_mcp/dbt/manifest.py +781 -0
  8. dbt_core_mcp/dbt/runner.py +67 -0
  9. dbt_core_mcp/dependencies.py +50 -0
  10. dbt_core_mcp/server.py +381 -0
  11. dbt_core_mcp/tools/__init__.py +77 -0
  12. dbt_core_mcp/tools/analyze_impact.py +78 -0
  13. dbt_core_mcp/tools/build_models.py +190 -0
  14. dbt_core_mcp/tools/demo/__init__.py +1 -0
  15. dbt_core_mcp/tools/demo/hello.html +267 -0
  16. dbt_core_mcp/tools/demo/ui_demo.py +41 -0
  17. dbt_core_mcp/tools/get_column_lineage.py +1988 -0
  18. dbt_core_mcp/tools/get_lineage.py +89 -0
  19. dbt_core_mcp/tools/get_project_info.py +96 -0
  20. dbt_core_mcp/tools/get_resource_info.py +134 -0
  21. dbt_core_mcp/tools/install_deps.py +102 -0
  22. dbt_core_mcp/tools/list_resources.py +84 -0
  23. dbt_core_mcp/tools/load_seeds.py +179 -0
  24. dbt_core_mcp/tools/query_database.py +459 -0
  25. dbt_core_mcp/tools/run_models.py +234 -0
  26. dbt_core_mcp/tools/snapshot_models.py +120 -0
  27. dbt_core_mcp/tools/test_models.py +238 -0
  28. dbt_core_mcp/utils/__init__.py +1 -0
  29. dbt_core_mcp/utils/env_detector.py +186 -0
  30. dbt_core_mcp/utils/process_check.py +130 -0
  31. dbt_core_mcp/utils/tool_utils.py +411 -0
  32. dbt_core_mcp/utils/warehouse_adapter.py +82 -0
  33. dbt_core_mcp/utils/warehouse_databricks.py +297 -0
  34. iflow_mcp_niclasolofsson_dbt_core_mcp-1.7.0.dist-info/METADATA +784 -0
  35. iflow_mcp_niclasolofsson_dbt_core_mcp-1.7.0.dist-info/RECORD +38 -0
  36. iflow_mcp_niclasolofsson_dbt_core_mcp-1.7.0.dist-info/WHEEL +4 -0
  37. iflow_mcp_niclasolofsson_dbt_core_mcp-1.7.0.dist-info/entry_points.txt +2 -0
  38. iflow_mcp_niclasolofsson_dbt_core_mcp-1.7.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,784 @@
1
+ Metadata-Version: 2.4
2
+ Name: iflow-mcp_niclasolofsson-dbt-core-mcp
3
+ Version: 1.7.0
4
+ Summary: DBT Core MCP Server: Interact with DBT projects via Model Context Protocol
5
+ Project-URL: Homepage, https://github.com/NiclasOlofsson/dbt-core-mcp
6
+ Project-URL: Repository, https://github.com/NiclasOlofsson/dbt-core-mcp
7
+ Project-URL: Issues, https://github.com/NiclasOlofsson/dbt-core-mcp/issues
8
+ Project-URL: Documentation, https://github.com/NiclasOlofsson/dbt-core-mcp#readme
9
+ Author-email: Niclas Olofsson <nicke.olofsson@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: analytics,data,dbt,dbt-core,mcp
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: fastmcp>=3.0.0b1
22
+ Requires-Dist: mcp>=1.12.0
23
+ Requires-Dist: psutil==7.2.1
24
+ Requires-Dist: pydantic>=2.0.0
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: requests>=2.28.0
27
+ Requires-Dist: sqlglot>=25.0.0
28
+ Requires-Dist: typing-extensions
29
+ Requires-Dist: watchfiles>=0.20.0
30
+ Description-Content-Type: text/markdown
31
+
32
+ # dbt Core MCP Server
33
+
34
+ [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=dbtcore&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22dbt-core-mcp%22%5D%7D)
35
+ [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install_Server-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=dbtcore&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22dbt-core-mcp%22%5D%7D&quality=insiders)
36
+ &nbsp;&nbsp;&nbsp;&nbsp;[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
38
+ [![dbt 1.9.0+](https://img.shields.io/badge/dbt-1.9.0+-orange.svg)](https://docs.getdbt.com/)
39
+
40
+ Meet your new dbt pair programmer - the one who actually understands your environment, respects your workflow, and does the heavy lifting.
41
+
42
+ ## Why This Changes Everything
43
+
44
+ If you've tried other dbt tools with Copilot (dbt power user, datamate, etc.), you know the pain:
45
+ - They don't respect your Python environment
46
+ - They can't see your actual project structure
47
+ - They fail when adapters are missing from THEIR environment
48
+ - You end up doing the work yourself anyway
49
+
50
+ **dbt-core-mcp is different.** It's not just another plugin - it's a true pair programming partner that:
51
+
52
+ - **Zero dbt Dependencies**: Our server needs NO dbt-core, NO adapters - works with YOUR environment
53
+ - **Stays in Flow**: Keep the conversation going with Copilot while it handles dbt commands, runs tests, and analyzes impact
54
+ - **Respects Your Environment**: Detects and uses YOUR exact dbt version, YOUR adapter, YOUR Python setup (uv, poetry, venv, conda)
55
+ - **Actually Helps**: Instead of generic suggestions, you get real work done - "run my changes and test downstream" actually does it
56
+ - **Knows Your Project**: Full access to your models, lineage, sources, and compiled SQL - no guessing, no manual lookups
57
+
58
+ &nbsp;
59
+ >&nbsp;
60
+ >**Before dbt-core-mcp**
61
+ >You: *"Copilot, help me understand what depends on stg_orders"*
62
+ >Copilot: *"You should check the manifest.json or run dbt list..."*
63
+ >You: *Switches to terminal, runs commands, copies output back...*
64
+ >
65
+ >**With dbt-core-mcp**
66
+ >You: *"What depends on stg_orders?"*
67
+ >Copilot: *Shows full lineage, impact analysis, and affected models instantly*
68
+ >You: *"Run my changes and test everything downstream"*
69
+ >Copilot: *Does it. Reports results. You focus on the next step.*
70
+ >&nbsp;
71
+
72
+ **This is pair programming the way it should be** - you focus on the logic, Copilot handles the execution. No context switching, no terminal juggling, just flow.
73
+
74
+ ## What You Get (Features & Benefits)
75
+
76
+ - **🔥 Zero dbt Dependencies**: Server has NO dbt-core, NO adapters - ultimate environment respect
77
+ - **Natural Language Control**: Just talk - "run my changes and test downstream" actually works
78
+ - **Bridge Execution**: Automatically detects YOUR environment and runs dbt with YOUR versions
79
+ - **Works with ANY Adapter**: duckdb, snowflake, postgres, bigquery, databricks - if you have it, we work with it
80
+ - **Smart Selection**: Automatic change detection - run only what changed, or changed + downstream
81
+ - **Full Project Awareness**: Lineage analysis, impact assessment, compiled SQL - instant access to everything
82
+ - **Peek Inside CTEs**: Query individual CTEs inside any model to see intermediate results, debug transformations, and design realistic fixtures
83
+ - **True Pair Programming**: Stay in conversation with Copilot while it executes dbt commands and reports results
84
+ - **Schema Change Detection**: Automatically detects column changes and recommends downstream updates
85
+ - **No Configuration Needed**: Works with your existing dbt setup - any adapter, any database, any version
86
+ - **Concurrency Safe**: Detects and waits for existing dbt processes to prevent conflicts
87
+
88
+ This server provides tools to interact with dbt projects via the Model Context Protocol, enabling AI assistants to:
89
+ - Query dbt project metadata and configuration
90
+ - Get detailed model and source information with full manifest metadata
91
+ - Execute SQL queries with Jinja templating support ({{ ref() }}, {{ source() }})
92
+ - Inspect models, sources, and tests
93
+ - Access dbt documentation and lineage
94
+
95
+ ### Natural Language, Powerful Results
96
+
97
+ Just talk to Copilot naturally - no need to memorize commands or syntax:
98
+
99
+ >&nbsp;
100
+ >**Explore your project**
101
+ >You: *"What models do we have in this project?"*
102
+ >Copilot: *Shows all models with materialization types and tags*
103
+ >
104
+ >**Understand dependencies**
105
+ >You: *"Show me what the customers model depends on"*
106
+ >Copilot: *Displays full lineage with upstream sources and models*
107
+ >
108
+ >**Run smart builds**
109
+ >You: *"Run only the models I changed and test everything downstream"*
110
+ >Copilot: *Executes dbt with smart selection, runs tests, reports results*
111
+ >&nbsp;
112
+
113
+ ## Get It Running (2 Minutes)
114
+
115
+ *If you don't have Python installed, get it at [python.org/downloads](https://www.python.org/downloads/) - you'll need Python 3.9 or higher.*
116
+
117
+ *Don't have `uv` yet? Install it with: `pip install uv` or see [docs.astral.sh/uv](https://docs.astral.sh/uv/getting-started/installation/)*
118
+
119
+ ### Option 1: One-Click Install (Easiest)
120
+
121
+ Click the badge for your VS Code version:
122
+
123
+ [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=dbtcore&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22dbt-core-mcp%22%5D%7D)
124
+ [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install_Server-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=dbtcore&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22dbt-core-mcp%22%5D%7D&quality=insiders)
125
+
126
+ That's it! The server will automatically start when you open a dbt project.
127
+
128
+ ### Option 2: Manual Configuration
129
+
130
+ Add this to your `.vscode/mcp.json` file in your dbt project workspace:
131
+
132
+ ```json
133
+ {
134
+ "servers": {
135
+ "dbt-core": {
136
+ "command": "uvx",
137
+ "args": ["dbt-core-mcp"]
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ Or if you prefer `pipx`:
144
+
145
+ ```json
146
+ {
147
+ "servers": {
148
+ "dbt-core": {
149
+ "command": "pipx",
150
+ "args": ["run", "dbt-core-mcp"]
151
+ }
152
+ }
153
+ }
154
+ ```
155
+
156
+ The server will automatically use your workspace directory as the dbt project location.
157
+
158
+ ### Option 3: Bleeding Edge (Latest from GitHub)
159
+
160
+ For the impatient who want the latest features immediately:
161
+
162
+ **With `uvx`:**
163
+ ```json
164
+ {
165
+ "servers": {
166
+ "dbt-core": {
167
+ "command": "uvx",
168
+ "args": [
169
+ "--from",
170
+ "git+https://github.com/NiclasOlofsson/dbt-core-mcp.git",
171
+ "dbt-core-mcp"
172
+ ]
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ **With `pipx`:**
179
+ ```json
180
+ {
181
+ "servers": {
182
+ "dbt-core": {
183
+ "command": "pipx",
184
+ "args": [
185
+ "run",
186
+ "--no-cache",
187
+ "--spec",
188
+ "git+https://github.com/NiclasOlofsson/dbt-core-mcp.git",
189
+ "dbt-core-mcp"
190
+ ]
191
+ }
192
+ }
193
+ }
194
+ ```
195
+
196
+ **Getting Updates:**
197
+ When using git installation, `uvx` and `pipx` cache the downloaded code. To get the latest changes:
198
+
199
+ ```bash
200
+ # For uvx users
201
+ uv cache clean dbt-core-mcp
202
+
203
+ # For pipx users (--no-cache prevents caching)
204
+ # Already configured in the pipx setup above
205
+ ```
206
+
207
+ After cleaning the cache, restart VS Code or your MCP client to pick up the latest version.
208
+
209
+ ### Optional Configuration
210
+
211
+ #### Command Timeout
212
+
213
+ By default, dbt commands have no timeout (they can run as long as needed). For complex models that take a long time to compile, you can set a timeout or explicitly disable it:
214
+
215
+ ```json
216
+ {
217
+ "servers": {
218
+ "dbt-core": {
219
+ "command": "uvx",
220
+ "args": [
221
+ "dbt-core-mcp",
222
+ "--dbt-command-timeout", "300" // 5 minutes, or use 0 for no timeout (default)
223
+ ]
224
+ }
225
+ }
226
+ }
227
+ ```
228
+
229
+ #### Project Directory
230
+
231
+ The server automatically detects your dbt project from the workspace root. If your dbt project is in a subdirectory or you need to specify a different location, use `--project-dir` with either a relative or absolute path:
232
+
233
+ ```json
234
+ {
235
+ "servers": {
236
+ "dbt-core": {
237
+ "command": "uvx",
238
+ "args": [
239
+ "dbt-core-mcp",
240
+ "--project-dir", "path/to/dbt/project" // relative or absolute path
241
+ ]
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ ## Requirements
248
+
249
+ **For the MCP Server:**
250
+ - Python 3.9 or higher
251
+ - NO dbt-core required, NO adapters required - just install `dbt-core-mcp`
252
+
253
+ **For Your dbt Project:**
254
+ - dbt Core 1.9.0 or higher
255
+ - Any dbt adapter (dbt-duckdb, dbt-postgres, dbt-snowflake, dbt-databricks, etc.)
256
+
257
+ The server automatically detects and uses YOUR project's dbt installation via bridge execution.
258
+
259
+ ## Limitations
260
+
261
+ - **Python models**: Not currently supported. Only SQL-based dbt models are supported at this time.
262
+ - **dbt Version**: Requires dbt Core 1.9.0 or higher
263
+
264
+ ## Available Tools
265
+
266
+ **Don't worry about memorizing these** - you don't need to know tool names or parameters. Just talk naturally to Copilot and it figures out what to use. This reference is here for the curious who want to understand what's happening under the hood.
267
+
268
+ **Pro tip:** Focus on the conversational examples (You: / Copilot:) - they show how to actually use these tools in practice.
269
+
270
+ ### Project Information
271
+
272
+ #### `get_project_info`
273
+ Get basic information about your dbt project including name, version, adapter type, and resource counts. By default, also runs `dbt debug` to validate your environment and test the database connection.
274
+
275
+ >&nbsp;
276
+ >You: *"What dbt version is this project using?"*
277
+ >Copilot: *Shows project info with dbt version, adapter type, and connection status*
278
+ >
279
+ >You: *"How many models and sources are in this project?"*
280
+ >Copilot: *Displays counts and project overview with diagnostics*
281
+ >
282
+ >You: *"Is my database connection working?"*
283
+ >Copilot: *Shows connection test results from dbt debug*
284
+ >
285
+ >You: *"Check my dbt setup"*
286
+ >Copilot: *Runs full environment validation and reports any issues*
287
+ >&nbsp;
288
+
289
+ **Parameters:**
290
+ - `run_debug`: Run `dbt debug` to validate environment and test connection (default: True)
291
+
292
+ **Returns:** Project metadata plus diagnostic results including:
293
+ - Database connection status (ok/failed/unknown)
294
+ - Environment validation output
295
+ - System and dependency checks
296
+
297
+ **Note:** Set `run_debug=False` to skip diagnostics and get only basic project info (faster for repeated queries).
298
+
299
+ ### Resource Discovery (Unified Tools)
300
+
301
+ **One tool, all resource types** - these unified tools work across models, sources, seeds, snapshots, and tests. No need for separate tools for each type.
302
+
303
+ #### `list_resources`
304
+ List all resources in your project, or filter by type (models, sources, seeds, snapshots, tests).
305
+
306
+ >&nbsp;
307
+ >You: *"Show me all resources in this project"*
308
+ >Copilot: *Lists all models, sources, seeds, snapshots, and tests*
309
+ >
310
+ >You: *"What models do we have?"*
311
+ >Copilot: *Filters to show only models with their materialization types*
312
+ >
313
+ >You: *"List all data sources"*
314
+ >Copilot: *Shows configured sources with schemas and descriptions*
315
+ >
316
+ >You: *"Show me the seeds"*
317
+ >Copilot: *Displays CSV seed files available in the project*
318
+ >
319
+ >You: *"Which models are materialized as tables?"*
320
+ >Copilot: *Filters models by materialization type*
321
+ >&nbsp;
322
+
323
+ **Parameters:**
324
+ - `resource_type`: Optional filter - `"model"`, `"source"`, `"seed"`, `"snapshot"`, `"test"`, or `None` for all
325
+
326
+ **Returns:** Consistent structure for all types with common fields (name, description, tags) plus type-specific details (materialization, source_name, etc.)
327
+
328
+ #### `get_resource_info`
329
+ Get detailed information about any resource - works for models, sources, seeds, snapshots, and tests.
330
+
331
+ >&nbsp;
332
+ >You: *"Show me details about the customers model"*
333
+ >Copilot: *Displays full model metadata, config, column information, and compiled SQL*
334
+ >
335
+ >You: *"What's in the raw_customers source?"*
336
+ >Copilot: *Shows source schema, columns, and freshness configuration*
337
+ >
338
+ >You: *"Describe the country_codes seed"*
339
+ >Copilot: *Returns seed configuration and column definitions*
340
+ >
341
+ >You: *"What columns does the orders model have?"*
342
+ >Copilot: *Shows column names, types, and descriptions from database*
343
+ >
344
+ >You: *"Show me the compiled SQL for customers"*
345
+ >Copilot: *Returns model info with compiled SQL (all Jinja resolved)*
346
+ >
347
+ >You: *"Tell me about the customer_snapshot"*
348
+ >Copilot: *Displays snapshot configuration and SCD tracking setup*
349
+ >&nbsp;
350
+
351
+ **Parameters:**
352
+ - `name`: Resource name (e.g., "customers", "jaffle_shop.raw_orders")
353
+ - `resource_type`: Optional - auto-detects if not specified
354
+ - `include_database_schema`: Include actual column types from database (default: true)
355
+ - `include_compiled_sql`: Include compiled SQL with Jinja resolved (default: true, models only)
356
+
357
+ **Auto-detection:** Just provide the name - the tool automatically finds it whether it's a model, source, seed, snapshot, or test. For sources, use `"source_name.table_name"` format or just the table name.
358
+
359
+ **Compiled SQL:** For models, automatically includes compiled SQL with all `{{ ref() }}` and `{{ source() }}` resolved to actual table names. Will trigger `dbt compile` if not already compiled. Set `include_compiled_sql=False` to skip compilation.
360
+
361
+ ### Lineage & Impact Analysis (Unified Tools)
362
+
363
+ **Understand relationships across all resource types** - analyze dependencies and impact for models, sources, seeds, snapshots, and tests.
364
+
365
+ #### `get_lineage`
366
+ Trace dependency relationships for any resource - shows what it depends on (upstream) and what depends on it (downstream).
367
+
368
+ >&nbsp;
369
+ >You: *"Show me the lineage for the customers model"*
370
+ >Copilot: *Displays full dependency tree with upstream sources and downstream models*
371
+ >
372
+ >You: *"What does stg_orders depend on?"*
373
+ >Copilot: *Shows upstream dependencies (sources and parent models)*
374
+ >
375
+ >You: *"What's downstream from the raw_customers source?"*
376
+ >Copilot: *Shows all models that use this source*
377
+ >
378
+ >You: *"Where does the revenue model get its data from?"*
379
+ >Copilot: *Displays upstream lineage with all source data*
380
+ >
381
+ >You: *"Show me everything that uses the country_codes seed"*
382
+ >Copilot: *Lists all downstream models that reference this seed*
383
+ >&nbsp;
384
+
385
+ **Parameters:**
386
+ - `name`: Resource name (works for models, sources, seeds, snapshots, tests)
387
+ - `direction`: `"upstream"` (sources), `"downstream"` (dependents), or `"both"` (default)
388
+ - `depth`: Maximum levels to traverse (None for unlimited, 1 for immediate, etc.)
389
+ - `resource_type`: Optional - auto-detects if not specified
390
+
391
+ **Returns:** Dependency tree with statistics (upstream_count, downstream_count, total_dependencies)
392
+
393
+ **Use cases:**
394
+ - Understand data flow and relationships
395
+ - Explore where resources get their data
396
+ - See what depends on specific resources
397
+ - Impact analysis before making changes
398
+
399
+ #### `analyze_impact`
400
+ Analyze the blast radius of changing any resource - shows all downstream dependencies that would be affected.
401
+
402
+ >&nbsp;
403
+ >You: *"What's the impact of changing the stg_customers model?"*
404
+ >Copilot: *Shows all downstream models, tests, and affected resources*
405
+ >
406
+ >You: *"If I modify the raw_orders source, what needs to run?"*
407
+ >Copilot: *Lists impacted models grouped by distance with recommended commands*
408
+ >
409
+ >You: *"What breaks if I change the country_codes seed?"*
410
+ >Copilot: *Shows total impact count and affected resources*
411
+ >
412
+ >You: *"How many models depend on this snapshot?"*
413
+ >Copilot: *Displays impact statistics and dependency count*
414
+ >&nbsp;
415
+
416
+ **Parameters:**
417
+ - `name`: Resource name (works for models, sources, seeds, snapshots, tests)
418
+ - `resource_type`: Optional - auto-detects if not specified
419
+
420
+ **Returns:**
421
+ - Affected resources grouped by distance from the changed resource
422
+ - Count of affected tests and other resources
423
+ - Total impact statistics
424
+ - Context-aware recommended dbt commands (e.g., `dbt run -s stg_customers+`)
425
+ - Impact level message (No/Low/Medium/High)
426
+
427
+ **Use cases:**
428
+ - Before refactoring: understand blast radius
429
+ - Planning incremental rollouts
430
+ - Estimating rebuild time after changes
431
+ - Risk assessment for modifications
432
+
433
+ #### `get_column_lineage`
434
+ Trace column-level lineage through SQL transformations - see exactly how columns flow through CTEs, joins, aggregations, and transformations.
435
+
436
+ >&nbsp;
437
+ >You: *"Show me where the revenue column comes from"*
438
+ >Copilot: *Traces upstream through CTEs showing each transformation step*
439
+ >
440
+ >You: *"How does customer_id flow through the customers model?"*
441
+ >Copilot: *Shows CTE chain: final → customer_agg → orders → stg_orders*
442
+ >
443
+ >You: *"What columns use customer_id downstream?"*
444
+ >Copilot: *Displays all downstream models and columns that reference it*
445
+ >
446
+ >You: *"Trace order_total from source to final output"*
447
+ >Copilot: *Shows complete transformation path with CTEs and expressions*
448
+ >
449
+ >You: *"What transformations happen to price in this model?"*
450
+ >Copilot: *Lists each CTE that transforms the column with SQL expressions*
451
+ >&nbsp;
452
+
453
+ **Parameters:**
454
+ - `model_name`: Name of the dbt model to analyze
455
+ - `column_name`: Name of the column to trace
456
+ - `direction`: `"upstream"` (sources), `"downstream"` (usage), or `"both"` (default)
457
+ - `depth`: Maximum levels to traverse (None for unlimited, 1 for immediate, etc.)
458
+
459
+ **Returns:** Column-level dependencies with detailed transformation tracking:
460
+ - **via_ctes**: List of CTE names in transformation order (shows the path through internal CTEs)
461
+ - **transformations**: Detailed transformation at each step (CTE name, column, SQL expression)
462
+ - **dependencies**: Source columns and tables with full qualification
463
+ - **dbt resource mapping**: Links to source models and sources
464
+
465
+ **CTE Transformation Tracking:**
466
+
467
+ The tool tracks how columns flow through Common Table Expressions (CTEs) inside models:
468
+
469
+ ```
470
+ customer_agg.order_count
471
+ └─ via_ctes: ["final", "customer_agg"]
472
+ └─ transformations:
473
+ - CTE: final
474
+ Column: order_count
475
+ Expression: COALESCE(customer_agg.order_count, 0)
476
+ - CTE: customer_agg
477
+ Column: order_count
478
+ Expression: COUNT(orders.order_id)
479
+ ```
480
+
481
+ This shows you:
482
+ - Which CTEs the column passes through (`via_ctes`)
483
+ - Exactly how it's transformed at each step (`transformations`)
484
+ - The SQL expression used at every transformation point
485
+
486
+ **Use cases:**
487
+ - Understand complex SQL transformations step-by-step
488
+ - Debug why a column has unexpected values (trace the transformation chain)
489
+ - Find all sources for a calculated column
490
+ - See downstream usage before renaming columns
491
+ - Document data lineage for compliance/auditing
492
+ - Identify optimization opportunities in CTE chains
493
+
494
+ **Note:** Requires the model to be compiled (`dbt compile`). Uses sqlglot to parse SQL and trace column flows.
495
+
496
+ ### Database Queries
497
+
498
+ #### `query_database`
499
+ Execute SQL queries against your database using dbt's ref() and source() functions. Results can be displayed inline or exported to CSV/TSV files for analysis.
500
+
501
+ >&nbsp;
502
+ >You: *"Show me 10 rows from the customers model"*
503
+ >Copilot: *Executes SELECT * FROM {{ ref('customers') }} LIMIT 10 and displays results*
504
+ >
505
+ >You: *"Show me the customer_agg CTE from customers with order_count > 5"*
506
+ >Copilot: *Extracts just that CTE (with upstream deps), applies your filter, and shows the rows*
507
+ >
508
+ >You: *"Great, use that output to shape my CTE unit test fixtures"*
509
+ >Copilot: *Done. You get realistic input/output examples without running the whole model*
510
+ >
511
+ >You: *"Count the orders in the staging table"*
512
+ >Copilot: *Runs SELECT COUNT(*) and shows the count*
513
+ >
514
+ >You: *"What's the schema of stg_payments?"*
515
+ >Copilot: *Queries column information and displays schema*
516
+ >
517
+ >You: *"Export customers data to CSV for analysis"*
518
+ >Copilot: *Saves query results to a CSV file you can open in Excel*
519
+ >
520
+ >You: *"Save all orders to a TSV file"*
521
+ >Copilot: *Exports data in tab-separated format for import into other tools*
522
+ >
523
+ >You: *"Run the orders_with_flags CTE from customers_enriched sorted by most recent"*
524
+ >Copilot: *Executes just that CTE (includes upstream deps), applies ORDER BY/LIMIT, and shows the slice you need to reason about the logic*
525
+ >
526
+ >You: *"Use that to build a realistic CTE unit test fixture"*
527
+ >Copilot: *Yes—now your fixtures match real shapes and edge cases*
528
+ >&nbsp;
529
+
530
+ **What you can do:**
531
+ - Query any model using `{{ ref('model_name') }}` or source using `{{ source('source_name', 'table_name') }}`
532
+ - Query any **individual CTE** inside a model with `cte_name` + `model_name`, and optionally add `sql` for WHERE/ORDER BY/LIMIT to zoom in on exactly what a step produces
533
+ - Get results displayed directly in the conversation (good for small result sets)
534
+ - Export to CSV or TSV files (perfect for large datasets or further analysis in Excel/other tools)
535
+ - Automatically handles large results without overwhelming the conversation
536
+
537
+ ### Execution Tools
538
+
539
+ #### `run_models`
540
+ Run dbt models with state-based selection for fast development. Requires previous state (from a prior run) to detect modifications.
541
+
542
+ >&nbsp;
543
+ >You: *"Run only the models I changed"*
544
+ >Copilot: *Uses state comparison to detect and run only modified models*
545
+ >
546
+ >You: *"Run my changes and everything downstream"*
547
+ >Copilot: *Runs modified models plus all downstream dependencies*
548
+ >
549
+ >You: *"Run the customers model"*
550
+ >Copilot: *Executes dbt run --select customers*
551
+ >
552
+ >You: *"Build all mart models with a full refresh"*
553
+ >Copilot: *Runs dbt run --select marts.* --full-refresh*
554
+ >
555
+ >You: *"Run modified models and check for schema changes"*
556
+ >Copilot: *Runs models and detects added/removed columns*
557
+ >&nbsp;
558
+
559
+ **State-based selection modes:**
560
+ - `select_state_modified`: Run only models that changed (requires previous state)
561
+ - `select_state_modified_plus_downstream`: Run changed models + everything downstream
562
+
563
+ **How state works:**
564
+ - First run establishes baseline state automatically
565
+ - Subsequent runs compare against this state to detect changes
566
+ - If no previous state exists, returns success (cannot determine modifications)
567
+ - State is saved automatically after each successful run
568
+
569
+ **Other parameters:**
570
+ - `select`: Model selector (e.g., "customers", "tag:mart")
571
+ - `exclude`: Exclude models
572
+ - `full_refresh`: Force full refresh for incremental models
573
+ - `fail_fast`: Stop on first failure
574
+ - `check_schema_changes`: Detect column additions/removals
575
+
576
+ **Schema Change Detection:**
577
+ When enabled, detects added or removed columns and recommends running downstream models to propagate changes.
578
+
579
+ #### `test_models`
580
+ Run dbt tests with state-based selection. Requires previous state to detect modifications.
581
+
582
+ >&nbsp;
583
+ >You: *"Test only the models I changed"*
584
+ >Copilot: *Uses state comparison to test only modified models*
585
+ >
586
+ >You: *"Run tests for my changes and downstream models"*
587
+ >Copilot: *Tests modified models and everything affected downstream*
588
+ >
589
+ >You: *"Test the customers model"*
590
+ >Copilot: *Executes dbt test --select customers*
591
+ >
592
+ >You: *"Run all tests for staging models"*
593
+ >Copilot: *Runs dbt test --select staging.*
594
+ >&nbsp;
595
+
596
+ **State-based selection modes:**
597
+ - `select_state_modified`: Test only changed models (requires previous state)
598
+ - `select_state_modified_plus_downstream`: Test changed models + downstream
599
+ - If no previous state exists, returns success (cannot determine modifications)
600
+
601
+ **Other parameters:**
602
+ - `select`: Test selector (e.g., "customers", "tag:mart")
603
+ - `exclude`: Exclude tests
604
+ - `fail_fast`: Stop on first failure
605
+
606
+ #### `build_models`
607
+ Run models and tests together in dependency order (most efficient approach). Supports state-based selection.
608
+
609
+ >&nbsp;
610
+ >You: *"Build my changes and everything downstream"*
611
+ >Copilot: *Uses state comparison to build modified models and dependencies*
612
+ >
613
+ >You: *"Run and test only what I modified"*
614
+ >Copilot: *Executes dbt build on changed models only*
615
+ >
616
+ >You: *"Build the entire mart layer with tests"*
617
+ >Copilot: *Runs dbt build --select marts.* with all tests*
618
+ >&nbsp;
619
+
620
+ **State-based selection modes:**
621
+ - `select_state_modified`: Build only changed models (requires previous state)
622
+ - `select_state_modified_plus_downstream`: Build changed models + downstream
623
+ - If no previous state exists, returns success (cannot determine modifications)
624
+
625
+ #### `seed_data`
626
+ Load seed data (CSV files) from `seeds/` directory into database tables.
627
+
628
+ >&nbsp;
629
+ >You: *"Load all seed data"*
630
+ >Copilot: *Runs dbt seed and loads all CSV files*
631
+ >
632
+ >You: *"Load only the seeds I changed"*
633
+ >Copilot: *Detects modified seed files and loads them*
634
+ >
635
+ >You: *"Reload the raw_customers seed file"*
636
+ >Copilot: *Executes dbt seed --select raw_customers --full-refresh*
637
+ >
638
+ >You: *"Show me what's in the country_codes seed"*
639
+ >Copilot: *Displays preview of loaded seed data*
640
+ >&nbsp;
641
+
642
+ Seeds are typically used for reference data like country codes, product categories, etc.
643
+
644
+ **State-based selection modes:**
645
+ - `select_state_modified`: Load only seeds that changed (requires previous state)
646
+ - `select_state_modified_plus_downstream`: Load changed seeds + downstream dependencies
647
+ - If no previous state exists, returns success (cannot determine modifications)
648
+
649
+ **Other parameters:**
650
+ - `select`: Seed selector (e.g., "raw_customers", "tag:lookup")
651
+ - `exclude`: Exclude seeds
652
+ - `full_refresh`: Truncate and reload seed tables
653
+ - `show`: Show preview of loaded data
654
+
655
+ **Important:** Change detection works via file hash:
656
+ - Seeds < 1 MiB: Content changes detected ✅
657
+ - Seeds ≥ 1 MiB: Only file path changes detected ⚠️
658
+
659
+ For large seeds, use manual selection or run all seeds.
660
+
661
+ #### `snapshot_models`
662
+ Execute dbt snapshots to capture slowly changing dimensions (SCD Type 2).
663
+
664
+ >&nbsp;
665
+ >You: *"Run all snapshots"*
666
+ >Copilot: *Executes dbt snapshot for all snapshot models*
667
+ >
668
+ >You: *"Execute the customer_history snapshot"*
669
+ >Copilot: *Runs dbt snapshot --select customer_history*
670
+ >
671
+ >You: *"Run daily snapshots"*
672
+ >Copilot: *Executes snapshots tagged with 'daily'*
673
+ >&nbsp;
674
+
675
+ Snapshots track historical changes by recording when records were first seen, when they changed, and their state at each point in time.
676
+
677
+ **Parameters:**
678
+ - `select`: Snapshot selector (e.g., "customer_history", "tag:daily")
679
+ - `exclude`: Exclude snapshots
680
+
681
+ **Note:** Snapshots are time-based and should be run on a schedule (e.g., daily/hourly), not during interactive development. They do not support smart selection.
682
+
683
+ #### `install_deps`
684
+ Install dbt packages defined in packages.yml to enable interactive package management workflow.
685
+
686
+ >&nbsp;
687
+ >You: *"I need to use dbt_utils macros"*
688
+ >Copilot: *Checks if installed, adds to packages.yml, runs install_deps()*
689
+ >
690
+ >You: *"Install the packages defined in packages.yml"*
691
+ >Copilot: *Executes dbt deps and shows installed packages*
692
+ >
693
+ >You: *"Add dbt_utils and install it"*
694
+ >Copilot: *Edits packages.yml, runs install_deps(), ready to use macros*
695
+ >&nbsp;
696
+
697
+ This tool enables a complete workflow where Copilot can:
698
+ 1. Suggest using a dbt package (e.g., dbt_utils)
699
+ 2. Edit packages.yml to add the package
700
+ 3. Run install_deps() to install it
701
+ 4. Write code that uses the package's macros
702
+
703
+ All without breaking conversation flow.
704
+
705
+ **Returns:** Installation status and list of installed packages
706
+
707
+ **Package Discovery:**
708
+ Use `list_resources(type="macro")` to see which packages are already installed.
709
+ Macros follow the pattern `macro.{package_name}.{macro_name}`.
710
+
711
+ **Note:** This is an interactive development tool (like run_models/test_models), not infrastructure automation. It enables Copilot to complete its own recommendations mid-conversation.
712
+
713
+ ## Developer Workflow
714
+
715
+ Fast iteration with smart selection - just describe what you want:
716
+
717
+ >&nbsp;
718
+ >You: *"Run only what I changed"*
719
+ >Copilot: *Detects modified models and runs them*
720
+ >
721
+ >You: *"Run my changes and test everything downstream"*
722
+ >Copilot: *Runs modified models + downstream dependencies, then tests*
723
+ >
724
+ >You: *"Build my modified models with tests"*
725
+ >Copilot: *Executes dbt build with smart selection*
726
+ >&nbsp;
727
+
728
+ The first run establishes a baseline state automatically. Subsequent runs detect changes and run only what's needed.
729
+
730
+ **Before-and-After Example:**
731
+
732
+ >&nbsp;
733
+ >**Traditional workflow:**
734
+ >```bash
735
+ >dbt run --select customers+
736
+ >dbt test --select customers+
737
+ >```
738
+ >
739
+ >**With dbt-core-mcp:**
740
+ >You: *"I modified the customers model, run it and test everything affected"*
741
+ >Copilot: *Handles everything - runs, tests, and reports results*
742
+ >&nbsp;
743
+
744
+ ## How It Works
745
+
746
+ This server executes dbt commands in your project's Python environment using a bridge execution pattern:
747
+
748
+ 1. **Zero dbt Dependencies**: MCP server requires NO dbt-core, NO adapters - just Python utilities
749
+ 2. **Environment Detection**: Automatically finds your Python environment (uv, poetry, venv, conda, etc.)
750
+ 3. **Bridge Execution**: Builds Python scripts as strings and executes them in YOUR environment
751
+ 4. **Uses YOUR dbt**: Runs with YOUR dbt-core version, YOUR adapters, YOUR configuration
752
+ 5. **No Conflicts**: Can't have version conflicts when we don't have dbt dependencies!
753
+ 6. **Concurrency Safety**: Detects and waits for existing dbt processes to prevent database lock conflicts
754
+
755
+ The server reads dbt's manifest.json for metadata and uses `dbt show --inline` (executed in YOUR environment) for SQL query execution with full Jinja templating support.
756
+
757
+ **In practice:**
758
+
759
+ >&nbsp;
760
+ >**Your project:** dbt-core 1.10.13 + dbt-duckdb
761
+ >**Our server:** mcp, fastmcp, pydantic, pyyaml, psutil (no dbt!)
762
+ >**Result:** Perfect compatibility - we detect your environment and run YOUR dbt
763
+ >&nbsp;
764
+
765
+ No configuration needed - it just works with your existing dbt setup, any version, any adapter.
766
+
767
+ ## Contributing
768
+
769
+ Want to help make this better? **The best contribution you can make is actually using it** - your feedback and bug reports are what really drive improvements.
770
+
771
+ Of course, code contributions are welcome too! Check out [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines. But seriously, just using it and telling us what works (or doesn't) is incredibly valuable.
772
+
773
+ ## Learn More
774
+
775
+ - **[Technical Architecture](TECHNICAL.md)** - Deep dive into zero-config philosophy, bridge architecture, performance optimizations, and design decisions. For the curious who want to understand how it all works under the hood.
776
+ - **[CTE Unit Testing](CTE-UNIT-TESTING.md)** - Comprehensive guide to testing SQL CTEs in isolation. Learn how to test complex SQL logic without building massive fixtures, enabling true TDD workflows for dbt models.
777
+
778
+ ## License
779
+
780
+ MIT License - see LICENSE file for details.
781
+
782
+ ## Author
783
+
784
+ Niclas Olofsson - [GitHub](https://github.com/NiclasOlofsson)