Mcp Grafana

io.github.dockndevai由 GitHub 帳號 dockndevai 發布v0.3.3更新於 Oct 27, 2026

Search & edit Grafana dashboards, query datasources (PromQL/LogQL/SQL), inspect alerts.

已驗證STDIO僅桌面安全與監控資料與分析

概覽

AI 產生的概覽

面向 Grafana 的本機 MCP 伺服器:讓助理搜尋與讀取儀表板、查詢 Prometheus/Loki/SQL 資料來源,並檢視告警與註解。

可以做什麼
  • 檢查執行個體健康狀態與版本
  • 搜尋並列出儀表板與資料夾,讀取儀表板的完整 JSON 模型
  • 列出資料來源,並透過統一查詢介面執行 PromQL、LogQL 或 SQL 查詢
  • 列出 Grafana 管理的告警規則與註解
  • 在讀寫模式下建立或更新儀表板、建立資料夾、寫入註解
  • 在管理員模式並開啟刪除開關後,刪除儀表板、資料夾與註解
適用情境
適合讓助理操作既有的 Grafana 執行個體:尋找儀表板、讀取其 JSON、執行指標或日誌查詢、檢視告警規則,或維護儀表板與註解。預設為唯讀,也適合只想檢視的團隊。
執行需求
透過 npx 從 npm 套件在本機執行。需要 GRAFANA_URL 指向 Grafana 執行個體,並在 GRAFANA_TOKEN 中提供服務帳號權杖,且能連線至該執行個體。GRAFANA_MODE 選擇唯讀(預設)、讀寫或管理員;刪除另需 GRAFANA_ALLOW_DELETE。
安裝前請注意
需要 Grafana 服務帳號權杖,應依最小權限授予(唯讀用 Viewer)。讀寫模式可建立或修改儀表板、資料夾與註解;管理員模式搭配刪除開關可不可逆地刪除它們。可選的資料夾與資料來源允許清單、受保護資料夾、試執行與稽核日誌雖有提供但預設未開啟。回應中會移除資料來源的機密資訊。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Mcp Grafana,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

mcp-grafana

[npm] [CI] [licence]

A safe-by-default Model Context Protocol server for Grafana. It lets an agent explore and operate Grafana — search dashboards, read the dashboard JSON model, list and query datasources (Prometheus / Loki / SQL), inspect alert rules and annotations, and (in higher modes) create/update dashboards and folders, write annotations, and delete.

Part of the dockndevai MCP server suite — one governance model across all of them.

[mcp-grafana — safe by default: read-only exposes 11 tools; raising the access mode unlocks writes and (gated) deletes]

What it gives an agent

The server starts read-only (see Safe by default); higher-capability tools are only registered when you raise the mode.

ToolForNeeds mode
get_healthcheck the instance is up, versionread-only
searchfind dashboards & folders by name/tag (get UIDs)read-only
list_dashboards / list_foldersenumerate dashboards / foldersread-only
get_dashboardthe full dashboard JSON model + metaread-only
list_datasources / get_datasourcedatasources (secrets redacted)read-only
query_datasourcerun PromQL / LogQL / SQL via the unified query APIread-only
list_alert_rulesGrafana-managed alert rulesread-only
list_annotationsevents overlaid on graphsread-only
create_or_update_dashboardupsert a dashboard (versioned, reversible)read-write
create_foldercreate a folderread-write
create_annotationmark a deploy/incident on graphsread-write
delete_dashboard / delete_folder / delete_annotationdelete (irreversible)admin + GRAFANA_ALLOW_DELETE

Install

bash
npx -y @dockndevai/mcp-grafana

You need a Grafana service account token (Administration → Service accounts → Add service account → Add token). Give it the least role that works — Viewer for read-only use, Editor to create/update, Admin only if you must delete.

Configure

json
{  "mcpServers": {    "grafana": {      "command": "npx",      "args": ["-y", "@dockndevai/mcp-grafana"],      "env": {        "GRAFANA_URL": "http://localhost:3000",        "GRAFANA_TOKEN": "glsa_...",        "GRAFANA_MODE": "read-only"      }    }  }}

