# Grafana MCP Server (`constant_quadruped/grafana-mcp-server`) Actor

Connect AI agents to Grafana via MCP. Search dashboards, query Prometheus/Loki, manage alerts, create dashboards, and monitor data sources. 25+ tools for complete Grafana control through natural language.

- **URL**: https://apify.com/constant\_quadruped/grafana-mcp-server.md
- **Developed by:** [CQ](https://apify.com/constant_quadruped) (community)
- **Categories:** MCP servers, Developer tools, AI
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Grafana MCP Server

Connect AI agents to your Grafana instance via the Model Context Protocol (MCP). Search and manage dashboards, query data sources, inspect alerts, organize folders, and create annotations through a standardized MCP interface.

This Actor is an MCP **server**. Its primary output is MCP tool/resource/prompt responses returned to a connected MCP client, not a scraped dataset. The Actor also writes a small operational log to its default dataset (see [Output](#output)).

### Features

- **Dashboard Management**: Search, view, create, and delete dashboards
- **Data Source Operations**: List, get, test, create, delete, and query data sources (Prometheus, Loki, InfluxDB, PostgreSQL, MySQL, MSSQL, Elasticsearch)
- **Alert Monitoring**: List alert rules, get a rule by UID, list alert instances, and pause/unpause an alert
- **Folder Organization**: List, get, create, and delete folders
- **Annotations**: List, create, and delete annotations for events and deployments
- **User & Org Info**: Get the current user, list organization users, and get the current organization

### Input Configuration

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `grafanaUrl` | string | Required to connect | Your Grafana instance URL, e.g. `https://mycompany.grafana.net` (Grafana Cloud) or `http://localhost:3000` (self-hosted). Must start with `http://` or `https://`. |
| `grafanaApiToken` | string (secret) | Required to connect | Service account token used as a Bearer token. Recommended role: Editor or Admin (Admin is needed for data source / user / org operations). |
| `grafanaOrgId` | integer | No | Organization ID for multi-organization setups. Sent as the `X-Grafana-Org-Id` header when provided. Leave empty for single-org instances. |

> Note: The input schema marks no field as strictly required. If you start the Actor **without** `grafanaUrl` and `grafanaApiToken`, it does not error — it publishes its server capabilities (tool names, resources, setup hint) to the dataset and exits cleanly. Provide both values to actually connect and serve tool calls.

#### Authentication

The server authenticates to Grafana with the service account token as an HTTP Bearer token (`Authorization: Bearer <token>`). No username/password is used. When `grafanaOrgId` is set, the `X-Grafana-Org-Id` header is added to each request. A trailing slash on `grafanaUrl` is stripped automatically.

#### Getting a Grafana API Token

1. In Grafana, go to **Administration** > **Service Accounts**
2. Click **Add service account**
3. Give it a name and select **Editor** or **Admin** role
4. Click **Add service account token** and copy the generated token

### Available Tools

#### Health & Status

- `grafana_health` - Check instance health, version, and database status

#### Dashboards

- `grafana_search_dashboards` - Search dashboards by query, tag, type, or folder IDs
- `grafana_get_dashboard` - Get full dashboard configuration by UID
- `grafana_create_dashboard` - Create a new dashboard with panels
- `grafana_delete_dashboard` - Delete a dashboard by UID

#### Data Sources

- `grafana_list_datasources` - List all configured data sources
- `grafana_get_datasource` - Get data source details by UID or name
- `grafana_test_datasource` - Test data source connectivity (health check)
- `grafana_create_datasource` - Add a new data source
- `grafana_delete_datasource` - Delete a data source by UID
- `grafana_query_datasource` - Execute a query (PromQL, LogQL, or SQL) against a data source

#### Alerts

- `grafana_list_alert_rules` - List all alert rules
- `grafana_get_alert_rule` - Get alert rule details by UID
- `grafana_list_alert_instances` - View current alert states
- `grafana_pause_alert` - Pause or unpause an alert by ID

#### Folders

- `grafana_list_folders` - List all folders
- `grafana_get_folder` - Get folder details by UID
- `grafana_create_folder` - Create a new folder
- `grafana_delete_folder` - Delete a folder by UID

#### Annotations

- `grafana_list_annotations` - List annotations with optional filters
- `grafana_create_annotation` - Create an annotation
- `grafana_delete_annotation` - Delete an annotation by ID

#### Users & Organization

- `grafana_get_current_user` - Get the authenticated user's info
- `grafana_list_org_users` - List members of the current organization
- `grafana_get_current_org` - Get current organization details

### Resources

The server exposes these MCP resources (read-only JSON):

- `grafana://dashboards` - All dashboards
- `grafana://datasources` - All data sources
- `grafana://folders` - All folders
- `grafana://alerts` - Current alert instances
- `grafana://health` - Instance health

### Prompts

Pre-built MCP prompts for common tasks:

- `dashboard-overview` - Get an overview of all dashboards
- `alert-status` - Check current alert status
- `datasource-health` - Verify data source connectivity
- `create-dashboard-template` - Template for a new monitoring dashboard (arguments: `service_name`, `datasource`)

### Example Usage

#### Query Prometheus Metrics

```json
{
  "tool": "grafana_query_datasource",
  "arguments": {
    "datasourceUid": "prometheus-uid",
    "query": "rate(http_requests_total[5m])",
    "from": 1703980800000,
    "to": 1704067200000
  }
}
```

#### Create a Dashboard

```json
{
  "tool": "grafana_create_dashboard",
  "arguments": {
    "title": "Service Monitoring",
    "tags": ["production", "api"],
    "panels": [
      {
        "title": "Request Rate",
        "type": "timeseries",
        "datasource": "Prometheus",
        "targets": [{"expr": "rate(http_requests_total[5m])"}]
      }
    ]
  }
}
```

#### Check Alert Status

```json
{
  "tool": "grafana_list_alert_instances",
  "arguments": {}
}
```

### Output

Being an MCP server, the substantive output is the MCP responses returned to the connected client. In addition, the Actor writes an operational log to its default dataset:

- **Tool-call records**: `timestamp`, `tool`, `success`, `duration` (ms), and `error` (present only on failure)
- **Connection record**: a `connection_verified` entry with `grafanaVersion` and `database` on successful connect
- **Capabilities record**: a `server_info` entry (tool names, resources, setup hint) when the Actor is started with no credentials

### Pricing

This Actor uses Apify's pay-per-event pricing model — you are billed per billable event (e.g. per tool call) rather than by compute time. See the Actor's page in the Apify Store for the current per-event rates.

### Limitations

- **Requires a reachable Grafana instance and a valid service account token.** If the health check fails on start (unreachable URL, bad token, network issue), the run is stopped with a descriptive error.
- **Grafana version / API**: Targets the Grafana HTTP API. Alert operations use the unified alerting endpoints (`/api/ruler/...`, `/api/v1/provisioning/...`, `/api/alerts`), so a modern Grafana with unified alerting is expected. `grafana_pause_alert` uses the legacy `/api/alerts/{id}/pause` endpoint and may not apply to Grafana-managed unified alert rules.
- **Permissions scope**: Read operations work with an Editor token, but data source creation/deletion, user/org listing, and some admin endpoints require an Admin-scoped service account token. Insufficient permissions surface as Grafana API errors in the tool response.
- **No pagination / rate-limit handling**: Listing tools (dashboards, folders, annotations, org users) returns whatever the Grafana API returns in a single request; there is no automatic pagination or retry/backoff.
- **Transport**: The server communicates over stdio (standard MCP transport). It does not implement authentication or multi-tenant isolation of its own — access control is delegated entirely to the supplied Grafana token.
- **Scope**: This Actor does not render or export dashboard images, manage Grafana users/teams beyond listing, or configure notification/contact points.

### Requirements

- Grafana instance (Cloud or self-hosted) reachable over the network
- Service account token with appropriate permissions (Editor or Admin)

# Actor input Schema

## `grafanaUrl` (type: `string`):

Your Grafana instance URL. For Grafana Cloud, use format: https://your-org.grafana.net. For self-hosted, use your server address like https://grafana.example.com or http://localhost:3000

## `grafanaApiToken` (type: `string`):

Service account token with Editor or Admin role. Create at: Administration → Service Accounts → Add service account → Add token

## `grafanaOrgId` (type: `integer`):

Optional: Grafana organization ID. Only needed for multi-organization setups. Leave empty for single-org instances.

## Actor input object example

```json
{
  "grafanaUrl": "https://mycompany.grafana.net"
}
```

# Actor output Schema

## `toolCallsDataset` (type: `string`):

Dataset containing all MCP tool calls with timestamp, tool name, success status, duration, and any errors

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("constant_quadruped/grafana-mcp-server").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("constant_quadruped/grafana-mcp-server").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call constant_quadruped/grafana-mcp-server --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=constant_quadruped/grafana-mcp-server",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/t8AjADoV7jgyDL2BE/builds/RY7gZnQVHlhjSzhyd/openapi.json
