package api import ( "context" "log" "net/http" "time" "github.com/danielgtaylor/huma/v2" "github.com/modelcontextprotocol/registry/internal/api/router" "github.com/modelcontextprotocol/registry/internal/config" "github.com/modelcontextprotocol/registry/internal/service" "github.com/modelcontextprotocol/registry/internal/telemetry" ) // Server represents the HTTP server type Server struct { config *config.Config registry service.RegistryService humaAPI huma.API server *http.Server } // NewServer creates a new HTTP server func NewServer(cfg *config.Config, registryService service.RegistryService, metrics *telemetry.Metrics) *Server { // Create HTTP mux and Huma API mux := http.NewServeMux() api := router.NewHumaAPI(cfg, registryService, mux, metrics) server := &Server{ config: cfg, registry: registryService, humaAPI: api, server: &http.Server{ Addr: cfg.ServerAddress, Handler: mux, ReadHeaderTimeout: 10 * time.Second, }, } return server } // Start begins listening for incoming HTTP requests func (s *Server) Start() error { log.Printf("HTTP server starting on %s", s.config.ServerAddress) return s.server.ListenAndServe() } // Shutdown gracefully shuts down the server func (s *Server) Shutdown(ctx context.Context) error { return s.server.Shutdown(ctx) }