See docs/CLIENTS.md for Claude Code / Cursor / Codex / VS Code / Windsurf snippets, and .env.example for every supported variable.

Safe by default

The access model is enforced by src/security.ts — defence in depth on top of the service-account token's own role:

  • GRAFANA_MODE — read-only (default) → read-write → admin. A tool is registered only if the mode allows its capability. Read-only exposes the 11 read tools; edits need read-write; deletes need admin.
  • GRAFANA_ALLOW_DELETE — deletes are irreversible, so on top of admin mode they also require this flag.
  • GRAFANA_FOLDER_ALLOWLIST / GRAFANA_PROTECTED_FOLDERS — confine which folders can be written to; mark folders (e.g. production) that may be read but never modified or deleted.
  • GRAFANA_DATASOURCE_ALLOWLIST — restrict which datasources query_datasource may hit.
  • GRAFANA_DRY_RUN — validate and log writes without executing them.
  • GRAFANA_AUDIT_LOG — a JSON audit line per guarded operation, on stderr (default on).
  • Interactive confirmation — when the client supports MCP elicitation, deleting a dashboard/folder/annotation prompts the human to approve before it runs; clients that can't elicit fall back to the GRAFANA_ALLOW_DELETE gate.
  • Secrets are never returned — datasource secureJsonData, passwords and tokens are stripped from every response.

[Interactive confirmation — the agent asks to delete a dashboard; the server pauses and asks the human via MCP elicitation. Declining leaves the dashboard untouched; approving proceeds.]

See SECURITY.md.

Working with dashboards & queries

Conventions for the dashboard JSON model, panel/target shapes, PromQL/LogQL/SQL query patterns, folder organisation and safe editing live in the bundled skill: .claude/skills/grafana-dashboards-and-queries/SKILL.md. Agents that load it can build and edit dashboards to a consistent standard without being re-taught each time.

Developing

bash
npm installnpm run buildGRAFANA_URL=http://localhost:3000 GRAFANA_TOKEN=glsa_… node dist/index.js# introspect without a live Grafana:echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | GRAFANA_TOKEN=x node dist/index.js

Licence

MIT

來源:README.md,提交 3216c7b

工具

11

get_health

Grafana health

Check the Grafana instance is reachable and return its version and database status.

無需輸入參數。

list_dashboards

List dashboards

List dashboards (optionally filtered by tag). Shorthand for search with type=dash-db.

輸入參數taglimit

get_dashboard

Get dashboard

Return the full dashboard JSON model (panels, targets, templating, time) plus meta (folder, version, url) for a dashboard UID. This is the model you edit and pass back to create_or_update_dashboard.

輸入參數uid必填

list_folders

List folders

List dashboard folders with their UIDs and titles.

無需輸入參數。

get_folder

Get folder

Return a folder's details by UID.

輸入參數uid必填

list_datasources

List datasources

List configured datasources (uid, name, type, url). Secrets (secureJsonData, passwords, tokens) are never returned. Use the uid with query_datasource.

無需輸入參數。

get_datasource

Get datasource

Return a single datasource by UID (secrets redacted).

輸入參數uid必填

query_datasource

Query a datasource

Run a query against a datasource through Grafana's unified query API and return the result frames. For Prometheus/Loki set `expr` (PromQL / LogQL); for SQL datasources set `rawSql`. Reading data only — this never mutates anything. Use a bounded time range and a small maxDataPoints to keep results manageable.

輸入參數toexprfromrawSqldatasourceUid必填maxDataPoints

list_alert_rules

List alert rules

List Grafana-managed alert rules (via the provisioning API): title, condition, folder, state.

無需輸入參數。

list_annotations

List annotations

List annotations (events overlaid on graphs), optionally within a time range or by tag.

輸入參數tofromtagslimit

版本歷史

3
  1. v0.3.3最新Oct 26, 2026
  2. v0.3.0Sep 29, 2026
  3. v0.2.3Sep 16, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分