使用说明
普罗米修斯MCP服务器(Go)
A. 模型上下文协议(MCP) Prometheus集成服务器。Native Go二进制文件,通过客户端Go内置Kubernetes连接。
安装
npx
npx -y mcp-prometheus@latest
MCP客户端配置
添加到您的MCP客户端配置(VS代码、游标、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。通过客户端go在集群配置中使用本机kubeconfig/。不 kubectl 或需要端口转发。
违约: openshift-monitoring/prometheus-operated:9090
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["-y", "mcp-prometheus@latest"]
}
}
}
二进制
下载自 GitHub发布 或从源代码构建:
make build
./mcp-prometheus
配置
环境变量
| 变量 | 描述 |
|---|---|
PROMETHEUS_URL |
直接Prometheus API URL(覆盖K8S自动连接) |
CLI标志
| 标志 | 描述 | 默认值 |
|---|---|---|
--url |
普罗米修斯直接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 |
对特定吊舱的深入调查 |
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容器注册表中找到:
ghcr.io/jeanlopezxyz/mcp-prometheus:latest
Helm 图表
使用附带的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值
| 参数 | 说明 | 默认值 |
|---|---|---|
image.registry |
容器注册表 | ghcr.io |
image.repository |
图像存储库 | jeanlopezxyz/mcp-prometheus |
image.version |
图像标签 | latest |
openshift |
启用OpenShift路由 | false |
service.port |
服务端口 | 8080 |
prometheus.namespace |
Prometheus命名空间 | openshift-monitoring |
prometheus.service |
Prometheus服务名称 | prometheus-operated |
rbac.useClusterReader |
使用群集读取器角色 | true |
自定义Prometheus示例
helm upgrade --install mcp-prometheus ./charts/mcp-prometheus \
--namespace mcp-servers \
--set openshift=true \
--set prometheus.url=http://prometheus.monitoring:9090