Prometheus MCP Server
Enables 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.
README
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 across multiple Prometheus tenants.
<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
- [x] Execute PromQL queries against Prometheus
- [x] Multi-tenant support - Query multiple Prometheus instances
- [x] Discover and explore metrics
- [x] List available metrics
- [x] Get metadata for specific metrics
- [x] View instant query results
- [x] View range query results with different step intervals
- [x] Authentication support
- [x] Basic auth from environment variables
- [x] Bearer token auth from environment variables
- [x] Docker containerization support
- [x] Cross-tenant queries
- [x] 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
Single Tenant Configuration (Backward Compatible)
-
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
.envfile 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
Multi-Tenant Configuration
For multiple Prometheus instances or tenants, use the JSON configuration:
# Multi-tenant configuration via JSON
PROMETHEUS_TENANTS='[
{
"name": "production",
"url": "https://prometheus-prod.example.com",
"username": "prod_user",
"password": "prod_password",
"org_id": "org-prod"
},
{
"name": "staging",
"url": "https://prometheus-staging.example.com",
"token": "staging_bearer_token"
},
{
"name": "development",
"url": "http://localhost:9090"
}
]'
# Optional: Set default tenant (defaults to first tenant if not specified)
PROMETHEUS_DEFAULT_TENANT=production
MCP Client Configuration
- Add the server configuration to your client configuration file. For example, for Claude Desktop:
Single Tenant
{
"mcpServers": {
"prometheus": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"PROMETHEUS_URL",
"ghcr.io/pab1it0/prometheus-mcp-server:latest"
],
"env": {
"PROMETHEUS_URL": "<url>"
}
}
}
}
Multi-Tenant
{
"mcpServers": {
"prometheus": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"PROMETHEUS_TENANTS",
"-e",
"PROMETHEUS_DEFAULT_TENANT",
"ghcr.io/pab1it0/prometheus-mcp-server:latest"
],
"env": {
"PROMETHEUS_TENANTS": "[{\"name\":\"prod\",\"url\":\"https://prometheus.example.com\",\"token\":\"your_token\"}]",
"PROMETHEUS_DEFAULT_TENANT": "prod"
}
}
}
}
Available Tools
| Tool | Category | Description |
|---|---|---|
list_tenants |
Multi-Tenant | List all configured Prometheus tenants |
execute_query |
Query | Execute a PromQL instant query against Prometheus (with optional tenant) |
execute_range_query |
Query | Execute a PromQL range query with start time, end time, and step interval (with optional tenant) |
execute_query_all_tenants |
Multi-Tenant | Execute a query across all configured tenants |
list_metrics |
Discovery | List all available metrics in Prometheus (with optional tenant) |
get_metric_metadata |
Discovery | Get metadata for a specific metric (with optional tenant) |
get_targets |
Discovery | Get information about all scrape targets (with optional tenant) |
Multi-Tenant Tool Examples
# List all configured tenants
await list_tenants()
# Query specific tenant
await execute_query("up", tenant="production")
# Query default tenant (if no tenant specified)
await execute_query("up")
# Query all tenants at once
await execute_query_all_tenants("up")
# List metrics from staging environment
await list_metrics(tenant="staging")
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 with multi-tenant support
│ ├── 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
- Multi-tenant tests
- Error handling tests
- Main application tests
When adding new features, please also add corresponding tests.
Configuration Examples
Environment File (.env)
# Single tenant
PROMETHEUS_URL=http://localhost:9090
PROMETHEUS_USERNAME=admin
PROMETHEUS_PASSWORD=secret
# Or multi-tenant
PROMETHEUS_TENANTS='[
{
"name": "local",
"url": "http://localhost:9090",
"username": "admin",
"password": "secret"
},
{
"name": "remote",
"url": "https://prometheus.example.com",
"token": "bearer_token_here",
"org_id": "my-org"
}
]'
PROMETHEUS_DEFAULT_TENANT=local
Docker Compose
version: "3.8"
services:
prometheus-mcp:
image: ghcr.io/pab1it0/prometheus-mcp-server:latest
environment:
PROMETHEUS_TENANTS: |
[
{
"name": "prod",
"url": "https://prometheus-prod.example.com",
"token": "${PROD_TOKEN}"
},
{
"name": "staging",
"url": "https://prometheus-staging.example.com",
"username": "${STAGING_USER}",
"password": "${STAGING_PASS}"
}
]
PROMETHEUS_DEFAULT_TENANT: prod
Migration from Single to Multi-Tenant
Existing single-tenant configurations will continue to work without changes. The server automatically creates a tenant named "default" for backward compatibility.
To migrate to multi-tenant:
- Keep existing config - Your current
PROMETHEUS_URL,PROMETHEUS_USERNAME, etc. will work - Add tenants gradually - Use
PROMETHEUS_TENANTSto add new tenants while keeping the old config - Specify tenants in queries - Add the optional
tenantparameter to tool calls when needed
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。