Skip to content

Commit d423d3e

Browse files
authored
refactor(streamable): /mcp and /health endpoints (#32)
move the MCP endpoint to `/mcp` and add an `/health` endpoint for health checks Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
1 parent 2f60f9d commit d423d3e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

cmd/start_server.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log/slog"
78
"net/http"
@@ -74,12 +75,23 @@ var startServerCmd = &cobra.Command{
7475
return fmt.Errorf("failed to serve on stdio: %v", err.Error())
7576
}
7677
default:
77-
handler := mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
78+
mux := http.NewServeMux()
79+
// MCP endpoint
80+
mux.Handle("/mcp", mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
7881
return srv
79-
}, nil)
82+
}, nil))
83+
// HealthCheck endpoint.
84+
mux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
85+
w.Header().Set("Content-Type", "application/json")
86+
json.NewEncoder(w).Encode(map[string]string{ //nolint:errcheck
87+
"status": "healthy",
88+
"time": time.Now().Format(time.RFC3339),
89+
})
90+
})
91+
8092
server := &http.Server{
8193
Addr: listen,
82-
Handler: handler,
94+
Handler: mux,
8395
ReadTimeout: 15 * time.Second,
8496
WriteTimeout: 15 * time.Second,
8597
IdleTimeout: 60 * time.Second,

test/e2e/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func newHTTPSession(mcpServerListen string, mcpServerDebug bool, argocdURL strin
245245
cl := mcp.NewClient(&mcp.Implementation{Name: "e2e-test-client", Version: "v1.0.0"}, nil)
246246
session, err := cl.Connect(ctx, &mcp.StreamableClientTransport{
247247
MaxRetries: 5,
248-
Endpoint: fmt.Sprintf("http://%s", os.Getenv("MCP_SERVER_LISTEN")),
248+
Endpoint: fmt.Sprintf("http://%s/mcp", os.Getenv("MCP_SERVER_LISTEN")),
249249
}, nil)
250250
require.NoError(t, err)
251251
return session, func() {

0 commit comments

Comments
 (0)