Prometheus MCP Server
Prometheus MCP 服务器
Prometheus 的模型上下文协议(MCP) 服务器。
这可以通过标准化的 MCP 接口访问您的 Prometheus 指标和查询,从而允许 AI 助手执行 PromQL 查询并分析您的指标数据。
特征
[x] 针对 Prometheus 执行 PromQL 查询
[x] 发现并探索指标
[x] 列出可用指标
[x] 获取特定指标的元数据
[x] 查看即时查询结果
[x] 查看不同步长间隔的范围查询结果
[x] 身份验证支持
[x] 来自环境变量的基本身份验证
[x] 来自环境变量的 Bearer 令牌认证
[x] Docker 容器化支持
[x] 为AI助手提供交互工具
工具列表是可配置的,因此您可以选择要向 MCP 客户端提供的工具。如果您不使用某些功能,或者不想占用太多上下文窗口空间,此功能非常有用。
Related MCP server: Prometheus MCP Server
用法
确保您的 Prometheus 服务器可从运行此 MCP 服务器的环境访问。
通过
.env文件或系统环境变量配置 Prometheus 服务器的环境变量:
# Required: Prometheus configuration
PROMETHEUS_URL=http://your-prometheus-server:9090
# Optional: Authentication credentials (if needed)
# Choose one of the following authentication methods if required:
# For basic auth
PROMETHEUS_USERNAME=your_username
PROMETHEUS_PASSWORD=your_password
# For bearer token auth
PROMETHEUS_TOKEN=your_token
# Optional: For multi-tenant setups like Cortex, Mimir or Thanos
ORG_ID=your_organization_id将服务器配置添加到客户端配置文件中。例如,对于 Claude Desktop:
{
"mcpServers": {
"prometheus": {
"command": "uv",
"args": [
"--directory",
"<full path to prometheus-mcp-server directory>",
"run",
"src/prometheus_mcp_server/main.py"
],
"env": {
"PROMETHEUS_URL": "http://your-prometheus-server:9090",
"PROMETHEUS_USERNAME": "your_username",
"PROMETHEUS_PASSWORD": "your_password"
}
}
}
}注意:如果您在 Claude Desktop 中看到
Error: spawn uv ENOENT,则可能需要指定uv的完整路径或在配置中设置环境变量NO_UV=1。
Docker 使用
该项目包括 Docker 支持,以便于部署和隔离。
预建 Docker 镜像
使用此项目的最简单方法是使用来自 GitHub Container Registry 的预构建映像:
docker pull ghcr.io/pab1it0/prometheus-mcp-server:latest您还可以使用带有标签的特定版本:
docker pull ghcr.io/pab1it0/prometheus-mcp-server:1.0.0在本地构建 Docker 镜像
如果您希望自己构建图像:
docker build -t prometheus-mcp-server .使用 Docker 运行
您可以通过多种方式使用 Docker 运行服务器:
使用 docker run 和预先构建的图像:
docker run -it --rm \
-e PROMETHEUS_URL=http://your-prometheus-server:9090 \
-e PROMETHEUS_USERNAME=your_username \
-e PROMETHEUS_PASSWORD=your_password \
ghcr.io/pab1it0/prometheus-mcp-server:latest使用 docker run 和本地构建的图像:
docker run -it --rm \
-e PROMETHEUS_URL=http://your-prometheus-server:9090 \
-e PROMETHEUS_USERNAME=your_username \
-e PROMETHEUS_PASSWORD=your_password \
prometheus-mcp-server使用docker-compose:
使用您的 Prometheus 凭据创建一个.env文件,然后运行:
docker-compose up在 Claude Desktop 中使用 Docker 运行
要将容器化服务器与 Claude Desktop 一起使用,请更新配置以使用带有环境变量的 Docker:
{
"mcpServers": {
"prometheus": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e", "PROMETHEUS_URL",
"-e", "PROMETHEUS_USERNAME",
"-e", "PROMETHEUS_PASSWORD",
"ghcr.io/pab1it0/prometheus-mcp-server:latest"
],
"env": {
"PROMETHEUS_URL": "http://your-prometheus-server:9090",
"PROMETHEUS_USERNAME": "your_username",
"PROMETHEUS_PASSWORD": "your_password"
}
}
}
}此配置通过使用仅带有变量名的-e标志,并在env对象中提供实际值,将环境变量从 Claude Desktop 传递到 Docker 容器。
关于 Docker 实现的说明:Docker 设置已更新,以匹配 chess-mcp 项目的结构,该项目已被证明可以与 Claude 正确配合。新的实现采用多阶段构建流程,并直接运行入口点脚本,无需中间的 shell 脚本。这种方法确保正确处理 MCP 通信的标准输入/输出 (stdin/stdout)。
发展
欢迎贡献代码!如果您有任何建议或改进,请创建 issue 或提交 pull request。
本项目使用uv来管理依赖项。请按照您平台的说明安装uv :
curl -LsSf https://astral.sh/uv/install.sh | sh然后,您可以创建一个虚拟环境并使用以下命令安装依赖项:
uv venv
source .venv/bin/activate # On Unix/macOS
.venv\Scripts\activate # On Windows
uv pip install -e .项目结构
该项目已采用src目录结构进行组织:
prometheus-mcp-server/
├── src/
│ └── prometheus_mcp_server/
│ ├── __init__.py # Package initialization
│ ├── server.py # MCP server implementation
│ ├── main.py # Main application logic
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .dockerignore # Docker ignore file
├── pyproject.toml # Project configuration
└── README.md # This file测试
该项目包括一个全面的测试套件,可确保功能并有助于防止回归。
使用 pytest 运行测试:
# Install development dependencies
uv pip install -e ".[dev]"
# Run the tests
pytest
# Run with coverage report
pytest --cov=src --cov-report=term-missing测试分为:
配置验证测试
服务器功能测试
错误处理测试
主要应用测试
当添加新功能时,请同时添加相应的测试。
工具
工具 | 类别 | 描述 |
| 询问 | 针对 Prometheus 执行 PromQL 即时查询 |
| 询问 | 执行包含开始时间、结束时间和步长间隔的 PromQL 范围查询 |
| 发现 | 列出 Prometheus 中所有可用的指标 |
| 发现 | 获取特定指标的元数据 |
| 发现 | 获取有关所有抓取目标的信息 |
执照
麻省理工学院
Available Tools
6 toolsexecute_queryExecute PromQL QueryCRead-onlyIdempotent
Execute a PromQL instant query against Prometheus
Inputs: query (required), time. Returns: object
execute_range_queryExecute PromQL Range QueryBRead-onlyIdempotent
Execute a PromQL range query with start time, end time, and step interval
Inputs: query (required), start (required), end (required), step (required). Returns: object
get_metric_metadataGet Metric MetadataARead-onlyIdempotent
Get metadata (type, help, unit) for metrics. Returns all metric metadata when no metric name is provided. Use filter_pattern to search metric names and descriptions.
Inputs: metric, filter_pattern, limit, offset. Returns: result
get_targetsGet Scrape TargetsARead-onlyIdempotent
Get information about all scrape targets
Inputs: no named parameters. Returns: object
health_checkHealth CheckARead-onlyIdempotent
Health check endpoint for container monitoring and status verification
Inputs: no named parameters. Returns: object
list_metricsList Available MetricsARead-onlyIdempotent
List all available metrics in Prometheus with optional pagination support
Inputs: limit, offset, filter_pattern, refresh_cache. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: query types (instant vs range), metadata retrieval, target info, health check, and metric listing. No overlap.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., execute_query, get_metric_metadata). No deviations.
Six tools cover the essential Prometheus operations without being excessive or insufficient. Well-scoped for the server's purpose.
Core CRUD-like operations for queries and metadata are present. Minor gaps like alert management or rule configuration are missing but not critical for the primary use case.
Maintenance
Related MCP Connectors
Query your app's logs, metrics and incidents from your AI assistant.
Query application logs, traces, and metrics from your AI coding assistant via Foam's MCP server.
Lets AI agents analyze API metrics, request logs, and traces, and manage apps and alerts.
List datasets, schemas, run APL queries, and use prompts for exploration, anomalies, and monitoring.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA tool that enables access to Prometheus metrics data through a Model Context Protocol server, allowing interaction with monitoring data using natural language.MIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI assistants to query Prometheus metrics, discover available data, and analyze system performance through natural language interactions.5236 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to query Prometheus metrics, monitor alerts, and analyze system health through read-only access to your Prometheus server with built-in query safety and optional AI-powered metric analysis.MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to execute PromQL queries and discover metrics across multiple Prometheus tenants using the Model Context Protocol. It supports single and multi-tenant configurations with secure authentication for instant and range query analysis.MIT