@@ -131,6 +131,59 @@ echo "Total: ${total_elapsed} seconds"
131131touch /tmp/ready
132132echo " The OpenTelemetry collector and the Grafana LGTM stack are up and running. (created /tmp/ready)"
133133
134+ # Create a service account token and MCP config for AI tool access
135+ # Try to create SA; if it already exists (persisted data), look it up
136+ SA_RESPONSE=$( curl -sf http://127.0.0.1:3000/api/serviceaccounts -H " Content-Type: application/json" -u admin:admin -d ' {"name":"ai-tools","role":"Viewer"}' )
137+ if [ -z " $SA_RESPONSE " ]; then
138+ # SA already exists — find its ID
139+ SA_RESPONSE=$( curl -sf " http://127.0.0.1:3000/api/serviceaccounts/search?query=ai-tools" -u admin:admin)
140+ SA_ID=$( echo " $SA_RESPONSE " | grep -o ' "id":[0-9]*' | head -1 | cut -d: -f2)
141+ else
142+ SA_ID=$( echo " $SA_RESPONSE " | grep -o ' "id":[0-9]*' | head -1 | cut -d: -f2)
143+ fi
144+ if [ -n " $SA_ID " ]; then
145+ # Delete existing tokens and create a fresh one
146+ EXISTING_TOKENS=$( curl -sf " http://127.0.0.1:3000/api/serviceaccounts/${SA_ID} /tokens" -u admin:admin)
147+ for TOKEN_ID in $( echo " $EXISTING_TOKENS " | grep -o ' "id":[0-9]*' | cut -d: -f2) ; do
148+ curl -sf -X DELETE " http://127.0.0.1:3000/api/serviceaccounts/${SA_ID} /tokens/${TOKEN_ID} " -u admin:admin > /dev/null
149+ done
150+ TOKEN_RESPONSE=$( curl -sf " http://127.0.0.1:3000/api/serviceaccounts/${SA_ID} /tokens" -H " Content-Type: application/json" -u admin:admin -d ' {"name":"ai-tools-token"}' )
151+ SA_TOKEN=$( echo " $TOKEN_RESPONSE " | grep -o ' "key":"[^"]*"' | cut -d' "' -f4)
152+ if [ -n " $SA_TOKEN " ]; then
153+ echo " ${SA_TOKEN} " > /tmp/grafana-sa-token
154+ mkdir -p /etc/lgtm
155+ EXEC=" ${CONTAINER_RUNTIME:- docker} exec lgtm"
156+ cat > /etc/lgtm/mcp.json << -MCPEOF
157+ {
158+ "mcpServers": {
159+ "grafana": {
160+ "command": "uvx",
161+ "args": ["mcp-grafana"],
162+ "env": {
163+ "GRAFANA_URL": "http://localhost:3000",
164+ "GRAFANA_SERVICE_ACCOUNT_TOKEN": "${SA_TOKEN} "
165+ }
166+ },
167+ "tempo": {
168+ "url": "http://localhost:3200/api/mcp"
169+ }
170+ }
171+ }
172+ MCPEOF
173+ cat > /etc/lgtm/claude-mcp-setup.sh << -SETUPEOF
174+ #!/bin/bash
175+ # Connect Claude Code to the LGTM stack
176+ claude mcp add grafana -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_SERVICE_ACCOUNT_TOKEN=${SA_TOKEN} -- uvx mcp-grafana
177+ claude mcp add --transport http tempo http://localhost:3200/api/mcp
178+ SETUPEOF
179+ echo " "
180+ echo " AI Tool Integration (MCP):"
181+ echo " Claude Code: bash <($EXEC cat /etc/lgtm/claude-mcp-setup.sh)"
182+ echo " Other tools: $EXEC cat /etc/lgtm/mcp.json"
183+ echo " Docs: docs/mcp-integration.md"
184+ fi
185+ fi
186+
134187if [[ ${ENABLE_OBI:- false} == " true" ]]; then
135188 # Non-blocking check — don't delay readiness if OBI fails (e.g. missing capabilities)
136189 if curl -o /dev/null -sg " http://127.0.0.1:6060/metrics" -w " %{response_code}" 2> /dev/null | grep -q " 200" ; then
@@ -153,6 +206,7 @@ echo "Open ports:"
153206echo " - 4317: OpenTelemetry GRPC endpoint"
154207echo " - 4318: OpenTelemetry HTTP endpoint"
155208echo " - 3000: Grafana (http://localhost:3000). User: admin, password: admin"
209+ echo " - 3200: Tempo endpoint (MCP at http://localhost:3200/api/mcp)"
156210echo " - 4040: Pyroscope endpoint"
157211echo " - 9090: Prometheus endpoint"
158212
0 commit comments