MCPcopy
hub / github.com/modelcontextprotocol/registry / NewHumaAPI

Function NewHumaAPI

internal/api/router/router.go:160–251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

158
159// NewHumaAPI creates a new Huma API with all routes registered
160func 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

Callers 1

NewServerFunction · 0.92

Calls 8

GetUIHTMLFunction · 0.92
WithSkipPathsFunction · 0.85
RegisterV0RoutesFunction · 0.85
RegisterV0_1RoutesFunction · 0.85
handle404Function · 0.85
PrometheusHandlerMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…