Grafana MCP server
io.github.itzhouq/grafana-mcp·v0.1.3Read-only project-level Grafana MCP: Loki logs, metrics, traces, alerts, test/prod switching
0 stars704 downloads/wk
Reviews
Write oneNobody has reviewed Grafana MCP yet.
If you have run it, two minutes of your experience saves the next person an afternoon.
Grafana MCP tools (10)
write = sends, deletes, buys or postsRead from the package source without running it. The installed server may list more.
alerts列出当前正在告警的规则(Grafana Alertmanager)。收到 [FIRING:N] 类告警消息后先用它确认现状。
datasources列出当前 Grafana 实例的全部数据源(类型、名称、UID)。
loki_labels查询 Loki 标签名或某标签的全部取值。不带 label 参数 → 列出所有标签名;带 label=app → 返回 app 标签的所有取值(用于确认项目 app 名称在当前环境是否存在,防止查错应用)。
loki_query执行 LogQL 日志查询(range 查询)。
project_context【调查前必调】获取当前项目的 Grafana 上下文:激活环境(test/prod)、项目 App 名称、namespace、数据源 UID、配置来源。
prom_instant执行 PromQL 即时查询(单时间点)。示例:kube_pod_container_status_restarts_total{namespace="prod"}
prom_query执行 PromQL 区间查询。示例:rate(container_cpu_usage_seconds_total{namespace="prod"}[5m])
switch_environment切换 Grafana 环境(仅影响本会话)。环境信息(连接地址、账密、数据源 UID)来自 ~/.zshrc 解析或配置文件,无需手动 export。切换后返回新环境上下文。
tempo_search用 TraceQL 搜索链路追踪。示例:{resource.service.name="api" && status=error}
tempo_trace按 traceID 获取完整链路(span 列表、耗时、状态)。日志中的 traceId=xxx 可直接跟进。
Public scan report
scanner v0.1.10 · 2026-10-13 · same rubric, same numbers if you re-run it
- Code scan3 source files scanned13/25
- –Live reliabilityno gateway calls yet and no remote to proben/a
- –Tool poisoningtools not inspected (local package is not executed); not countedn/a
- Auth qualitystatic API keys via environment variables6/15
- Maintenancelast push 5 days ago15/15
- Maintainer identityregistry namespace matches repository owner; GitHub account older than a year8/10
Findings (1)
- highShell command built from a string (injection risk)
exec.shell-concatindex.ts: …&& item) { try { const json = execSync( `op item get "${item}" --vault "${vault}" --fields user,password --format …
How Grafana MCP compares
Against every graded MCP server, from our own scans and uptime checks. Updated after each scan run.
- Safety score
- 65/100
- higher than 20% of 48,273 servers
- Tools
- 10
- the typical server has 7
- Tools that change things
- 0%
- typical: 0%. Fewer write tools means less an agent can break
- Downloads a week
- 704
- more than 92% of 11,915 servers with a package
What its tools let an agent do: 10 read
Install Grafana MCP in Claude Code, Cursor or VS Code
Runs npx -y grafana-mcp on your machine. Read the scan report first; the gateway never runs local packages.
claude mcp add grafana-mcp -- npx -y grafana-mcp
What the publisher says
From the Grafana MCP repository's README, as published. We do not edit it. Read it on GitHub
grafana-mcp
Project-level Grafana MCP server — give your AI coding agent read-only access to Loki logs, Prometheus metrics, Tempo traces and alerts, with per-project context and test/prod environment switching. 零依赖单文件 TypeScript,bun 直接运行。
AI 编码 Agent(Claude Code / Cursor / …)
│ MCP (stdio)
▼
grafana-mcp ──读──▶ .mcp.json env / .grafana.json / ~/.zshrc(凭据与项目上下文)
│ HTTP(只读查询 API)
▼
Grafana ──▶ Loki(日志)/ Prometheus(指标)/ Tempo(链路)/ Alerts(告警)它解决什么问题
日常迭代业务系统时,测试阶段要快速定位 QA 反馈的问题,线上要快速排查功能 bug 与性能瓶颈——这些证据都在 Grafana 体系里(Loki 日志、Prometheus 指标、Tempo 链路)。让 agent 在写代码、修 bug 的同时能直接查到这些上下文,问题定位的效率和准确性会明显提升。但直接用通用 MCP 封装 Grafana API 会遇到三个实际障碍:
声明
- 非官方项目:本仓库与 Grafana Labs 无隶属关系;Grafana、Loki、Prometheus、Tempo 是各自所有方的商标。
- 免责:软件按"现状"提供。使用者需自行确保对目标 Grafana 实例的访问已获授权,并遵守所在组织的数据安全与审计规定;日志与指标输出可能包含业务敏感信息,分享查询结果前请自行判断合规边界。作者不对违规使用及其后果负责。
- 只读边界:全部 10 个工具均为查询类,不含任何写操作。建议为 agent 配置 Viewer 角色的专用账号(最小权限),不要复用管理员凭据。
快速开始
前提:本机已安装 bun(curl -fsSL https://bun.sh/install | bash)。项目零 npm 依赖,无需 npm install。
方式一:完全项目级配置(推荐 — 零全局依赖)
所有信息(test/prod 双环境地址、凭据、数据源 UID、项目 app 名称)全部写在项目 .mcp.json 中,不依赖 ~/.zshrc,换台机器只需复制 .mcp.json:
{
"mcpServers": {
"grafana": {
"command": "bunx",
"args": ["grafana-mcp"],
"env": {
"GRAFANA_ENV": "test",
"GRAFANA_APP": "my-app",
"GRAFANA_NAMESPACE": "my-namespace",
"GRAFANA_TEST_URL": "https://grafana.test.example.com",
"GRAFANA_TEST_USER": "viewer",
"GRAFANA_TEST_PASSWORD": "********",
"GRAFANA_TEST_LOKI_DATASOURCE": "loki-uid-here",
"GRAFANA_TEST_PROMETHEUS_DATASOURCE": "prom-uid-here",
"GRAFANA_PROD_URL": "https://grafana.prod.example.com",
"GRAFANA_PROD_USER": "viewer",
"GRAFANA_PROD_PASSWORD": "********",
"GRAFANA_PROD_LOKI_DATASOURCE": "loki-uid-prod",
"GRAFANA_PROD_PROMETHEUS_DATASOURCE": "prom-uid-prod"
}
}
}
}配置好后:
- project_context 会自动显示当前环境、可用环境列表、项目 app 等信息
- switch_environment 可在 test/prod 之间切换(仅影响当前会话)
- loki_query 会自动注入 app="my-app" 标签(传 injectApp=false 关闭)
⚠️ .mcp.json 含明文凭据,务必加入 .gitignore。
方式二:zshrc 全局凭据 + 项目级上下文
适合多项目共享同一套 Grafana 凭据的场景。凭据配在 ~/.zshrc 中(一次性),每个项目只配项目上下文:
项目 .mcp.json(只配项目上下文,不含凭据):
{
"mcpServers": {
"grafana": {
"command": "bunx",
"args": ["grafana-mcp"],
"env": {
"GRAFANA_ENV": "test",
"GRAFANA_APP": "my-app"
}
}
}
}或项目 .grafana.json(承载更多信息,对 agent 可见可解释):
{
"defaultEnv": "test",
"app": "my-app",
"appLabel": "app",
"namespace": "my-namespace",
"notes": "本项目日志标签 app=my-app;查指标时 pod 前缀为 my-app-"
}Shortened. The full README is on GitHub.
Nothing above is checked by us. What we check is on the safety report.
Grafana MCP: common questions
- Is Grafana MCP server safe?
- With care: it is graded C, so read the findings first (65/100). Read the Grafana MCP safety report
- How do I install Grafana MCP?
- It runs on your machine. Copy the Claude Code, Cursor, VS Code or Claude Desktop config from the install section.
- Does Grafana MCP need an API key?
- Yes. The registry entry asks for
GRAFANA_TEST_PASSWORD,GRAFANA_PROD_PASSWORD. - Is Grafana MCP maintained?
- The last commit was 24 days ago (2026-10-09). The latest release is v0.1.3.
- What can I use instead of Grafana MCP?
- Servers from other publishers that do the same job: Netdata MCP server.
- How does Grafana MCP compare with other MCP servers?
- safety score 65/100 (higher than 20% of 48,273 servers); tools 10 (the typical server has 7); tools that change things 0% (typical: 0%. Fewer write tools means less an agent can break). Full comparison.
Alternatives to Grafana MCP
Same job from other publishers: the closest match first, then the best rated.
- NetdataReal-time infrastructure monitoring with metrics, logs, alerts, and ML-based anomaly detection.not reviewedWidely usedA