## Motivation and Context The database logic was getting a bit unwieldy and fragile - especially because business logic that should really have lived at the registry service level was being pushed into the persistence level. This PR tightens the interface, simplifies the code there, as well as rips out a bunch of mocks etc. we don't need. ## How Has This Been Tested? Locally everything works ## Breaking Changes The list endpoint was surprisingly always filtering for isLatest only, which seems like a bug? I have removed this filter.
48 lines
1.9 KiB
Go
48 lines
1.9 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
|
)
|
|
|
|
// Common database errors
|
|
var (
|
|
ErrNotFound = errors.New("record not found")
|
|
ErrAlreadyExists = errors.New("record already exists")
|
|
ErrInvalidInput = errors.New("invalid input")
|
|
ErrDatabase = errors.New("database error")
|
|
ErrInvalidVersion = errors.New("invalid version: cannot publish duplicate version")
|
|
ErrMaxServersReached = errors.New("maximum number of versions for this server reached (10000): please reach out at https://github.com/modelcontextprotocol/registry to explain your use case")
|
|
)
|
|
|
|
// ServerFilter defines filtering options for server queries
|
|
type ServerFilter struct {
|
|
Name *string // for finding versions of same server
|
|
RemoteURL *string // for duplicate URL detection
|
|
}
|
|
|
|
// Database defines the interface for database operations
|
|
type Database interface {
|
|
// Retrieve server entries with optional filtering
|
|
List(ctx context.Context, filter *ServerFilter, cursor string, limit int) ([]*apiv0.ServerJSON, string, error)
|
|
// Retrieve a single server by its ID
|
|
GetByID(ctx context.Context, id string) (*apiv0.ServerJSON, error)
|
|
// CreateServer adds a new server to the database
|
|
CreateServer(ctx context.Context, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
|
|
// UpdateServer updates an existing server record
|
|
UpdateServer(ctx context.Context, id string, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
|
|
// Close closes the database connection
|
|
Close() error
|
|
}
|
|
|
|
// ConnectionType represents the type of database connection
|
|
type ConnectionType string
|
|
|
|
const (
|
|
// ConnectionTypeMemory represents an in-memory database connection
|
|
ConnectionTypeMemory ConnectionType = "memory"
|
|
// ConnectionTypePostgreSQL represents a PostgreSQL database connection
|
|
ConnectionTypePostgreSQL ConnectionType = "postgresql"
|
|
)
|