界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
开发与工程 · SKILL.md

prometheus-mcp-connector

prometheus-mcp-connector

【开发与工程】MCP connector for Prometheus monitoring – enables AI-powered PromQL query building, alert rule creation, and metric exploration through Claude

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: prometheus-mcp-connector description: "MCP connector for Prometheus monitoring – enables AI-powered PromQL query building, alert rule creation, and metric exploration through Claude" license: Apache 2.0 tags: ["cloud","monitoring","mcp","prometheus","metrics"] difficulty: advanced time_to_master: "4-8 weeks" version: "1.0.0"

Prometheus MCP Connector

Overview

This skill enables Claude to interact with Prometheus through the Model Context Protocol (MCP). It provides a bridge between Claude's AI capabilities and Prometheus's REST API, allowing natural language control of Prometheus operations, intelligent automation, and AI-powered assistance for Prometheus workflows.

When to Use This Skill

  • PromQL query generation from natural language
  • Alert rule and recording rule creation
  • Metric exploration and cardinality analysis
  • Target and service discovery configuration
  • Federation and remote write setup

Architecture

┌─────────────┐     ┌─────────────────┐     ┌──────────────────┐
│   Claude     │────▶│   MCP Server    │────▶│   Prometheus       │
│   (Client)   │◀────│   (TypeScript)  │◀────│   (REST API      )│
└─────────────┘     └─────────────────┘     └──────────────────┘

Core Concepts

MCP Server Setup

The connector implements an MCP server that exposes Prometheus operations as tools Claude can invoke. The server translates natural language intentions into REST API calls.

Key Endpoints/Interfaces

/api/v1/query, /api/v1/query_range, /api/v1/series, /api/v1/targets, /api/v1/rules

Implementation

// Prometheus MCP Server Implementation
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "prometheus-mcp-connector",
  version: "1.0.0",
});

// Tool: List/Query Resources
server.tool(
  "list_resources",
  "List and query Prometheus resources with optional filters",
  {
    query: z.string().optional().describe("Search query or filter"),
    limit: z.number().optional().describe("Max results to return"),
  },
  async ({ query, limit }) => {
    // Call Prometheus REST API
    const response = await fetch(`${BASE_URL}/api/v1/query`, {
      headers: { "Authorization": `Bearer ${API_KEY}` },
    });
    const data = await response.json();
    return {
      content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
    };
  }
);

// Tool: Create Resource
server.tool(
  "create_resource",
  "Create a new resource in Prometheus",
  {
    name: z.string().describe("Resource name"),
    config: z.object({}).passthrough().optional().describe("Resource configuration"),
  },
  async ({ name, config }) => {
    const response = await fetch(`${BASE_URL}/api/v1/query`, {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ name, ...config }),
    });
    const data = await response.json();
    return {
      content: [{ type: "text", text: `Created: ${JSON.stringify(data)}` }],
    };
  }
);

// Tool: Analyze/Report
server.tool(
  "analyze",
  "AI-powered analysis of Prometheus data",
  {
    type: z.string().describe("Analysis type"),
    timeframe: z.string().optional().describe("Time range for analysis"),
  },
  async ({ type, timeframe }) => {
    // Fetch data and provide AI analysis
    const response = await fetch(`${BASE_URL}/api/v1/query`, {
      headers: { "Authorization": `Bearer ${API_KEY}` },
    });
    const data = await response.json();
    return {
      content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
    };
  }
);

// Start server
const transport = new StdioServerTransport();
await server.connect(transport);

Claude Desktop Configuration

{
  "mcpServers": {
    "prometheus-mcp-connector": {
      "command": "node",
      "args": ["path/to/prometheus-mcp-connector/index.js"],
      "env": {
        "PROMETHEUS_API_KEY": "your-api-key",
        "PROMETHEUS_BASE_URL": "https://your-instance-url"
      }
    }
  }
}

Best Practices

  1. Authentication: Store API keys securely using environment variables; never hardcode credentials
  2. Rate Limiting: Implement request throttling to respect Prometheus API rate limits
  3. Error Handling: Provide clear, actionable error messages for common failure scenarios
  4. Pagination: Handle paginated responses for large datasets efficiently
  5. Caching: Cache frequently accessed read-only data to reduce API calls
  6. Security: Validate all inputs before passing to the Prometheus API; sanitize outputs
  7. Logging: Log all API interactions for debugging and audit purposes

Example Prompts

"Create a PromQL query for the 95th percentile request latency by service with a 5-minute rate window"

Security Considerations

  • All API credentials must be stored as environment variables
  • Implement input validation and sanitization for all tool parameters
  • Use HTTPS for all API communications
  • Follow the principle of least privilege for API token permissions
  • Audit log all write operations for compliance tracking

Resources

Changelog

VersionDateChanges
1.0.02026-04-01Initial MCP connector skill

Part of SkillGalaxy - 10,000+ comprehensive skills for AI-assisted development.

我的收藏