# 在windows安裝mcp server **環境** * claude dekstop、 mcp server在 windows 上 * grafana 本身在 ubuntu 中 ## (一)安裝go 安裝[Go](https://go.dev/dl/) * go1.24.2.windows-386.msi * 加入PATH - `按下 Win 鍵 → 搜尋「環境變數」 → 選擇「編輯系統環境變數」或「編輯帳戶的環境變數」` - 在下方選擇 Path → 點「編輯」 - 點「新增」:`C:\Program Files(x86)\Go\bin ` ## (二)安裝 mcp-grafana ``` go install github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest ``` * 這會在 %USERPROFILE%\go\bin\ 產生一個 mcp-grafana.exe 可執行檔。 * 找這個路徑確認`C:\Users\你的使用者名稱\go\bin\mcp-grafana.exe` ## (三)安裝 MCP-Host 端 這邊是使用claude desktop ## (四)取得grafana API KEY 在選單部分依序點擊 `Administrator /Users and access / Service accounts /Add service account / Add service account token` * Add service account部分 Roles 選擇 Admin 比較好 * 這個 token 就是 API KEY (`glsa_`開頭的) ## (五)編輯 cluade desktop 設定檔 資料夾:`C:\Users\chenb\AppData\Roaming\Claude` **注意!!!!!** 不是編輯 `config.json` 這個檔案 **操作步驟:** 1. 開啟 Claude Desktop 應用程式。 2. 點擊應用程式左上角的 **☰** (選單圖示)。 3. 在彈出的選單中,依序點擊: * **Settings** * **Developer** * **Edit Config** 4. 此時在資料夾當中就會自動出現 `claude_desktop_config.json` 這個檔案 5. 沒錯,我們就是要編輯這個檔案 --- `claude_desktop_config.json`範例 ``` { "mcpServers": { "grafana": { "command": "cmd", "args": [ "/c", "C:/Users/chenb/go/bin/mcp-debug.bat" ], "env": { "GRAFANA_URL": "http://192.168.14.148:3000", "GRAFANA_API_KEY": "glsa_J8cVdi6o8d9vAMyeJAJ6" } } } } ``` ## (六)除錯 上面args的部分,理論上應該是要執行`"C:/Users/chenb/go/bin/mcp-grafana.exe"` 這個 `mcp-grafana.exe` 才是 grafana mcp server最核心的執行檔 但是直接執行可能會遇到**未正確讀取環境變數(GRAFANA_URL 和 GRAFANA_API_KEY )** 的問題 **解決方式:** 先執行這個 .bat (Batch file)檔案 在 Batch file 除了有重新設定 `GRAFANA_URL`還有`GRAFANA_API_KEY` 同時有增加了 `mcp-debug.bat` 被執行的 logs --- `mcp-debug.bat` 範例 ``` @echo off echo [%DATE% %TIME%] mcp-debug.bat 被 Claude 執行 >> C:\Users\chenb\go\bin\mcp-called.txt set GRAFANA_URL=http://192.168.14.148:3000 set GRAFANA_API_KEY=glsa_J8cVdi6o8d9vAMyeJAJ6 C:\Users\chenb\go\bin\mcp-grafana.exe ``` ## (七)測試 如果在 `mcp-debug.bat` 中有加入 `echo [%DATE% %TIME%] mcp-debug.bat 被 Claude 執行 >> C:\Users\chenb\go\bin\mcp-called.txt` 這段 理論上打開 claude dekstop 就會出現 `mcp-called.txt` 了 接著我們透過claude desktop 來測試 下一個prompt,`幫我讀取grafana中conpot_log最新10筆資料`  * 過程中應該會不斷跟我們要授權  * 成功啦!!!
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up