Documentation
¶
Index ¶
- Variables
- func WithPublishLockT[T any](ctx context.Context, db Database, serverName string, ...) (T, error)
- type Database
- type Migration
- type Migrator
- type PostgreSQL
- func (db *PostgreSQL) Close() error
- func (db *PostgreSQL) CreateServer(ctx context.Context, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
- func (db *PostgreSQL) GetAllVersionsByServerID(ctx context.Context, serverID string) ([]*apiv0.ServerJSON, error)
- func (db *PostgreSQL) GetByServerID(ctx context.Context, serverID string) (*apiv0.ServerJSON, error)
- func (db *PostgreSQL) GetByServerIDAndVersion(ctx context.Context, serverID string, version string) (*apiv0.ServerJSON, error)
- func (db *PostgreSQL) GetByVersionID(ctx context.Context, versionID string) (*apiv0.ServerJSON, error)
- func (db *PostgreSQL) List(ctx context.Context, filter *ServerFilter, cursor string, limit int) ([]*apiv0.ServerJSON, string, error)
- func (db *PostgreSQL) UpdateServer(ctx context.Context, id string, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
- func (db *PostgreSQL) WithPublishLock(ctx context.Context, serverName string, fn func(ctx context.Context) error) error
- type ServerFilter
Constants ¶
This section is empty.
Variables ¶
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") )
Common database errors
Functions ¶
func WithPublishLockT ¶ added in v1.1.0
func WithPublishLockT[T any](ctx context.Context, db Database, serverName string, fn func(ctx context.Context) (T, error)) (T, error)
WithPublishLockT is a generic helper that wraps WithPublishLock for functions returning a value This exists because Go does not support generic methods on interfaces - only the Database interface method WithPublishLock (without generics) can exist, so we provide this generic wrapper function. This is a common pattern in Go for working around this language limitation.
Types ¶
type Database ¶
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 version ID
GetByVersionID(ctx context.Context, versionID string) (*apiv0.ServerJSON, error)
// Retrieve latest version of a server by server ID
GetByServerID(ctx context.Context, serverID string) (*apiv0.ServerJSON, error)
// Retrieve specific version of a server by server ID and version
GetByServerIDAndVersion(ctx context.Context, serverID string, version string) (*apiv0.ServerJSON, error)
// Retrieve all versions of a server by server ID
GetAllVersionsByServerID(ctx context.Context, serverID 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)
// WithPublishLock executes a function with an exclusive lock for publishing a server
// This prevents race conditions when multiple versions are published concurrently
WithPublishLock(ctx context.Context, serverName string, fn func(ctx context.Context) error) error
// Close closes the database connection
Close() error
}
Database defines the interface for database operations
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator handles database migrations
func NewMigrator ¶
func NewMigrator(conn *pgx.Conn) *Migrator
NewMigrator creates a new migrator instance
type PostgreSQL ¶
type PostgreSQL struct {
// contains filtered or unexported fields
}
PostgreSQL is an implementation of the Database interface using PostgreSQL
func NewPostgreSQL ¶
func NewPostgreSQL(ctx context.Context, connectionURI string) (*PostgreSQL, error)
NewPostgreSQL creates a new instance of the PostgreSQL database
func (*PostgreSQL) CreateServer ¶
func (db *PostgreSQL) CreateServer(ctx context.Context, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
CreateServer adds a new server to the database
func (*PostgreSQL) GetAllVersionsByServerID ¶ added in v1.1.0
func (db *PostgreSQL) GetAllVersionsByServerID(ctx context.Context, serverID string) ([]*apiv0.ServerJSON, error)
GetAllVersionsByServerID retrieves all versions of a server by server ID
func (*PostgreSQL) GetByServerID ¶ added in v1.1.0
func (db *PostgreSQL) GetByServerID(ctx context.Context, serverID string) (*apiv0.ServerJSON, error)
GetByServerID retrieves the latest version of a server by server ID
func (*PostgreSQL) GetByServerIDAndVersion ¶ added in v1.1.0
func (db *PostgreSQL) GetByServerIDAndVersion(ctx context.Context, serverID string, version string) (*apiv0.ServerJSON, error)
GetByServerIDAndVersion retrieves a specific version of a server by server ID and version
func (*PostgreSQL) GetByVersionID ¶ added in v1.1.0
func (db *PostgreSQL) GetByVersionID(ctx context.Context, versionID string) (*apiv0.ServerJSON, error)
func (*PostgreSQL) List ¶
func (db *PostgreSQL) List( ctx context.Context, filter *ServerFilter, cursor string, limit int, ) ([]*apiv0.ServerJSON, string, error)
func (*PostgreSQL) UpdateServer ¶
func (db *PostgreSQL) UpdateServer(ctx context.Context, id string, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)
UpdateServer updates an existing server record with new server details
func (*PostgreSQL) WithPublishLock ¶ added in v1.1.0
func (db *PostgreSQL) WithPublishLock(ctx context.Context, serverName string, fn func(ctx context.Context) error) error
WithPublishLock executes a function with an exclusive advisory lock for publishing a server This prevents race conditions when multiple versions are published concurrently
type ServerFilter ¶
type ServerFilter struct {
Name *string // for finding versions of same server
RemoteURL *string // for duplicate URL detection
UpdatedSince *time.Time // for incremental sync filtering
SubstringName *string // for substring search on name
Version *string // for exact version matching
IsLatest *bool // for filtering latest versions only
}
ServerFilter defines filtering options for server queries