Fixes #264. Adds endpoints: ``` /v0/auth/github # exchange a github token for a registry token that gives you access to namespaces io.github.username and io.github.org for your orgs /v0/auth/none # get a registry token for namespace io.modelcontextprotocol.anonymous (only for testing/local dev purposes) ``` Updates `/v0/publish` to accept one of these registry tokens. ## Motivation and Context See #264 ## How Has This Been Tested? - Running locally and getting a token from `/v0/auth/none` and then publishing to `/v0/publish` - Updating the integration tests that get a token and then publish, and them passing ## Breaking Changes This is a breaking change to the auth API. This is fine for registry given it's not deployed yet. ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [x] I have added appropriate error handling - [x] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: adam jones <domdomegg@users.noreply.github.com>
37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
// Package router contains API routing logic
|
|
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/danielgtaylor/huma/v2"
|
|
"github.com/danielgtaylor/huma/v2/adapters/humago"
|
|
"github.com/modelcontextprotocol/registry/internal/config"
|
|
"github.com/modelcontextprotocol/registry/internal/service"
|
|
)
|
|
|
|
// NewHumaAPI creates a new Huma API with all routes registered
|
|
//
|
|
//nolint:ireturn // huma.API is the expected interface type for Huma APIs
|
|
func NewHumaAPI(cfg *config.Config, registry service.RegistryService, mux *http.ServeMux) huma.API {
|
|
// Create Huma API configuration
|
|
humaConfig := huma.DefaultConfig("MCP Registry API", "1.0.0")
|
|
humaConfig.Info.Description = "A community driven registry service for Model Context Protocol (MCP) servers."
|
|
// Disable $schema property in responses: https://github.com/danielgtaylor/huma/issues/230
|
|
humaConfig.CreateHooks = []func(huma.Config) huma.Config{}
|
|
|
|
// Create a new API using humago adapter for standard library
|
|
api := humago.New(mux, humaConfig)
|
|
|
|
// Register routes for all API versions
|
|
RegisterV0Routes(api, cfg, registry)
|
|
|
|
// Add redirect from / to /docs
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/" {
|
|
http.Redirect(w, r, "/docs", http.StatusMovedPermanently)
|
|
}
|
|
})
|
|
|
|
return api
|
|
}
|