diff --git a/pkg/http/authorization.go b/pkg/http/authorization.go index c517cb72..7ef98082 100644 --- a/pkg/http/authorization.go +++ b/pkg/http/authorization.go @@ -23,7 +23,7 @@ const ( func AuthorizationMiddleware(requireOAuth bool, serverURL string, mcpServer *mcp.Server) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/healthz" || r.URL.Path == "/.well-known/oauth-protected-resource" { + if r.URL.Path == healthEndpoint || r.URL.Path == oauthProtectedResourceEndpoint { next.ServeHTTP(w, r) return } diff --git a/pkg/http/http.go b/pkg/http/http.go index 02f0f060..01944af9 100644 --- a/pkg/http/http.go +++ b/pkg/http/http.go @@ -16,7 +16,13 @@ import ( "github.com/manusa/kubernetes-mcp-server/pkg/mcp" ) -const oauthProtectedResourceEndpoint = "/.well-known/oauth-protected-resource" +const ( + oauthProtectedResourceEndpoint = "/.well-known/oauth-protected-resource" + healthEndpoint = "/healthz" + mcpEndpoint = "/mcp" + sseEndpoint = "/sse" + sseMessageEndpoint = "/message" +) func Serve(ctx context.Context, mcpServer *mcp.Server, staticConfig *config.StaticConfig) error { mux := http.NewServeMux() @@ -32,10 +38,10 @@ func Serve(ctx context.Context, mcpServer *mcp.Server, staticConfig *config.Stat sseServer := mcpServer.ServeSse(staticConfig.SSEBaseURL, httpServer) streamableHttpServer := mcpServer.ServeHTTP(httpServer) - mux.Handle("/sse", sseServer) - mux.Handle("/message", sseServer) - mux.Handle("/mcp", streamableHttpServer) - mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + mux.Handle(sseEndpoint, sseServer) + mux.Handle(sseMessageEndpoint, sseServer) + mux.Handle(mcpEndpoint, streamableHttpServer) + mux.HandleFunc(healthEndpoint, func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }) mux.HandleFunc(oauthProtectedResourceEndpoint, func(w http.ResponseWriter, r *http.Request) {