Allow for vendor extensions on servers (#298)

<!-- Provide a brief summary of your changes -->
This PR serves as a placeholder and brings together all of the changes
related to supporting vendor extensions passed through the API. The idea
is to have a single place to track and review the work as it comes
together (even if it’s still a bit of a work in progress).

**The changes in this PR cover:**
* Updates on the data model
* Updates on both databases (in-memory and postgresql), added a new
table to PSQL for tracking the extensions leaving the server table only
for the clean server.json properties
* Updates the seed.json file (thus the big line change)
* Adds a seed-migrate tool to help migrating an existing seed file to
the new format
* Updates the seed import mechanism to support this
* Updates the existing tests - unit, integration and validation tests
* Adds the publish handler to the OpenAPI spec (it was missing)
* Fixes linting errors
* Updates on the API side on (publish, list, get) to support the new
format of `ServerResponse` -
```
{
  "server": {},
  "x-io.modelcontextprotocol.registry": {}, /*not available for publish since this gets populated by the registry*/
  "x-publisher": {}
}
```

## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Motivated by the discussions in:
https://github.com/modelcontextprotocol/registry/discussions/284

## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Locally and by running all of the tests

## Breaking Changes
<!-- Will users need to update their code or configurations? -->
Yes, it changes both the API and the format of the seed file
 
## 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)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

---

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Co-authored-by: adam jones <domdomegg+git@gmail.com>
This commit is contained in:
Radoslav Dimitrov 2025-08-23 11:59:03 +03:00 • committed by GitHub
commit 8d7e471fd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19980 additions and 15589 deletions

View file

@ -18,10 +18,9 @@ type fakeRegistryService struct {
//
//nolint:ireturn // Factory function intentionally returns interface for dependency injection
func NewFakeRegistryService() RegistryService {
// Sample registry entries with updated model structure
registries := []*model.Server{
// Sample registry entries with updated model structure using ServerDetail
serverDetails := []*model.ServerDetail{
{
ID: uuid.New().String(),
Name: "bluegreen/mcp-server",
Description: "A dummy MCP registry for testing",
Repository: model.Repository{
@ -30,13 +29,10 @@ func NewFakeRegistryService() RegistryService {
ID: "example/mcp-1",
},
VersionDetail: model.VersionDetail{
Version: "1.0.0",
ReleaseDate: time.Now().Format(time.RFC3339),
IsLatest: true,
Version: "1.0.0",
},
},
{
ID: uuid.New().String(),
Name: "orangepurple/mcp-server",
Description: "Another dummy MCP registry for testing",
Repository: model.Repository{
@ -45,13 +41,10 @@ func NewFakeRegistryService() RegistryService {
ID: "example/mcp-2",
},
VersionDetail: model.VersionDetail{
Version: "0.9.0",
ReleaseDate: time.Now().Format(time.RFC3339),
IsLatest: false,
Version: "0.9.0",
},
},
{
ID: uuid.New().String(),
Name: "greenyellow/mcp-server",
Description: "Yet another dummy MCP registry for testing",
Repository: model.Repository{
@ -60,70 +53,92 @@ func NewFakeRegistryService() RegistryService {
ID: "example/mcp-3",
},
VersionDetail: model.VersionDetail{
Version: "0.9.5",
ReleaseDate: time.Now().Format(time.RFC3339),
IsLatest: false,
Version: "0.9.5",
},
},
}
// Create a new in-memory database
registryMap := make(map[string]*model.Server)
for _, entry := range registries {
registryMap[entry.ID] = entry
// Create a new in-memory database using registry metadata IDs
serverDetailMap := make(map[string]*model.ServerDetail)
for _, entry := range serverDetails {
registryID := uuid.New().String() // Generate registry metadata ID
serverDetailMap[registryID] = entry
}
memDB := database.NewMemoryDB(registryMap)
memDB := database.NewMemoryDB(serverDetailMap)
return &fakeRegistryService{
db: memDB,
}
}
// List retrieves MCPRegistry entries with optional filtering and pagination
func (s *fakeRegistryService) List(cursor string, limit int) ([]model.Server, string, error) {
// List retrieves servers with extension wrapper format
func (s *fakeRegistryService) List(cursor string, limit int) ([]model.ServerResponse, string, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Use the database's List method with no filters to get all entries
entries, nextCursor, err := s.db.List(ctx, nil, cursor, limit)
// Use the database's List method to get ServerRecord entries
serverRecords, nextCursor, err := s.db.List(ctx, nil, cursor, limit)
if err != nil {
return nil, "", err
}
// Convert from []*model.Server to []model.Server
result := make([]model.Server, len(entries))
for i, entry := range entries {
result[i] = *entry
// Convert ServerRecord to ServerResponse format
result := make([]model.ServerResponse, len(serverRecords))
for i, record := range serverRecords {
result[i] = record.ToServerResponse()
}
return result, nextCursor, nil
}
// GetByID retrieves a specific server detail by its ID
func (s *fakeRegistryService) GetByID(id string) (*model.ServerDetail, error) {
// GetByID retrieves a specific server by its registry metadata ID in extension wrapper format
func (s *fakeRegistryService) GetByID(id string) (*model.ServerResponse, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Use the database's GetByID method to retrieve the server detail
serverDetail, err := s.db.GetByID(ctx, id)
// Use the database's GetByID method to retrieve the server record
serverRecord, err := s.db.GetByID(ctx, id)
if err != nil {
return nil, err
}
return serverDetail, nil
// Convert ServerRecord to ServerResponse format
response := serverRecord.ToServerResponse()
return &response, nil
}
// Publish adds a new server detail to the in-memory database
func (s *fakeRegistryService) Publish(serverDetail *model.ServerDetail) error {
// Publish publishes a server with separated extensions
func (s *fakeRegistryService) Publish(req model.PublishRequest) (*model.ServerResponse, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Use the database's Publish method to add the server detail
return s.db.Publish(ctx, serverDetail)
// Validate the request
if err := model.ValidatePublisherExtensions(req); err != nil {
return nil, err
}
// Validate server name exists
if _, err := model.ParseServerName(req.Server); err != nil {
return nil, err
}
// Extract publisher extensions from request
publisherExtensions := model.ExtractPublisherExtensions(req)
// Publish to database
serverRecord, err := s.db.Publish(ctx, req.Server, publisherExtensions)
if err != nil {
return nil, err
}
// Convert ServerRecord to ServerResponse format
response := serverRecord.ToServerResponse()
return &response, nil
}
// Close closes the in-memory database connection
func (s *fakeRegistryService) Close() error {
return s.db.Close()
}
}

View file

@ -22,29 +22,8 @@ func NewRegistryServiceWithDB(db database.Database) RegistryService {
}
}
// GetAll returns all registry entries
func (s *registryServiceImpl) GetAll() ([]model.Server, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Use the database's List method with no filters to get all entries
entries, _, err := s.db.List(ctx, nil, "", 30)
if err != nil {
return nil, err
}
// Convert from []*model.Server to []model.Server
result := make([]model.Server, len(entries))
for i, entry := range entries {
result[i] = *entry
}
return result, nil
}
// List returns registry entries with cursor-based pagination
func (s *registryServiceImpl) List(cursor string, limit int) ([]model.Server, string, error) {
// List returns registry entries with cursor-based pagination in extension wrapper format
func (s *registryServiceImpl) List(cursor string, limit int) ([]model.ServerResponse, string, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
@ -55,49 +34,63 @@ func (s *registryServiceImpl) List(cursor string, limit int) ([]model.Server, st
}
// Use the database's List method with pagination
entries, nextCursor, err := s.db.List(ctx, nil, cursor, limit)
serverRecords, nextCursor, err := s.db.List(ctx, nil, cursor, limit)
if err != nil {
return nil, "", err
}
// Convert from []*model.Server to []model.Server
result := make([]model.Server, len(entries))
for i, entry := range entries {
result[i] = *entry
// Convert ServerRecord to ServerResponse format
result := make([]model.ServerResponse, len(serverRecords))
for i, record := range serverRecords {
result[i] = record.ToServerResponse()
}
return result, nextCursor, nil
}
// GetByID retrieves a specific server detail by its ID
func (s *registryServiceImpl) GetByID(id string) (*model.ServerDetail, error) {
// GetByID retrieves a specific server by its registry metadata ID in extension wrapper format
func (s *registryServiceImpl) GetByID(id string) (*model.ServerResponse, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Use the database's GetByID method to retrieve the server detail
serverDetail, err := s.db.GetByID(ctx, id)
// Use the database's GetByID method to retrieve the server record
serverRecord, err := s.db.GetByID(ctx, id)
if err != nil {
return nil, err
}
return serverDetail, nil
// Convert ServerRecord to ServerResponse format
response := serverRecord.ToServerResponse()
return &response, nil
}
// Publish adds a new server detail to the registry
func (s *registryServiceImpl) Publish(serverDetail *model.ServerDetail) error {
// Publish publishes a server with separated extensions
func (s *registryServiceImpl) Publish(req model.PublishRequest) (*model.ServerResponse, error) {
// Create a timeout context for the database operation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if serverDetail == nil {
return database.ErrInvalidInput
// Validate the request
if err := model.ValidatePublisherExtensions(req); err != nil {
return nil, err
}
err := s.db.Publish(ctx, serverDetail)
// Validate server name exists
if _, err := model.ParseServerName(req.Server); err != nil {
return nil, err
}
// Extract publisher extensions from request
publisherExtensions := model.ExtractPublisherExtensions(req)
// Publish to database
serverRecord, err := s.db.Publish(ctx, req.Server, publisherExtensions)
if err != nil {
return err
return nil, err
}
return nil
}
// Convert ServerRecord to ServerResponse format
response := serverRecord.ToServerResponse()
return &response, nil
}

View file

@ -2,9 +2,12 @@ package service
import "github.com/modelcontextprotocol/registry/internal/model"
// RegistryService defines the interface for registry operations
// RegistryService defines the interface for registry operations with extension wrapper architecture
type RegistryService interface {
List(cursor string, limit int) ([]model.Server, string, error)
GetByID(id string) (*model.ServerDetail, error)
Publish(serverDetail *model.ServerDetail) error
// List retrieves servers with extension wrapper format
List(cursor string, limit int) ([]model.ServerResponse, string, error)
// GetByID retrieves a single server by registry metadata ID with extension wrapper format
GetByID(id string) (*model.ServerResponse, error)
// Publish publishes a server with separated extensions
Publish(req model.PublishRequest) (*model.ServerResponse, error)
}