diff --git a/.kustomization.yaml b/.kustomization.yaml index ee93de0..dab798f 100644 --- a/.kustomization.yaml +++ b/.kustomization.yaml @@ -30,19 +30,12 @@ resources: - mcp-servers/high-command-mcp/service.yaml - mcp-servers/high-command-mcp/configmap.yaml - mcp-servers/high-command-mcp/ingress.yaml - - # Grafana MCP - - mcp-servers/grafana-mcp/deployment.yaml - - mcp-servers/grafana-mcp/service.yaml - - mcp-servers/grafana-mcp/configmap.yaml - - mcp-servers/grafana-mcp/ingress.yaml # Note: secrets.yaml files should be added separately and not committed to git # Uncomment and add secret files when using kustomize: # - mcp-servers/proxmox-ve-mcp/secret.yaml # - mcp-servers/unifi-network-mcp/secret.yaml # - mcp-servers/unifi-protect-mcp/secret.yaml -# - mcp-servers/grafana-mcp/secret.yaml labels: - pairs: diff --git a/CHANGELOG.md b/CHANGELOG.md index b8b5cb1..c6c9cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - unifi-manager-mcp - Removed due to container image issues +- grafana-mcp - Removed (no longer needed), including `scripts/create-grafana-mcp-token.sh` ### Fixed diff --git a/mcp-servers/grafana-mcp/README.md b/mcp-servers/grafana-mcp/README.md deleted file mode 100644 index 19e253d..0000000 --- a/mcp-servers/grafana-mcp/README.md +++ /dev/null @@ -1,149 +0,0 @@ -# Grafana MCP Server Deployment - -This directory contains the Kubernetes manifests for deploying the Grafana MCP (Model Context Protocol) server. - -## Deployment Status - -✅ **Deployed and Running** -- Namespace: `mcp-servers` -- Deployment: `grafana-mcp` (3 replicas) -- Service: `grafana-mcp` (ClusterIP on port 8000) -- Ingress: `grafana-mcp.dataknife.net` -- Health Endpoint: `/healthz` - -## Configuration - -### ConfigMap -- **GRAFANA_URL**: `https://grafana.dataknife.net` (cross-cluster access via ingress) - -### Secret (Required) -The secret `grafana-mcp-secrets` must contain: -- **GRAFANA_SERVICE_ACCOUNT_TOKEN**: Service account token for authentication -- **GRAFANA_ORG_ID**: (Optional) Organization ID for multi-org setups - -## Creating the Service Account Token - -Since automated token creation via API requires admin credentials that may not be accessible, create the token manually: - -### Option 1: Via Grafana UI (Recommended) - -1. Access Grafana at `https://grafana.dataknife.net` -2. Log in with admin credentials -3. Navigate to **Administration** → **Service Accounts** -4. Click **New service account** -5. Create service account: - - **Name**: `mcp-server` - - **Role**: `Editor` (or appropriate role based on your needs) -6. Click **Add service account** -7. In the service account details, click **Add token** → **Add service account token** -8. Name: `mcp-server-token` -9. Copy the generated token - -### Option 2: Via Grafana API - -If you have admin access to Grafana API: - -```bash -# Set variables -GRAFANA_URL="https://grafana.dataknife.net" -GRAFANA_USER="admin" -GRAFANA_PASSWORD="your-admin-password" - -# Create service account -SA_RESPONSE=$(curl -s -X POST \ - -H "Content-Type: application/json" \ - -u "$GRAFANA_USER:$GRAFANA_PASSWORD" \ - "$GRAFANA_URL/api/serviceaccounts" \ - -d '{"name":"mcp-server","role":"Editor","isDisabled":false}') - -SA_ID=$(echo "$SA_RESPONSE" | jq -r '.id') - -# Create token -TOKEN_RESPONSE=$(curl -s -X POST \ - -H "Content-Type: application/json" \ - -u "$GRAFANA_USER:$GRAFANA_PASSWORD" \ - "$GRAFANA_URL/api/serviceaccounts/$SA_ID/tokens" \ - -d '{"name":"mcp-server-token","secondsToLive":0}') - -TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.key') -echo "Token: $TOKEN" -``` - -## Updating the Secret - -**Important:** The secret is stored on the **prd-apps** cluster, not in git. Never commit secret files. - -Once you have the token, update the secret on the prd-apps cluster: - -```bash -# Switch to prd-apps cluster -kubectl config use-context prd-apps - -# Base64 encode the token -TOKEN_B64=$(echo -n "YOUR_TOKEN_HERE" | base64 -w 0) - -# Update the secret -kubectl patch secret grafana-mcp-secrets -n mcp-servers --type='json' \ - -p="[{\"op\":\"replace\",\"path\":\"/data/GRAFANA_SERVICE_ACCOUNT_TOKEN\",\"value\":\"$TOKEN_B64\"}]" - -# Restart pods to pick up the new token (on prd-apps cluster) -kubectl rollout restart deployment grafana-mcp -n mcp-servers -``` - -Or create the secret from scratch: - -```bash -# Switch to prd-apps cluster -kubectl config use-context prd-apps - -# Create/update the secret -kubectl create secret generic grafana-mcp-secrets \ - --from-literal=GRAFANA_SERVICE_ACCOUNT_TOKEN='YOUR_TOKEN_HERE' \ - --from-literal=GRAFANA_ORG_ID='' \ - -n mcp-servers \ - --dry-run=client -o yaml | kubectl apply -f - - -# Label the secret -kubectl label secret grafana-mcp-secrets -n mcp-servers \ - app=grafana-mcp component=mcp-server --overwrite -``` - -## Verification - -Check deployment status: - -```bash -# Check pods -kubectl get pods -n mcp-servers -l app=grafana-mcp - -# Check logs -kubectl logs -n mcp-servers -l app=grafana-mcp --tail=50 - -# Test health endpoint -curl http://$(kubectl get svc grafana-mcp -n mcp-servers -o jsonpath='{.spec.clusterIP}'):8000/healthz -``` - -## Required RBAC Permissions - -The service account needs appropriate permissions based on which MCP tools you plan to use. The `Editor` role provides broad access. For more granular control, see the [Grafana MCP documentation](https://github.com/grafana/mcp-grafana) for specific RBAC requirements. - -Common permissions needed: -- `datasources:read`, `datasources:query` - For querying Loki, Prometheus, etc. -- `dashboards:read`, `dashboards:write` - For dashboard operations -- `alert.rules:read`, `alert.rules:write` - For alert management -- `folders:*` - For folder operations - -## Troubleshooting - -### Pods not starting -- Check if the secret exists and contains valid token -- Verify image can be pulled: `kubectl describe pod -n mcp-servers -l app=grafana-mcp` - -### Authentication errors -- Verify the service account token is valid -- Check Grafana URL is accessible from the pod -- Ensure service account has required permissions - -### Health check failures -- Check pod logs: `kubectl logs -n mcp-servers -l app=grafana-mcp` -- Verify `/healthz` endpoint is responding diff --git a/mcp-servers/grafana-mcp/configmap.yaml b/mcp-servers/grafana-mcp/configmap.yaml deleted file mode 100644 index c689889..0000000 --- a/mcp-servers/grafana-mcp/configmap.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: grafana-mcp-config - namespace: mcp-servers - labels: - app: grafana-mcp - component: mcp-server -data: - # Using ingress URL for cross-cluster access (MCP on prd-apps, Grafana on nprd-apps) - GRAFANA_URL: "https://grafana.dataknife.net" diff --git a/mcp-servers/grafana-mcp/deployment.yaml b/mcp-servers/grafana-mcp/deployment.yaml deleted file mode 100644 index 5446df3..0000000 --- a/mcp-servers/grafana-mcp/deployment.yaml +++ /dev/null @@ -1,132 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: grafana-mcp - namespace: mcp-servers - labels: - app: grafana-mcp - version: v1 - component: mcp-server -spec: - replicas: 3 - selector: - matchLabels: - app: grafana-mcp - template: - metadata: - labels: - app: grafana-mcp - component: mcp-server - spec: - securityContext: - fsGroup: 1000 - containers: - - name: grafana-mcp - image: harbor.dataknife.net/dockerhub/grafana/mcp-grafana:1.6.3 - imagePullPolicy: IfNotPresent - - # HTTP Transport Configuration - streamable-http mode - args: - - "-t" - - "streamable-http" - - "--address" - - "0.0.0.0:8000" - - env: - - name: GRAFANA_URL - valueFrom: - configMapKeyRef: - name: grafana-mcp-config - key: GRAFANA_URL - - name: GRAFANA_SERVICE_ACCOUNT_TOKEN - valueFrom: - secretKeyRef: - name: grafana-mcp-secrets - key: GRAFANA_SERVICE_ACCOUNT_TOKEN - optional: true - - name: GRAFANA_USERNAME - valueFrom: - secretKeyRef: - name: grafana-mcp-secrets - key: GRAFANA_USERNAME - optional: true - - name: GRAFANA_PASSWORD - valueFrom: - secretKeyRef: - name: grafana-mcp-secrets - key: GRAFANA_PASSWORD - optional: true - - name: GRAFANA_ORG_ID - valueFrom: - secretKeyRef: - name: grafana-mcp-secrets - key: GRAFANA_ORG_ID - optional: true - - ports: - - name: http - containerPort: 8000 - protocol: TCP - - # tcpSocket avoids Host-allowlist 403 on kubelet httpGet (/healthz). - # Works for both pre- and post-DNS-rebinding mcp-grafana images. - livenessProbe: - tcpSocket: - port: http - initialDelaySeconds: 10 - periodSeconds: 30 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 - - readinessProbe: - tcpSocket: - port: http - initialDelaySeconds: 5 - periodSeconds: 10 - timeoutSeconds: 3 - successThreshold: 1 - failureThreshold: 2 - - # Resource Management - resources: - requests: - cpu: "100m" - memory: "128Mi" - limits: - cpu: "500m" - memory: "512Mi" - - # Security Context - securityContext: - readOnlyRootFilesystem: true - runAsNonRoot: true - runAsUser: 1000 - allowPrivilegeEscalation: false - capabilities: - drop: - - ALL - - # Volume Mounts - volumeMounts: - - name: tmp - mountPath: /tmp - - # Volumes - volumes: - - name: tmp - emptyDir: {} - - # Pod Disruption Budget - affinity: - podAntiAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 100 - podAffinityTerm: - labelSelector: - matchExpressions: - - key: app - operator: In - values: - - grafana-mcp - topologyKey: kubernetes.io/hostname diff --git a/mcp-servers/grafana-mcp/ingress.yaml b/mcp-servers/grafana-mcp/ingress.yaml deleted file mode 100644 index 9c68eab..0000000 --- a/mcp-servers/grafana-mcp/ingress.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: grafana-mcp - namespace: mcp-servers - labels: - app: grafana-mcp - component: mcp-server - managed-by: gitops - annotations: - nginx.ingress.kubernetes.io/ssl-redirect: "true" -spec: - ingressClassName: nginx - rules: - - host: grafana-mcp.dataknife.net - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: grafana-mcp - port: - number: 8000 diff --git a/mcp-servers/grafana-mcp/secret.yaml.example b/mcp-servers/grafana-mcp/secret.yaml.example deleted file mode 100644 index 3c32ca0..0000000 --- a/mcp-servers/grafana-mcp/secret.yaml.example +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: grafana-mcp-secrets - namespace: mcp-servers - labels: - app: grafana-mcp - component: mcp-server -type: Opaque -stringData: - # Service Account Token (preferred authentication method) - # Create a service account in Grafana and generate a token - GRAFANA_SERVICE_ACCOUNT_TOKEN: "" - - # Username/Password authentication (alternative to service account token) - # Note: Use either service account token OR username/password, not both - GRAFANA_USERNAME: "" - GRAFANA_PASSWORD: "" - - # Organization ID for multi-org Grafana setups (optional) - # If not specified, uses the default organization - GRAFANA_ORG_ID: "" diff --git a/mcp-servers/grafana-mcp/service.yaml b/mcp-servers/grafana-mcp/service.yaml deleted file mode 100644 index 3e37ef2..0000000 --- a/mcp-servers/grafana-mcp/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: grafana-mcp - namespace: mcp-servers - labels: - app: grafana-mcp - component: mcp-server -spec: - type: ClusterIP - ports: - - port: 8000 - targetPort: http - protocol: TCP - name: http - selector: - app: grafana-mcp diff --git a/scripts/create-grafana-mcp-token.sh b/scripts/create-grafana-mcp-token.sh deleted file mode 100755 index cb3262d..0000000 --- a/scripts/create-grafana-mcp-token.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# Script to create Grafana service account and token for MCP server -# Usage: ./scripts/create-grafana-mcp-token.sh - -set -e - -GRAFANA_URL="${GRAFANA_URL:-https://grafana.dataknife.net}" -GRAFANA_USER="${GRAFANA_USER:-admin}" -GRAFANA_PASSWORD="${GRAFANA_PASSWORD:-$(kubectl get secret grafana -n managed-syslog -o jsonpath='{.data.admin-password}' 2>/dev/null | base64 -d || echo '')}" - -if [ -z "$GRAFANA_PASSWORD" ]; then - echo "Error: GRAFANA_PASSWORD not set and could not retrieve from secret" - echo "Please set GRAFANA_PASSWORD environment variable or ensure grafana secret exists" - exit 1 -fi - -echo "Connecting to Grafana at $GRAFANA_URL..." - -# Check if service account already exists -SA_ID=$(curl -s -u "$GRAFANA_USER:$GRAFANA_PASSWORD" \ - "$GRAFANA_URL/api/serviceaccounts/search?query=mcp-server" \ - | jq -r '.serviceAccounts[]? | select(.name=="mcp-server") | .id // empty') - -if [ -z "$SA_ID" ]; then - echo "Creating service account 'mcp-server' with Editor role..." - SA_RESPONSE=$(curl -s -X POST \ - -H "Content-Type: application/json" \ - -u "$GRAFANA_USER:$GRAFANA_PASSWORD" \ - "$GRAFANA_URL/api/serviceaccounts" \ - -d '{"name":"mcp-server","role":"Editor","isDisabled":false}') - - SA_ID=$(echo "$SA_RESPONSE" | jq -r '.id // empty') - - if [ -z "$SA_ID" ] || [ "$SA_ID" = "null" ]; then - echo "Error creating service account:" - echo "$SA_RESPONSE" | jq '.' - exit 1 - fi - - echo "Service account created with ID: $SA_ID" -else - echo "Service account 'mcp-server' already exists with ID: $SA_ID" -fi - -# Create token -echo "Creating service account token..." -TOKEN_RESPONSE=$(curl -s -X POST \ - -H "Content-Type: application/json" \ - -u "$GRAFANA_USER:$GRAFANA_PASSWORD" \ - "$GRAFANA_URL/api/serviceaccounts/$SA_ID/tokens" \ - -d '{"name":"mcp-server-token","secondsToLive":0}') - -TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.key // empty') - -if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then - echo "Error creating token:" - echo "$TOKEN_RESPONSE" | jq '.' - exit 1 -fi - -echo "" -echo "==========================================" -echo "Service Account Token created successfully!" -echo "==========================================" -echo "" -echo "Token: $TOKEN" -echo "" -echo "To update the secret, run:" -echo " kubectl create secret generic grafana-mcp-secrets \\" -echo " --from-literal=GRAFANA_SERVICE_ACCOUNT_TOKEN='$TOKEN' \\" -echo " --from-literal=GRAFANA_ORG_ID='' \\" -echo " -n mcp-servers \\" -echo " --dry-run=client -o yaml | kubectl apply -f -" -echo "" -echo "Or update the existing secret:" -echo " kubectl patch secret grafana-mcp-secrets -n mcp-servers \\" -echo " --type='json' \\" -echo " -p='[{\"op\":\"replace\",\"path\":\"/data/GRAFANA_SERVICE_ACCOUNT_TOKEN\",\"value\":\"'$(echo -n "$TOKEN" | base64 -w 0)'\"}]'" -echo ""