From fabd0dda799af3001e969a560dded9a8f7dbad10 Mon Sep 17 00:00:00 2001 From: bryanhuhta Date: Wed, 9 Jul 2025 19:06:52 -0700 Subject: [PATCH 1/2] Create Grafana MCP example --- .gitignore | 1 + examples/mcp/.env.template | 2 + examples/mcp/README.md | 76 +++++++++++++++++++ examples/mcp/docker-compose.yml | 30 ++++++++ .../provisioning/datasources/pyroscope.yml | 27 +++++++ .../mcp/provisioning/plugins/pyroscope.yaml | 21 +++++ 6 files changed, 157 insertions(+) create mode 100644 examples/mcp/.env.template create mode 100644 examples/mcp/README.md create mode 100644 examples/mcp/docker-compose.yml create mode 100644 examples/mcp/provisioning/datasources/pyroscope.yml create mode 100644 examples/mcp/provisioning/plugins/pyroscope.yaml diff --git a/.gitignore b/.gitignore index a599f3ed8c..c032d358bc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ data-compactor/ data-metastore/ .DS_Store **/dist +**/.env # IDE .cursor diff --git a/examples/mcp/.env.template b/examples/mcp/.env.template new file mode 100644 index 0000000000..6fe982e561 --- /dev/null +++ b/examples/mcp/.env.template @@ -0,0 +1,2 @@ +OPENAI_ORGANIZATION_ID="" +OPENAI_API_KEY="" diff --git a/examples/mcp/README.md b/examples/mcp/README.md new file mode 100644 index 0000000000..f07dc85f83 --- /dev/null +++ b/examples/mcp/README.md @@ -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": "" + } + } + } +} +``` + +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! diff --git a/examples/mcp/docker-compose.yml b/examples/mcp/docker-compose.yml new file mode 100644 index 0000000000..1f0dc9d3d4 --- /dev/null +++ b/examples/mcp/docker-compose.yml @@ -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: diff --git a/examples/mcp/provisioning/datasources/pyroscope.yml b/examples/mcp/provisioning/datasources/pyroscope.yml new file mode 100644 index 0000000000..ec2b5b734f --- /dev/null +++ b/examples/mcp/provisioning/datasources/pyroscope.yml @@ -0,0 +1,27 @@ +--- +apiVersion: 1 +datasources: + - uid: local-pyroscope + type: grafana-pyroscope-datasource + name: Pyroscope + url: http://pyroscope:4040 + jsonData: + keepCookies: [pyroscope_git_session] + # Uncomment these if using with Grafana Cloud + # basicAuth: true + # basicAuthUser: '123456' + # secureJsonData: + # basicAuthPassword: PASSWORD + - uid: local-prometheus + type: prometheus + name: Prometheus + access: proxy + url: http://host.docker.internal:9099 + basicAuth: true #username: admin, password: admin + basicAuthUser: admin + jsonData: + manageAlerts: true + prometheusType: Prometheus #Cortex | Mimir | Prometheus | Thanos + prometheusVersion: 2.40.0 + secureJsonData: + basicAuthPassword: admin #https://grafana.com/docs/grafana/latest/administration/provisioning/#using-environment-variables diff --git a/examples/mcp/provisioning/plugins/pyroscope.yaml b/examples/mcp/provisioning/plugins/pyroscope.yaml new file mode 100644 index 0000000000..d097855827 --- /dev/null +++ b/examples/mcp/provisioning/plugins/pyroscope.yaml @@ -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 From 7cf504269c95fa4cecabf3588a8557259a39d2d8 Mon Sep 17 00:00:00 2001 From: bryanhuhta Date: Wed, 9 Jul 2025 19:08:56 -0700 Subject: [PATCH 2/2] Remove unnecessary comments --- examples/mcp/provisioning/datasources/pyroscope.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/examples/mcp/provisioning/datasources/pyroscope.yml b/examples/mcp/provisioning/datasources/pyroscope.yml index ec2b5b734f..52a36090c3 100644 --- a/examples/mcp/provisioning/datasources/pyroscope.yml +++ b/examples/mcp/provisioning/datasources/pyroscope.yml @@ -7,21 +7,16 @@ datasources: url: http://pyroscope:4040 jsonData: keepCookies: [pyroscope_git_session] - # Uncomment these if using with Grafana Cloud - # basicAuth: true - # basicAuthUser: '123456' - # secureJsonData: - # basicAuthPassword: PASSWORD - uid: local-prometheus type: prometheus name: Prometheus access: proxy url: http://host.docker.internal:9099 - basicAuth: true #username: admin, password: admin + basicAuth: true basicAuthUser: admin jsonData: manageAlerts: true - prometheusType: Prometheus #Cortex | Mimir | Prometheus | Thanos + prometheusType: Prometheus prometheusVersion: 2.40.0 secureJsonData: - basicAuthPassword: admin #https://grafana.com/docs/grafana/latest/administration/provisioning/#using-environment-variables + basicAuthPassword: admin