8000 GitHub - cgoolsby/prometheus-mcp
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cgoolsby/prometheus-mcp

Repository files navigation

Prometheus MCP Server

A Model Context Protocol (MCP) server for Prometheus written in Go. This server enables AI assistants to query and analyze Prometheus metrics through standardized MCP interfaces.

Features

  • Execute PromQL instant queries
  • Execute PromQL range queries over a time period
  • Discover series by label matchers
  • Explore label names and values
  • Access metric metadata
  • Get information about scrape targets
  • Access alerts and recording rules
  • Get Prometheus server status information

Installation

Prerequisites

  • Go 1.20 or higher
  • A running Prometheus instance

Building from source

# Clone the repository
git clone https://github.com/cgoolsby/prometheus-mcp.git
cd prometheus-mcp

# Build the project
go build -o prometheus-mcp ./cmd/server

# Run the server
./prometheus-mcp

Configuration

The server can be configured using environment variables:

Usage with AI Assistants

This MCP server can be used with AI assistants that support the Model Context Protocol, such as Claude.

Using with Claude Desktop

  1. Add the server configuration to Claude Desktop:
    • On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • On Windows: %APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "prometheus-mcp-server": {
      "command": "/path/to/prometheus-mcp",
      "env": {
        "PROMETHEUS_HOST": "http://your-prometheus-instance:9090"
      }
    }
  }
}

Available Functions

The server provides the following functions:

  • mcp__instant_query: Execute an instant PromQL query
  • mcp__range_query: Execute a range PromQL query over a time period
  • mcp__get_series: Find series by label matchers
  • mcp__get_label_values: Get values for a specific label
  • mcp__get_metadata: Get metadata for metrics
  • mcp__get_targets: Get information about scrape targets
  • mcp__get_alerts: Get information about alerts
  • mcp__get_rules: Get information about recording and alerting rules
  • mcp__get_status: Get status information about the Prometheus server

Development

# Run tests
go test ./...

# Build the project
go build -o prometheus-mcp ./cmd/server

# Run end-to-end tests
./scripts/e2e_test.sh
# or
make e2e-test

Pre-commit Hooks

This repository includes pre-commit hooks to ensure code quality. To enable them, run:

git config core.hooksPath .githooks

You can skip the end-to-end tests in the pre-commit hook by setting an environment variable:

SKIP_E2E_TESTS=true git commit -m "Your commit message"

Tutorial

A detailed tutorial on how to use the Prometheus MCP server with a local Prometheus instance and Ollama for LLM integration is available in the docs/tutorial.md file.

License

MIT

Project Structure

├── cmd/                 # Command-line applications
│   └── server/          # Main MCP server application
├── docs/                # Documentation
│   └── tutorial.md      # Tutorial for using the server
├── examples/            # Example code
│   └── demo.go          # Go demo showing MCP server usage
├── internal/            # Internal packages
│   └── server/          # Server implementation
├── pkg/                 # Public packages
│   ├── mcp/             # MCP protocol implementation
│   └── prometheus/      # Prometheus client
├── scripts/             # Utility scripts
│   └── e2e_test.sh      # End-to-end test script
└── .githooks/           # Git hooks
    └── pre-commit       # Pre-commit hook for quality checks

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository
  2. Create a new branch for your feature or bugfix
  3. Implement your changes
  4. Add tests for your changes
  5. Ensure all tests pass (make test and make e2e-test)
  6. Commit your changes (the pre-commit hook will run quality checks)
  7. Push to your branch
  8. Create a Pull Request

Code Style

This project follows standard Go coding conventions. Please ensure your code:

  • Is formatted with go fmt
  • Passes go vet
  • Has appropriate comments and documentation
  • Includes tests for new functionality

Reporting Issues

If you find a bug or have a feature request, please create an issue with the following information:

  • A clear, descriptive title
  • A detailed description of the issue or feature request
  • Steps to reproduce the issue (for bugs)
  • Expected behavior
  • Actual behavior
  • Environment information (OS, Go version, Prometheus version)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0