database

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

This section is empty.

Types

type ConnectionType

type ConnectionType string

ConnectionType represents the type of database connection

const (
	// ConnectionTypeMemory represents an in-memory database connection
	ConnectionTypeMemory ConnectionType = "memory"
	// ConnectionTypePostgreSQL represents a PostgreSQL database connection
	ConnectionTypePostgreSQL ConnectionType = "postgresql"
)

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 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
}

Database defines the interface for database operations

type MemoryDB

type MemoryDB struct {
	// contains filtered or unexported fields
}

MemoryDB is an in-memory implementation of the Database interface

func NewMemoryDB

func NewMemoryDB() *MemoryDB

func (*MemoryDB) Close

func (db *MemoryDB) Close() error

For an in-memory database, this is a no-op

func (*MemoryDB) CreateServer

func (db *MemoryDB) CreateServer(ctx context.Context, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)

func (*MemoryDB) GetByID

func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv0.ServerJSON, error)

func (*MemoryDB) List

func (db *MemoryDB) List(
	ctx context.Context,
	filter *ServerFilter,
	cursor string,
	limit int,
) ([]*apiv0.ServerJSON, string, error)

func (*MemoryDB) UpdateServer

func (db *MemoryDB) UpdateServer(ctx context.Context, id string, server *apiv0.ServerJSON) (*apiv0.ServerJSON, error)

type Migration

type Migration struct {
	Version int
	Name    string
	SQL     string
}

Migration represents a database migration

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

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context) error

Migrate runs all pending migrations

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) Close

func (db *PostgreSQL) Close() error

Close closes the database connection

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) GetByID

func (db *PostgreSQL) GetByID(ctx context.Context, id 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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL