Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions pkg/mcp-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func Run(
router := gin.New()
router.SetTrustedProxies(trustedProxy)

router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})

router.Use(ginzap.Ginzap(logger, time.RFC3339, true))
router.Use(ginzap.RecoveryWithZap(logger, true))
store := cookie.NewStore(secret)
Expand Down
29 changes: 29 additions & 0 deletions pkg/mcp-proxy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package mcpproxy

import (
"crypto/rsa"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
"github.com/sigbit/mcp-auth-proxy/pkg/proxy"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -67,3 +70,29 @@ func TestRun_PassesHTTPStreamingOnlyToProxyRouter(t *testing.T) {
require.Contains(t, err.Error(), "failed to create proxy router")
require.True(t, streamingOnlyReceived, "httpStreamingOnly should be forwarded to proxy router")
}

func TestHealthzEndpoint(t *testing.T) {
gin.SetMode(gin.TestMode)
router := gin.New()

// Register healthz before auth middleware, same as in Run()
router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})

// Add a catch-all that returns 401 to simulate auth middleware
router.Use(func(c *gin.Context) {
c.AbortWithStatus(http.StatusUnauthorized)
})

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/healthz", nil)
router.ServeHTTP(w, req)

require.Equal(t, http.StatusOK, w.Code)

var body map[string]string
err := json.Unmarshal(w.Body.Bytes(), &body)
require.NoError(t, err)
require.Equal(t, "ok", body["status"])
}
Loading