package mcp import ( "net/http" "strings" ) // BearerAuth returns a middleware that enforces a static bearer token on every // request. token must be non-empty; if it is empty, every request is rejected. func BearerAuth(token string, next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if token == "" { http.Error(w, "unauthorized", http.StatusUnauthorized) return } got, ok := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer ") if !ok || got != token { http.Error(w, "unauthorized", http.StatusUnauthorized) return } next.ServeHTTP(w, r) }) }