Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions mcpgrafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
grafanaUsernameEnvVar = "GRAFANA_USERNAME"
grafanaPasswordEnvVar = "GRAFANA_PASSWORD"

grafanaURLHeader = "X-Grafana-URL"
grafanaAPIKeyHeader = "X-Grafana-API-Key"
grafanaURLHeader = "X-Grafana-URL"
grafanaServiceAccountTokenHeader = "X-Grafana-Service-Account-Token"
grafanaAPIKeyHeader = "X-Grafana-API-Key" // Deprecated: use X-Grafana-Service-Account-Token instead
)

func urlAndAPIKeyFromEnv() (string, string) {
Expand Down Expand Up @@ -68,7 +69,15 @@ func userAndPassFromEnv() *url.Userinfo {

func urlAndAPIKeyFromHeaders(req *http.Request) (string, string) {
u := strings.TrimRight(req.Header.Get(grafanaURLHeader), "/")
apiKey := req.Header.Get(grafanaAPIKeyHeader)

// Check for the new service account token header first
apiKey := req.Header.Get(grafanaServiceAccountTokenHeader)
if apiKey != "" {
return u, apiKey
}

// Fall back to the deprecated API key header
apiKey = req.Header.Get(grafanaAPIKeyHeader)
return u, apiKey
}

Expand Down
Loading