2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TradingView MCP: Windows + WSL2 環境向けセットアップ手順

2
Last updated at Posted at 2026-04-18

TradingView MCP セットアップ手順メモ

(訂正): 設定手順の順番に誤りがあったのと、ポート番号が競合する場合があったので、手順を修正しました。TradingView.exe を 49222 番ポートでデバッグ起動し、その後にポートプロキシ設定を追加します。

WSL2 から Windows ホスト上の TradingView に接続する手順とコマンドのまとめです。
今後、環境を再構築する際などの参考にしてください。

1. TradingView の起動

TradingView Desktop を起動する際、デバッグポートを有効にする必要があります。

:: Windows のショートカットやコマンドプロンプトから
TradingView.exe --remote-debugging-port=49222

(注意) 9222番ポートは指定しないほうが良いでしょう。次のステップで、ポートプロキシ設定をします。そこで、0.0.0.0:9222をLISTENするようにするのですが、ポート競合が発生する場合があります。起動順序が守られていれば競合しないようにもできますが、後々のトラブルの元になります。経験談。

TradingView.exe ファイルの場所が分からなければ、TradingView Desktop を起動し、タスクマネージャーのプロセス一覧から「TradingView」を右クリック、プルダウンから「ファイルの場所を開く」とすれば、パスが分かります。

C:\Program Files\WindowsApps\TradingView.Desktop_3.0.0.7652_x64__n534cwy3pjxzj

2. Windows 側 (PowerShell 管理者として実行)

Windows ホスト側で WSL2 からの 9222 ポートへの通信を受け入れ、それをローカルで実行中の TradingView に転送するための設定です。

1. 外部(WSL2)からの 9222 ポートへの接続を、Windows ローカルの 49222 に転送する

netsh interface portproxy add v4tov4 listenport=9222 listenaddress=0.0.0.0 connectport=49222 connectaddress=127.0.0.1

これで、TradingView リモートデバッグポート (Chrome DevTools Protocol 用) 127.0.0.1:49222 と Windows ホストの 0.0.0.0:9222 が関連付けられる。

2. Windows ファイアウォールで 9222 ポートの受信を許可する

New-NetFirewallRule -DisplayName "TradingView CDP" -Direction Inbound -LocalPort 9222 -Protocol TCP -Action Allow

(確認用) 設定されているか確認するコマンド

netsh interface portproxy show all
Get-NetFirewallRule -DisplayName "TradingView CDP"

3. WSL2 側 (Ubuntu 等)

WSL2 内の localhost:9222 を Windows ホストの IP に橋渡しするための設定です。

必要なパッケージのインストール

sudo apt-get update && sudo apt-get install -y socat

自動起動設定 (~/.bashrc への追記内容)

以下の内容を ~/.bashrc の末尾に追加しました。これにより、新しいターミナルを開くたびに socat がバックグラウンドで起動し、接続を維持します。

# TradingView MCP: Bridge WSL2 localhost:9222 to Windows Host:9222
if ! ss -tunlp | grep -q ":9222 "; then
    # デフォルトゲートウェイ(Windowsホスト)のIPを動的に取得
    WIN_HOST_IP=$(ip route | grep default | awk '{print $3}')
    if [ -n "$WIN_HOST_IP" ]; then
        # WSL2の9222をWindowsの9222へ転送
        socat TCP-LISTEN:9222,fork,reuseaddr TCP:$WIN_HOST_IP:9222 > /dev/null 2>&1 &
    fi
fi

4. 動作確認

1. Windows 側で CDP エンドポイントを確認します。

curl.exe http://127.0.0.1:49222/json/version
curl.exe http://127.0.0.1:49222/json/list

2. WSL 側で CDP エンドポイントを確認します。

curl http://localhost:9222/json/version
curl http://localhost:9222/json/list

2. WSL 側で tv コマンドを確認します。

この状態で、WSL2 から tv status を実行して success: true が返ってくれば、すべての設定が正常に機能しています。

tv status
{
  "success": true,
  "cdp_connected": true,
  "target_id": "********************************",
  "target_url": "https://jp.tradingview.com/chart/********/",
  "target_title": "TradingViewのリアルタイム株価、指数、先物、FX、そしてビットコインチャート",
  "chart_symbol": "********",
  "chart_resolution": "1D",
  "chart_type": 1,
  "api_available": true
}
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?