Prometheus MCP Server 是一个模型上下文协议(MCP)服务器,它能让 AI 助手与 Prometheus 实现无缝集成,支持通过自然语言与监控基础设施进行交互。借助该服务器,你可以通过 Visual Studio Code、Cursor、Windsurf、Claude Desktop 等 MCP 客户端轻松查询、发现和分析指标。
首先,将 Prometheus MCP 服务器与你的客户端进行安装。典型的配置如下:
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["prometheus-mcp@latest", "stdio"],
"env": {
"PROMETHEUS_URL": "http://localhost:9090"
}
}
}
}
# 对于 VS Code
code --add-mcp '{"name":"prometheus","command":"npx","args":["prometheus-mcp@latest","stdio"],"env":{"PROMETHEUS_URL":"http://localhost:9090"}}'
# 对于 VS Code Insiders
code-insiders --add-mcp '{"name":"prometheus","command":"npx","args":["prometheus-mcp@latest","stdio"],"env":{"PROMETHEUS_URL":"http://localhost:9090"}}'
安装完成后,Prometheus MCP 服务器即可在 VS Code 中与你的 GitHub Copilot 代理一起使用。
前往 Cursor Settings → MCP → Add new MCP Server。你可以自行命名,使用 command 类型并输入命令 npx prometheus-mcp。也可以通过点击 Edit 来验证配置或添加命令参数。
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["prometheus-mcp@latest", "stdio"],
"env": {
"PROMETHEUS_URL": "http://localhost:9090"
}
}
}
}
遵循 Windsurf MCP 文档进行操作,使用以下配置:
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["prometheus-mcp@latest", "stdio"],
"env": {
"PROMETHEUS_URL": "http://localhost:9090"
}
}
}
}
Claude Desktop 支持两种安装方法:
最简单的安装方式是使用预构建的 DXT 扩展:
.dxt 文件。对于高级用户或需要自定义配置的情况,可以手动配置 MCP 服务器:
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["prometheus-mcp@latest", "stdio"],
"env": {
"PROMETHEUS_URL": "http://localhost:9090"
}
}
}
}
具体安装命令可参考快速开始部分的不同客户端安装步骤。
Prometheus MCP 服务器支持以下参数,可在上述 JSON 配置的 "args" 列表中提供:
> npx prometheus-mcp@latest --help
Commands:
stdio Start Prometheus MCP server using stdio transport
http Start Prometheus MCP server using HTTP transport
Options:
--help Show help [boolean]
--version Show version number [boolean]
你还可以使用环境变量来配置服务器:
PROMETHEUS_URL - Prometheus 服务器的 URLENABLE_DISCOVERY_TOOLS - 设置为 "false" 可禁用发现工具(默认值:true)ENABLE_INFO_TOOLS - 设置为 "false" 可禁用信息工具(默认值:true)ENABLE_QUERY_TOOLS - 设置为 "false" 可禁用查询工具(默认值:true)当在服务器环境中运行或需要使用 HTTP 传输时,可使用 http 命令启动 MCP 服务器:
npx prometheus-mcp@latest http --port 3000
然后在你的 MCP 客户端配置中,将 url 设置为 HTTP 端点:
{
"mcpServers": {
"prometheus": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:3000/mcp"]
}
}
}
使用 Docker 运行 Prometheus MCP 服务器:
{
"mcpServers": {
"prometheus": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--init",
"--pull=always",
"-e",
"PROMETHEUS_URL=http://host.docker.internal:9090",
"ghcr.io/idanfishman/prometheus-mcp",
"stdio"
]
}
}
}
Prometheus MCP 服务器提供了 10 个工具,分为三个可配置的类别:
用于探索 Prometheus 基础设施的工具:
prometheus_list_metrics
prometheus_metric_metadata
metric (字符串):要获取元数据的指标名称prometheus_list_labels
prometheus_label_values
label (字符串):要获取值的标签名称prometheus_list_targets
prometheus_scrape_pool_targets
scrapePool (字符串):抓取池名称用于访问 Prometheus 服务器信息的工具:
prometheus_runtime_info
prometheus_build_info
用于执行 Prometheus 查询的工具:
prometheus_query
query (字符串):Prometheus 查询表达式time (字符串,可选):查询的时间参数(RFC3339 格式)prometheus_query_range
query (字符串):Prometheus 查询表达式start (字符串):开始时间戳(RFC3339 或 Unix 时间戳)end (字符串):结束时间戳(RFC3339 或 Unix 时间戳)step (字符串):查询分辨率步长以下是一些你可以与 AI 助手进行交互的示例:
http_requests_total metric?"(http_requests_total 指标有哪些可用的标签?)本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。
本项目是为 Prometheus 和 MCP 社区精心打造的 ❤️