关于 mcp-prometheus
mcp-prometheus 是 Go 编写的 MCP 服务,向客户端提供 Prometheus 查询、状态、规则、目标及 Kubernetes 诊断功能。它可直连配置的 Prometheus URL,也可通过 Kubernetes API 代理连接。
主要功能
- 01PromQL 瞬时与区间查询
- 02检查目标、规则和服务状态
- 03集群、节点与命名空间诊断
- 04CPU、内存和网络分析
- 05通过 Kubernetes API 代理连接
适用场景
- 01查看 Prometheus 指标和抓取目标
- 02检查集群或节点健康状况
- 03调查 Pod 资源使用情况
- 04比较不同时间段的指标
MCP 相关
该 MCP 服务向 MCP 客户端提供 11 种 Prometheus 查询、状态和诊断工具。它通过 Prometheus URL 直连,或经 Kubernetes API 代理连接。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Prometheus MCP 服务(Go)
用于集成 Prometheus 的 Model Context Protocol (MCP) 服务。原生 Go 二进制程序,通过 client-go 内置 Kubernetes 连接能力。
安装
npx
npx -y mcp-prometheus@latest
MCP 客户端配置
添加到 MCP 客户端配置中(VS Code、Cursor、Windsurf 等):
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["-y", "mcp-prometheus@latest"],
"env": {
"PROMETHEUS_URL": "http://localhost:9090"
}
}
}
}
VS Code
code --add-mcp '{"name":"prometheus","command":"npx","args":["-y","mcp-prometheus@latest"],"env":{"PROMETHEUS_URL":"http://localhost:9090"}}'
Kubernetes 自动连接
通过 K8S API 服务代理,自动连接到在 OpenShift/Kubernetes 中运行的 Prometheus。使用 client-go 通过原生 kubeconfig/集群内配置连接。无需 kubectl 或端口转发。
默认值:openshift-monitoring/prometheus-operated:9090
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["-y", "mcp-prometheus@latest"]
}
}
}
二进制程序
从 GitHub Releases 下载,或从源代码构建:
make build
./mcp-prometheus
配置
环境变量
| 变量 | 描述 |
|---|---|
PROMETHEUS_URL | 直接指定的 Prometheus API URL(优先于 K8S 自动连接) |
CLI 标志
| 标志 | 描述 | 默认值 |
|---|---|---|
--url | 直接指定的 Prometheus URL | - |
--namespace | Kubernetes 命名空间 | openshift-monitoring |
--service | Kubernetes 服务名称 | prometheus-operated |
--service-port | Kubernetes 服务端口 | 9090 |
--service-scheme | 服务协议(http/https) | https |
--kubeconfig | kubeconfig 文件路径 | 自动检测 |
优先级: --url / PROMETHEUS_URL > K8S 自动连接
连接策略:
- 直接 URL(设置了
--url或PROMETHEUS_URL时) - K8S API 代理(自动检测 kubeconfig 或集群内配置)
工具(11 个)
基本查询
| 工具 | 描述 |
|---|---|
query | 执行 PromQL 即时查询 |
queryRange | 执行 PromQL 时间范围查询 |
getTargets | 获取抓取目标状态 |
getRules | 获取告警规则和记录规则 |
getPrometheusStatus | 获取服务版本和运行时信息 |
集群诊断
| 工具 | 描述 |
|---|---|
getClusterHealthOverview | 全面概览集群健康状况 |
diagnoseNode | 诊断指定节点的健康状况 |
diagnoseNamespace | 诊断命名空间的健康状况 |
资源分析
| 工具 | 描述 |
|---|---|
getTopResourceConsumers | 查看 CPU、内存和网络资源消耗排名 |
investigatePod | 深入调查指定 Pod |
compareTimeRanges | 比较两个时间段的指标 |
示例提示词
"What's the current CPU usage across all nodes?"
"Show me the cluster health overview"
"Which pods are using the most memory?"
"Diagnose node worker-1"
"Are all scrape targets healthy?"
"Compare CPU usage now vs 24 hours ago"
"Investigate pod my-app in namespace production"
"What alerting rules are defined?"
开发
构建
make build # Build for current platform
make build-all-platforms # Cross-compile for all platforms
容器
podman build -f Containerfile -t mcp-prometheus .
Kubernetes / OpenShift 部署
容器镜像
容器镜像可从 GitHub Container Registry 获取:
ghcr.io/jeanlopezxyz/mcp-prometheus:latest
Helm Chart
使用随附的 Helm Chart 部署:
# Add the chart repository (or use local chart)
helm upgrade --install mcp-prometheus ./charts/mcp-prometheus \
--namespace mcp-servers \
--create-namespace \
--set openshift=true
Helm Values
| 参数 | 描述 | 默认值 |
|---|---|---|
image.registry | 容器注册表 | ghcr.io |
image.repository | 镜像仓库 | jeanlopezxyz/mcp-prometheus |
image.version | 镜像标签 | latest |
openshift | 启用 OpenShift Routes | false |
service.port | 服务端口 | 8080 |
prometheus.namespace | Prometheus 命名空间 | openshift-monitoring |
prometheus.service | Prometheus 服务名称 | prometheus-operated |
rbac.useClusterReader | 使用 cluster-reader 角色 | true |
使用自定义 Prometheus 的示例
helm upgrade --install mcp-prometheus ./charts/mcp-prometheus \
--namespace mcp-servers \
--set openshift=true \
--set prometheus.url=http://prometheus.monitoring:9090
许可证
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。