Prometheus Mcp 伺服器
概覽
什麼是 Prometheus MCP 伺服器?
Prometheus MCP 伺服器是一個模型上下文協議(MCP)伺服器,旨在幫助 AI 助手通過標準化接口查詢和分析 Prometheus 指標。這個伺服器充當橋樑,允許 AI 系統與 Prometheus 提供的豐富數據無縫互動,Prometheus 是一個在雲原生環境中廣泛使用的強大監控和警報工具包。
Prometheus MCP 伺服器的特點
- 標準化接口:該伺服器提供一組標準化的 API,使 AI 助手能夠輕鬆訪問和操作 Prometheus 指標。
- 實時數據訪問:用戶可以實時查詢指標,從而獲得即時見解和決策支持。
- 易於集成:設計上能夠與現有的 AI 系統和 Prometheus 設置平滑集成,增強整體功能而無需進行大量更改。
- 開源:作為一個公共庫,它鼓勵社區貢獻和改進,促進協作開發環境。
- 可擴展性:該架構支持擴展,適合小型和大型部署。
如何使用 Prometheus MCP 伺服器
- 安裝:從 GitHub 克隆庫並按照文檔中提供的安裝說明進行操作。
- 配置:通過配置必要的參數來設置伺服器,以連接到您的 Prometheus 實例。
- API 訪問:利用提供的 API 從您的 AI 助手向 Prometheus MCP 伺服器發送查詢。
- 數據分析:分析返回的指標,並將其整合到您的 AI 工作流程中,以增強決策能力。
- 社區支持:與社區互動以獲得支持、功能請求和對項目的貢獻。
常見問題
Prometheus MCP 伺服器的目的是什么?
Prometheus MCP 伺服器的主要目的是使 AI 助手能夠通過標準化接口查詢和分析 Prometheus 指標,增強 AI 在數據驅動環境中的能力。
Prometheus MCP 伺服器是開源的嗎?
是的,Prometheus MCP 伺服器是一個開源項目,允許用戶對其開發和改進進行貢獻。
我如何能夠貢獻於 Prometheus MCP 伺服器?
您可以通過分叉庫、進行改進並提交拉取請求來貢獻。此外,您還可以通過 GitHub 問題頁報告問題或建議功能。
運行 Prometheus MCP 伺服器的系統要求是什麼?
該伺服器需要一個兼容的環境,並能夠訪問 Prometheus 實例。具體要求可以在庫中的文檔中找到。
我可以將 Prometheus MCP 伺服器與其他監控工具一起使用嗎?
雖然它主要設計用於 Prometheus,但該架構允許根據具體用例和要求與其他監控工具進行潛在集成。
詳細
Prometheus MCP Server
A Model Context Protocol (MCP) server for Prometheus.
This provides access to your Prometheus metrics and queries through standardized MCP interfaces, allowing AI assistants to execute PromQL queries and analyze your metrics data.
<a href="https://glama.ai/mcp/servers/@pab1it0/prometheus-mcp-server"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@pab1it0/prometheus-mcp-server/badge" alt="Prometheus Server MCP server" /> </a>Features
-
Execute PromQL queries against Prometheus
-
Discover and explore metrics
- List available metrics
- Get metadata for specific metrics
- View instant query results
- View range query results with different step intervals
-
Authentication support
- Basic auth from environment variables
- Bearer token auth from environment variables
-
Docker containerization support
-
Provide interactive tools for AI assistants
The list of tools is configurable, so you can choose which tools you want to make available to the MCP client. This is useful if you don't use certain functionality or if you don't want to take up too much of the context window.
Usage
-
Ensure your Prometheus server is accessible from the environment where you'll run this MCP server.
-
Configure the environment variables for your Prometheus server, either through a
.env
file or system environment variables:
### 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
- Add the server configuration to your client configuration file. For example, for Claude Desktop:
{
"mcpServers": {
"prometheus": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"PROMETHEUS_URL",
"ghcr.io/pab1it0/prometheus-mcp-server:latest"
],
"env": {
"PROMETHEUS_URL": "<url>"
}
}
}
}
Development
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
This project uses uv
to manage dependencies. Install uv
following the instructions for your platform:
curl -LsSf https://astral.sh/uv/install.sh | sh
You can then create a virtual environment and install the dependencies with:
uv venv
source .venv/bin/activate # On Unix/macOS
.venv\Scripts\activate # On Windows
uv pip install -e .
Project Structure
The project has been organized with a src
directory structure:
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
Testing
The project includes a comprehensive test suite that ensures functionality and helps prevent regressions.
Run the tests with pytest:
### Install development dependencies
uv pip install -e ".[dev]"
### Run the tests
pytest
### Run with coverage report
pytest --cov=src --cov-report=term-missing
Tests are organized into:
- Configuration validation tests
- Server functionality tests
- Error handling tests
- Main application tests
When adding new features, please also add corresponding tests.
Tools
| Tool | Category | Description |
| | | |
| execute_query
| Query | Execute a PromQL instant query against Prometheus |
| execute_range_query
| Query | Execute a PromQL range query with start time, end time, and step interval |
| list_metrics
| Discovery | List all available metrics in Prometheus |
| get_metric_metadata
| Discovery | Get metadata for a specific metric |
| get_targets
| Discovery | Get information about all scrape targets |
License
MIT
伺服器配置
{
"mcpServers": {
"prometheus-mcp-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--pab1it0--prometheus-mcp-server--prometheus-mcp-server",
"prometheus-mcp-server"
],
"env": {
"PROMETHEUS_URL": "prometheus-url",
"PROMETHEUS_USERNAME": "prometheus-username",
"PROMETHEUS_PASSWORD": "prometheus-password"
}
}
}
}