About Prometheus MCP 服务器
Prometheus MCP 服务器 exposes Prometheus metric queries to MCP clients for metric inspection and analysis. It supports instant and range PromQL queries and can turn range results into charts.
Key features
- 01Search metrics with regular expressions
- 02Retrieve metric labels and values
- 03Run instant PromQL queries
- 04Run range PromQL queries
- 05Generate charts from range queries
Use cases
- 01Find metric names matching a pattern
- 02Inspect metric labels and their values
- 03Analyze metric changes over a time range
- 04Chart the results of a range query
MCP support
The MCP server provides tools for metric search, label lookup, instant and range PromQL queries, and chart generation. Query results are returned as JSON, while charts are returned as base64-encoded PNG images.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEPrometheus MCP 服务器
这是一个简化版的Prometheus MCP服务器,用于查询指标提供 ai 分析。
快速开始
启动
- 设置Prometheus地址环境变量:
export PROMETHEUS_URL=your_Prometheus_endpoint
- 启动服务器:
go run cmd/server/main.go sse
服务器将在:8081端口启动,可以通过以下URL访问:
- (可选) 设置日志文件路径:
export APP_LOG_FILE=/path/to/logfile.log
测试
npx @modelcontextprotocol/inspector node build/index.js
功能特性
AI友好化分析指标
- JSON格式输出:所有查询结果均以JSON格式返回,便于AI系统解析处理
MCP工具
-
search_metrics - 按正则表达式搜索指标
- 参数:
pattern(指标名称模式,支持正则表达式) - 示例:
http_.*匹配所有以http_开头的指标 - 返回: 匹配的指标名称列表(JSON格式)
- 参数:
-
get_metric_labels - 获取指标的所有标签
- 参数:
name(指标名称) - 示例:
http_requests_total - 返回: 该指标的所有标签列表(JSON格式,不包括
__name__标签)
- 参数:
-
get_metric_label_values - 获取指标标签的所有值
- 参数:
name(指标名称)label(标签名称)
- 示例: 获取
http_requests_total指标的method标签的所有值 - 返回: 指定标签的所有值列表(JSON格式)
- 参数:
-
query - 执行PromQL即时查询
- 参数:
query(PromQL查询语句)time(查询时间戳,格式为RFC3339或Unix时间戳,可选)
- 示例: 查询当前CPU使用率
- 返回: 查询结果(JSON格式)
- 参数:
-
query_range - 执行PromQL范围查询
- 参数:
query(PromQL查询语句)start(开始时间,格式为RFC3339或Unix时间戳(毫秒))end(结束时间,格式为RFC3339或Unix时间戳(毫秒))step(查询步长,例如'15s'、'1m')
- 示例: 查询过去1小时CPU使用率变化,每15秒一个数据点
- 返回: 范围查询结果(JSON格式)
- 参数:
-
query_chart - 执行PromQL范围查询并生成图表
- 参数:
query(PromQL查询语句)start(开始时间,格式为RFC3339或Unix时间戳(毫秒))end(结束时间,格式为RFC3339或Unix时间戳(毫秒))step(查询步长,例如'15s'、'1m')title(图表标题,可选)
- 示例: 查询过去1小时CPU使用率变化并生成图表
- 返回: 图表图片(base64编码的PNG格式)
- 参数:
服务器端
- 设置Prometheus地址:
export PROMETHEUS_URL=your_Prometheus_endpoint
- 启动服务器:
go run cmd/server/main.go sse
服务器默认将在:8081端口暴露Prometheus指标。
mcp 客户端配置
配置示例:
{
"mcpServers": {
"products-sse": {
"url": "http://localhost:8081/sse"
}
}
}
项目结构
.
├── cmd/ # 命令行程序入口
│ └── server/ # 服务器代码
├── internal/ # 内部实现
├── pkg/ # 可复用包
│ └── prometheus # Prometheus相关实现
└── go.mod # Go模块定义
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.