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
This commit is contained in:
1 parent
44b7306064
commit
3546e19772
2 files changed
+15
-9
No files matched your search
@@ -1,6 +1,9 @@
|
|||||||
# Binary
|
# Binary
|
||||||
st-pierre
|
st-pierre
|
||||||
|
|
||||||
|
# Nix build result
|
||||||
|
result
|
||||||
|
|
||||||
# Environment
|
# Environment
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|||||||
@@ -78,11 +78,16 @@ func main() {
|
|||||||
|
|
||||||
streamableServer := server.NewStreamableHTTPServer(mcpServer)
|
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{
|
httpServer := &http.Server{
|
||||||
Addr: ":" + port,
|
Addr: ":" + port,
|
||||||
Handler: corsMiddleware(authHandler),
|
Handler: corsMiddleware(mux),
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("starting", zap.String("port", port))
|
logger.Info("starting", zap.String("port", port))
|
||||||
@@ -160,7 +165,11 @@ func handleStoreKnowledge(sqlite *sqliteStore, qdrant *qdrantStore, logger *zap.
|
|||||||
|
|
||||||
note, ok := args["note"].(string)
|
note, ok := args["note"].(string)
|
||||||
if !ok || note == "" {
|
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"])
|
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 {
|
func authMiddleware(token string, next http.Handler) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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"))
|
authHeader := strings.ToLower(r.Header.Get("Authorization"))
|
||||||
if !strings.HasPrefix(authHeader, "bearer ") || strings.TrimPrefix(authHeader, "bearer ") != token {
|
if !strings.HasPrefix(authHeader, "bearer ") || strings.TrimPrefix(authHeader, "bearer ") != token {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|||||||
Reference in new issue
Block a user