From 3546e1977229b6d47f2ff47eda4217a83cd4ccbe Mon Sep 17 00:00:00 2001 From: didier amyot Date: Wed, 3 Jun 2026 19:29:46 -0400 Subject: [PATCH] Serve MCP at /mcp, keep /health at root - Route MCP streamable handler to /mcp via http.ServeMux - Move /health to a dedicated mux route (no auth required) - Simplify authMiddleware by removing /health special case - Apply CORS middleware at the mux level - Ignore nix build result symlink --- .gitignore | 3 +++ main.go | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 0913e80..c839cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Binary st-pierre +# Nix build result +result + # Environment .env diff --git a/main.go b/main.go index 5520848..6431291 100644 --- a/main.go +++ b/main.go @@ -78,11 +78,16 @@ func main() { streamableServer := server.NewStreamableHTTPServer(mcpServer) - authHandler := authMiddleware(token, streamableServer) + mux := http.NewServeMux() + mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) + }) + mux.Handle("/mcp", authMiddleware(token, streamableServer)) httpServer := &http.Server{ Addr: ":" + port, - Handler: corsMiddleware(authHandler), + Handler: corsMiddleware(mux), } logger.Info("starting", zap.String("port", port)) @@ -160,7 +165,11 @@ func handleStoreKnowledge(sqlite *sqliteStore, qdrant *qdrantStore, logger *zap. note, ok := args["note"].(string) if !ok || note == "" { - return mcp.NewToolResultError("note is required and must be a non-empty string"), nil + if content, ok := args["content"].(string); ok && content != "" { + note = content + } else { + return mcp.NewToolResultError("note (or content) is required and must be a non-empty string"), nil + } } repos := parseStringSlice(args["repos"]) @@ -238,12 +247,6 @@ func handleSearchKnowledge(sqlite *sqliteStore, qdrant *qdrantStore) server.Tool func authMiddleware(token string, next http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/health" { - w.WriteHeader(http.StatusOK) - w.Write([]byte("ok")) - return - } - authHeader := strings.ToLower(r.Header.Get("Authorization")) if !strings.HasPrefix(authHeader, "bearer ") || strings.TrimPrefix(authHeader, "bearer ") != token { w.Header().Set("Content-Type", "application/json")