# kannandreams/dbt-mcp-server architecture

> Architecture diagram of the GitHub repository kannandreams/dbt-mcp-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kannandreams/dbt-mcp-server
- Repository: https://github.com/kannandreams/dbt-mcp-server

## Overview

##### Project Type and Purpose
- This is a lightweight, JSON‑driven “MCP (Model Control Protocol) Server” for running dbt models via CLI, HTTP API, or AI clients (e.g. Claude).
- It unifies trigger workflows (dbt commands, tests, etc.) and sends Slack notifications on completion.

##### High‑Level Architecture Components
a. Clients
- CLI client (invokes `mcp_dispatcher.py` with a JSON file)
- HTTP client (e.g. `uvicorn mcp_dispatcher:app`)
- AI client example (`claude_client_example.py`)
b. API / Dispatcher Layer
- FastAPI app in `mcp_dispatcher.py` (serves `/run` endpoint)
- JSON request parser (reads `mcp_request.json`)
- Template loader (`prompt_templates/*.txt` – optional for prompts)
c. Command Definition Store
- `mcp_servers.json` – maps each “mcpServer” key to a command and args
d. Execution Engine
- Subprocess orchestration (spawns `dbt` or node commands per config)
- Environment management (`.python‑version`, `pyproject.toml`, Dockerfile)
e. Notification Service
- Slack webhook integration (`SLACK_WEBHOOK_URL`)
- Sends success/failure alerts
f. External Dependencies
- dbt runtime (assumed installed or containerized)
- Claude or other AI (optional)
- Slack

##### Relationships & Data Flow
1. Client sends JSON payload →
2. FastAPI receives HTTP POST (or CLI script loads JSON) →
3. Dispatcher matches payload key against `mcp_servers.json` →
4. Dispatcher spawns corresponding subprocess (e.g., `dbt run`) →
5. On completion, captures exit status/logs →
6. Posts notification to Slack →
7. Returns JSON response to client

##### Architectural Patterns & Principles
- “Plugin” style command mapping via JSON file (`mcp_servers.json`)
- Single‑responsibility: dispatcher handles routing, execution, and notification separately
- External‑service integration abstracted behind a simple interface (Slack webhook)
- Containerization support for environment consistency (Dockerfile)

##### Technologies & Frameworks
- Python + FastAPI + Uvicorn
- JSON for configuration and requests
- Docker for packaging
- Slack Webhooks
- dbt CLI
- Optional AI client integration (Claude)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        CLI["CLI Client"]:::python
        HTTP["HTTP Client"]:::python
        AI["AI Client"]:::python
    end

    %% API / Dispatcher Layer
    subgraph "API / Dispatcher Layer"
        API["FastAPI\n(mcp_dispatcher.py)"]:::python
        JSONParser["JSON Parser\n(mcp_request.json)"]:::config
        Template["Template Loader\n(prompt_templates/)"]:::config
    end

    %% Command Definition Store
    CDS["Command Definition Store\n(mcp_servers.json)"]:::config

    %% Execution Engine
    subgraph "Execution Engine"
        EE["Subprocess Orchestration"]:::python
        Env["Env Config\n(Dockerfile, .python-version, pyproject.toml)"]:::config
    end

    %% Notification Service
    Notif["Notification Service\n(Slack Webhook)"]:::python

    %% External Systems
    subgraph "External Systems"
        DBT["dbt CLI"]:::external
        Slack["Slack"]:::external
        Claude["AI Service"]:::external
    end

    %% Data Flow
    CLI -->|"JSON payload"| API
    HTTP -->|"HTTP POST JSON"| API
    AI -->|"JSON payload"| API
    API -->|reads| JSONParser
    API -->|loads| CDS
    API -->|loads| Template
    API -->|"spawns"| EE
    EE -->|"executes"| DBT
    EE -->|reads| Env
    API -->|"posts webhook"| Notif
    Notif -->|"HTTP POST"| Slack
    API -->|"returns JSON response"| CLI
    API -->|"returns JSON response"| HTTP
    API -->|"returns JSON response"| AI

    %% Click Events
    click CLI "https://github.com/kannandreams/dbt-mcp-server/blob/main/mcp_dispatcher.py"
    click API "https://github.com/kannandreams/dbt-mcp-server/blob/main/mcp_dispatcher.py"
    click AI "https://github.com/kannandreams/dbt-mcp-server/blob/main/claude_client_example.py"
    click JSONParser "https://github.com/kannandreams/dbt-mcp-server/blob/main/mcp_request.json"
    click CDS "https://github.com/kannandreams/dbt-mcp-server/blob/main/mcp_servers.json"
    click Template "https://github.com/kannandreams/dbt-mcp-server/tree/main/prompt_templates/"
    click Notif "https://github.com/kannandreams/dbt-mcp-server/blob/main/mcp_dispatcher.py"

    %% Styles
    classDef python fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef config fill:#FFF5CC,stroke:#D69D00,color:#8A6E00;
    classDef external fill:#DFF0D8,stroke:#3C763D,color:#3C763D;
```
