0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL環境でdbt-mcpを動かす。

Last updated at Posted at 2025-06-19

3行まとめ

  • WSLからはデフォルトで.envを読み込んでくれないので、exportかsetしておく必要がある。
  • Claude Code Ubuntu 24.04.1 LTS → 動く(ただし日本語NGぽい)
  • Claude Desktop → 2025/06/16 現在jsonエラーで動かない

事前準備

  • dbtのアカウント(今回はdbtCloud)
  • dbtのモデルを作成しておく
  • WSLへClaude Codeはインストールしておく
  • WSLへtaskはインストールしておく

WSL環境へdbt-mcp をインストールする

  • リポジトリをクローンする
git clone https://github.com/dbt-labs/dbt-mcp.git
cd dbt-mcp
.env
    DBT_HOST="cloud.getdbt.com"
    DBT_PROD_ENV_ID="999999"	# Environments PRODのID  Orchestration/Environments/Development のURLから取ってこれます。/environments/(この部分の数字)/settings
    DBT_DEV_ENV_ID="999999"	# Environments DEVのID   Orchestration/Environments/Development のURLから取ってこれます。/environments/(この部分の数字)/settings
    DBT_USER_ID="999999"	# Create Service token したときに忘れずにメモる。
    DBT_TOKEN="dbtu_hogehoge"	# Settings/Users から自分を選択したときのURLから取ってこれます。/users/(この部分の数字)
    DBT_PROJECT_DIR="/home/[username]/path/to/nishimura_semantic_layer_test"	# dbt-mcpのパスにProject名をつける(パスは実在していなくてOK)
    DISABLE_REMOTE="false"
    DISABLE_DBT_CLI="true"

dbt-mcp 起動方法その1

  • 環境変数の設定してから、dbt-mcp を起動する。
export DBT_HOST="cloud.getdbt.com"
export DBT_PROD_ENV_ID="999999"
export DBT_DEV_ENV_ID="999999"
export DBT_USER_ID="999999"
export DBT_TOKEN="dbtu_hogehoge"
export DBT_PROJECT_DIR="/home/[username]/path/to/nishimura_semantic_layer_test"
export DISABLE_DBT_CLI="true"
dbt-mcp

dbt-mcp 起動方法その2

  • set コマンドで読み込ませる
set -a && source .env && set +a && dbt-mcp

起動確認できればOK

$ set -a && source .env && set +a && dbt-mcp
[06/17/25 23:51:01] INFO     Registering semantic layer tools                                               server.py:94
                    INFO     Registering remote tools                                                      server.py:106
[06/17/25 23:51:02] INFO     HTTP Request: GET https://cloud.getdbt.com/api/ai/mcp/tools/list "HTTP/1.1  _client.py:1026
                             200 OK"
                    INFO     Loaded remote tools: text_to_sql, execute_sql                                   tools.py:87
                    INFO     Starting MCP server                                                            server.py:30

WSL Claude Code で起動する

## export してから
$ bash -ic claude dbt-mcp

こんな感じにでてくればOK
(プロンプトが日本語だとエラーになるけど)

$ bash -ic claude dbt-mcp
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                         │
│                                                   │
│   /help for help, /status for your current setup  │
│                                                   │
│   cwd: /mnt/c/kaori/dbt-mcp                       │
╰───────────────────────────────────────────────────╯


 ※ Tip: Use /memory to view and manage Claude memory

> Get a list of dbt models

● I'll help you get a list of dbt models. Let me first examine the codebase to understand how to retrieve this
  information.

● Search(pattern: "models", include: "*.py")…
  ⎿  Found 5 files (ctrl+r to expand)

● Read(get_models.py)…
  ⎿  Read 31 lines (ctrl+r to expand)

● Read(src/dbt_mcp/discovery/tools.py)…
  ⎿  Read 48 lines (ctrl+r to expand)

● Perfect! I can see there's already a script get_models.py that demonstrates how to get dbt models. You can run it
   directly:

● Bash(cd /mnt/c/kaori/dbt-mcp && python get_models.py)…
  ⎿  Found 6 models:
     - dim_customers (model.my_new_project.dim_customers)
     - fct_orders (model.my_new_project.fct_orders)
     - metricflow_time_spine (model.my_new_project.metricflow_time_spine)
     - stg_customers (model.my_new_project.stg_customers)
     - stg_orders (model.my_new_project.stg_orders)
     - stg_payments (model.my_new_project.stg_payments)

● Found 6 dbt models:
  - dim_customers (model.my_new_project.dim_customers)
  - fct_orders (model.my_new_project.fct_orders)
  - metricflow_time_spine (model.my_new_project.metricflow_time_spine)
  - stg_customers (model.my_new_project.stg_customers)
  - stg_orders (model.my_new_project.stg_orders)
  - stg_payments (model.my_new_project.stg_payments)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?