NewHumaAPI creates a new Huma API with all routes registered
(cfg *config.Config, registry service.RegistryService, mux *http.ServeMux, metrics *telemetry.Metrics, versionInfo *v0.VersionBody)
| 158 | |
| 159 | // NewHumaAPI creates a new Huma API with all routes registered |
| 160 | func NewHumaAPI(cfg *config.Config, registry service.RegistryService, mux *http.ServeMux, metrics *telemetry.Metrics, versionInfo *v0.VersionBody) huma.API { |
| 161 | // Create Huma API configuration |
| 162 | humaConfig := huma.DefaultConfig("Official MCP Registry", "1.0.0") |
| 163 | humaConfig.Info.Description = "A community driven registry service for Model Context Protocol (MCP) servers.\n\n[GitHub repository](https://github.com/modelcontextprotocol/registry) | [Documentation](https://github.com/modelcontextprotocol/registry/tree/main/docs)" |
| 164 | // Disable $schema property in responses: https://github.com/danielgtaylor/huma/issues/230 |
| 165 | humaConfig.CreateHooks = []func(huma.Config) huma.Config{} |
| 166 | |
| 167 | // Create a new API using humago adapter for standard library |
| 168 | api := humago.New(mux, humaConfig) |
| 169 | |
| 170 | // Add OpenAPI tag metadata with descriptions |
| 171 | api.OpenAPI().Tags = []*huma.Tag{ |
| 172 | { |
| 173 | Name: "servers", |
| 174 | Description: "Operations for discovering and retrieving MCP servers", |
| 175 | }, |
| 176 | { |
| 177 | Name: "publish", |
| 178 | Description: "Operations for publishing MCP servers to the registry", |
| 179 | }, |
| 180 | { |
| 181 | Name: "auth", |
| 182 | Description: "Authentication operations for obtaining tokens to publish servers", |
| 183 | }, |
| 184 | { |
| 185 | Name: "admin", |
| 186 | Description: "Administrative operations for managing servers (requires elevated permissions)", |
| 187 | }, |
| 188 | { |
| 189 | Name: "health", |
| 190 | Description: "Health check endpoint for monitoring service availability", |
| 191 | }, |
| 192 | { |
| 193 | Name: "ping", |
| 194 | Description: "Simple ping endpoint for testing connectivity", |
| 195 | }, |
| 196 | { |
| 197 | Name: "version", |
| 198 | Description: "Version information endpoint for retrieving build and version details", |
| 199 | }, |
| 200 | } |
| 201 | |
| 202 | // Add metrics middleware with options |
| 203 | api.UseMiddleware(MetricTelemetryMiddleware(metrics, |
| 204 | WithSkipPaths("/health", "/metrics", "/ping", "/docs"), |
| 205 | )) |
| 206 | |
| 207 | // Register routes for all API versions |
| 208 | RegisterV0Routes(api, cfg, registry, metrics, versionInfo) |
| 209 | RegisterV0_1Routes(api, cfg, registry, metrics, versionInfo) |
| 210 | |
| 211 | // Add /metrics for Prometheus metrics using promhttp |
| 212 | mux.Handle("/metrics", metrics.PrometheusHandler()) |
| 213 | |
| 214 | // Add UI and 404 handler for all other routes |
| 215 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 216 | if r.URL.Path == "/" { |
| 217 | // Serve UI at root. The page renders publisher-controlled content |
no test coverage detected
searching dependent graphs…