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..52a36090c3 --- /dev/null +++ b/examples/mcp/provisioning/datasources/pyroscope.yml @@ -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 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