Skip to content

feat: Create Grafana MCP example #4290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data-compactor/
data-metastore/
.DS_Store
**/dist
**/.env

# IDE
.cursor
Expand Down
2 changes: 2 additions & 0 deletions examples/mcp/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_ORGANIZATION_ID=""
OPENAI_API_KEY=""
76 changes: 76 additions & 0 deletions examples/mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Using Grafana MCP server with Pyroscope

This example demonstrates how to use the Grafana MCP server with Pyroscope.

## Quickstart

Before running any code, download the latest Grafana MCP server. For a complete
list of all possible installation options, see https://github.com/grafana/mcp-grafana?tab=readme-ov-file#usage.
To quickly get started, it's easiest to install the server via `go install`.

```shell
go install github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest
```

Verify the installation worked by running

```shell
mcp-grafana -h
```

To run the example, first copy the `.env.template` file to a `.env` file.

```shell
cp .env.template .env
```

Then populate the `.env` file with the relevant tokens.

Next, start the services with Docker Compose.

```shell
docker compose up
```

This will start a Grafana instance running at http://localhost:3000 and a
Pyroscope instance running at http://localhost:4040.

We need to get an API key for the local Grafana instance. To do this, follow
these steps:

1. Open http://localhost:3000/org/serviceaccounts
1. Create a service account with a "Admin" role
1. Click "Add service account token"
1. Generate and copy the token
1. Save the copied token for the next steps.

Finally, configure your client to use the MCP server. For example, a Claude
configuration would look like this

```json
{
"mcpServers": {
"grafana": {
"command": "mcp-grafana",
"args": [],
"env": {
"GRAFANA_URL": "http://localhost:3000",
"GRAFANA_API_KEY": "<your service account token>"
}
}
}
}
```

Once you saved your client configuration file, you can begin using your LLM to
fetch data from Grafana. Start with asking something like:

> Can you list all the data sources in my Grafana instance?

If everything is set up correctly, the LLM should identify two data sources:
Prometheus and Pyroscope. From here, you can ask for information about Pyroscope
like:

> Can you list all the service names in Pyroscope?

Happy prompting!
30 changes: 30 additions & 0 deletions examples/mcp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
grafana:
image: grafana/grafana:latest
environment:
GF_AUTH_ANONYMOUS_ENABLED: true
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
GF_AUTH_DISABLE_LOGIN_FORM: true
GF_INSTALL_PLUGINS: grafana-llm-app
OPENAI_API_KEY: $OPENAI_API_KEY
OPENAI_ORGANIZATION_ID: $OPENAI_ORGANIZATION_ID
volumes:
- ./provisioning:/etc/grafana/provisioning
ports:
- 3000:3000
depends_on:
- pyroscope
- qdrant

pyroscope:
image: grafana/pyroscope:latest
ports:
- 4040:4040

qdrant:
image: qdrant/qdrant
volumes:
- qdrant-storage:/qdrant/storage

volumes:
qdrant-storage:
22 changes: 22 additions & 0 deletions examples/mcp/provisioning/datasources/pyroscope.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: 1
datasources:
- uid: local-pyroscope
type: grafana-pyroscope-datasource
name: Pyroscope
url: http://pyroscope:4040
jsonData:
keepCookies: [pyroscope_git_session]
- uid: local-prometheus
type: prometheus
name: Prometheus
access: proxy
url: http://host.docker.internal:9099
basicAuth: true
basicAuthUser: admin
jsonData:
manageAlerts: true
prometheusType: Prometheus
prometheusVersion: 2.40.0
secureJsonData:
basicAuthPassword: admin
21 changes: 21 additions & 0 deletions examples/mcp/provisioning/plugins/pyroscope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: 1

apps:
- type: 'grafana-llm-app'
disabled: false
jsonData:
openAI:
provider: openai
url: https://api.openai.com
organizationId: $OPENAI_ORGANIZATION_ID
vector:
enabled: true
model: text-embedding-ada-002
embed:
type: openai
store:
type: qdrant
qdrant:
address: qdrant:6334
secureJsonData:
openAIKey: $OPENAI_API_KEY
Loading