-
Notifications
You must be signed in to change notification settings - Fork 788
Expand file tree
/
Copy pathdatabase.go
More file actions
60 lines (52 loc) · 2.61 KB
/
database.go
File metadata and controls
60 lines (52 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package database
import (
"context"
"errors"
"time"
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
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
}
// 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
// Rate limiting methods
IncrementPublishCount(ctx context.Context, authMethodSubject string) error
GetPublishCount(ctx context.Context, authMethodSubject string, date time.Time) (int, error)
// CheckAndIncrementPublishCount atomically checks if the count is under the limit and increments if so
// Returns the current count and whether the increment was successful
CheckAndIncrementPublishCount(ctx context.Context, authMethodSubject string, limit int) (currentCount int, incrementSuccessful bool, err 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"
)