Prometheus MCP Server + Grafana MCP Server

Intermediate1 hour
Use Cases

Common Use Cases

  • Service health dashboards
  • SLA monitoring
  • Capacity planning
  • Alert visualization
Before You Begin

Prerequisites

  • Prometheus server with targets configured
  • Grafana instance with API access
  • Services instrumented with Prometheus metrics
Walkthrough

Step-by-Step Guide

1

Connect Prometheus

Configure the Prometheus MCP Server with your Prometheus server URL.

2

Connect Grafana

Set up the Grafana MCP Server with an admin API key for dashboard management.

3

Discover Metrics

Query Prometheus for available metrics and identify key health indicators.

async function discoverMetrics(service) {
  const metrics = await prometheus.labelValues({ label: "__name__", match: `{service="${service}"}` });
  return metrics.filter(m => m.match(/(request|error|duration|memory|cpu)/));
}
4

Generate Dashboard

Programmatically create a Grafana dashboard with panels for each key metric.

async function createDashboard(service, metrics) {
  const panels = metrics.map((metric, i) => ({
    title: formatMetricName(metric),
    type: metric.includes("total") ? "stat" : "timeseries",
    targets: [{ expr: metric.includes("total") ? `rate(${metric}[5m])` : metric }],
    gridPos: { x: (i % 2) * 12, y: Math.floor(i / 2) * 8, w: 12, h: 8 }
  }));
  await grafana.createDashboard({ title: `${service} Overview`, panels });
}
5

Set Up Alerts

Configure Grafana alerts based on Prometheus query thresholds.

Examples

Code Examples

typescript
SLA Dashboard
async function createSLADashboard(services) {
  for (const service of services) {
    const availability = `1 - (rate(http_requests_total{service="${service}",code=~"5.."}[5m]) / rate(http_requests_total{service="${service}"}[5m]))`;
    await grafana.addPanel({ title: `${service} Availability`, expr: availability, thresholds: [{ value: 0.999, color: "green" }, { value: 0.99, color: "yellow" }] });
  }
}
Help

Troubleshooting

How do I handle high-cardinality metrics?+
Dashboard loads slowly with many panels+

Quick Info

DifficultyIntermediate
Time Estimate1 hour
Tools
Prometheus MCP ServerGrafana MCP Server

Need Integration Help?

Our team can implement this integration for you.

Get in Touch
CortexAgent Customer Service

Want to skip the form?

Our team is available to help you get started with CortexAgent.

This chat may be recorded for quality assurance. You can view our Privacy Policy.