Skip to main content
Glama
grafana

Grafana

Official
by grafana
cloud_testing_utils.go1.88 kB
//go:build cloud // +build cloud package tools import ( "context" "os" "strings" "testing" mcpgrafana "github.com/grafana/mcp-grafana" ) // createCloudTestContext creates a context with a Grafana URL, Grafana service account token and // Grafana client for cloud integration tests. // The test will be skipped if required environment variables are not set. // testName is used to customize the skip message (e.g. "OnCall", "Sift", "Incident") // urlEnv and apiKeyEnv specify the environment variable names for the Grafana URL and API key (deprecated). // The function will automatically try the new SERVICE_ACCOUNT_TOKEN pattern first, then fall back to API_KEY. func createCloudTestContext(t *testing.T, testName, urlEnv, apiKeyEnv string) context.Context { ctx := context.Background() grafanaURL := os.Getenv(urlEnv) if grafanaURL == "" { t.Skipf("%s environment variable not set, skipping cloud %s integration tests", urlEnv, testName) } // Try the new service account token environment variable first serviceAccountTokenEnv := strings.Replace(apiKeyEnv, "API_KEY", "SERVICE_ACCOUNT_TOKEN", 1) grafanaApiKey := os.Getenv(serviceAccountTokenEnv) if grafanaApiKey == "" { // Fall back to the deprecated API key environment variable grafanaApiKey = os.Getenv(apiKeyEnv) if grafanaApiKey != "" { t.Logf("Warning: %s is deprecated, please use %s instead", apiKeyEnv, serviceAccountTokenEnv) } } if grafanaApiKey == "" { t.Skipf("Neither %s nor %s environment variables are set, skipping cloud %s integration tests", serviceAccountTokenEnv, apiKeyEnv, testName) } client := mcpgrafana.NewGrafanaClient(ctx, grafanaURL, grafanaApiKey, nil, 0) config := mcpgrafana.GrafanaConfig{ URL: grafanaURL, APIKey: grafanaApiKey, } ctx = mcpgrafana.WithGrafanaConfig(ctx, config) ctx = mcpgrafana.WithGrafanaClient(ctx, client) return ctx }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/grafana/mcp-grafana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server