Content
# Prometheus MCP Server
This is a simplified version of the Prometheus MCP server for querying metrics to provide AI analysis.
## Quick Start
### Launch
1. Set the Prometheus address environment variable:
```bash
export PROMETHEUS_URL=your_Prometheus_endpoint
```
2. Start the server:
```bash
go run cmd/server/main.go sse
```
The server will start on port `:8081`, and can be accessed via the following URL:
- http://localhost:8081/sse
3. (Optional) Set the log file path:
```bash
export APP_LOG_FILE=/path/to/logfile.log
```
### Testing
```bash
npx @modelcontextprotocol/inspector node build/index.js
```
## Features
### AI-Friendly Analysis Metrics
1. **JSON Format Output**: All query results are returned in JSON format, making it easy for AI systems to parse and process.
### MCP Tools
1. **search_metrics** - Search for metrics by regular expression
- Parameters: `pattern` (metric name pattern, supports regular expressions)
- Example: `http_.*` matches all metrics starting with `http_`
- Returns: A list of matching metric names (in JSON format)
2. **get_metric_labels** - Get all labels for a metric
- Parameters: `name` (metric name)
- Example: `http_requests_total`
- Returns: A list of all labels for the metric (in JSON format, excluding the `__name__` label)
3. **get_metric_label_values** - Get all values for a metric label
- Parameters:
- `name` (metric name)
- `label` (label name)
- Example: Get all values for the `method` label of the `http_requests_total` metric
- Returns: A list of all values for the specified label (in JSON format)
4. **query** - Execute a PromQL instant query
- Parameters:
- `query` (PromQL query statement)
- `time` (query timestamp, in RFC3339 format or Unix timestamp, optional)
- Example: Query the current CPU usage
- Returns: Query results (in JSON format)
5. **query_range** - Execute a PromQL range query
- Parameters:
- `query` (PromQL query statement)
- `start` (start time, in RFC3339 format or Unix timestamp (milliseconds))
- `end` (end time, in RFC3339 format or Unix timestamp (milliseconds))
- `step` (query step, e.g., '15s', '1m')
- Example: Query the CPU usage changes over the past hour, with one data point every 15 seconds
- Returns: Range query results (in JSON format)
6. **query_chart** - Execute a PromQL range query and generate a chart
- Parameters:
- `query` (PromQL query statement)
- `start` (start time, in RFC3339 format or Unix timestamp (milliseconds))
- `end` (end time, in RFC3339 format or Unix timestamp (milliseconds))
- `step` (query step, e.g., '15s', '1m')
- `title` (chart title, optional)
- Example: Query the CPU usage changes over the past hour and generate a chart
- Returns: Chart image (in base64 encoded PNG format)
### Server Side
1. Set the Prometheus address:
```bash
export PROMETHEUS_URL=your_Prometheus_endpoint
```
2. Start the server:
```bash
go run cmd/server/main.go sse
```
The server will expose Prometheus metrics on port `:8081` by default.
### MCP Client Configuration
Configuration example:
```json
{
"mcpServers": {
"products-sse": {
"url": "http://localhost:8081/sse"
}
}
}
```
## Project Structure
```
.
├── cmd/ # Command line program entry
│ └── server/ # Server code
├── internal/ # Internal implementation
├── pkg/ # Reusable packages
│ └── prometheus # Prometheus related implementation
└── go.mod # Go module definition
```
Connection Info
You Might Also Like
markitdown
Python tool for converting files and office documents to Markdown.
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.