storage

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIStore

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

APIStore implements the Store interface using the remote http server

func NewAPIStore

func NewAPIStore(logger *zap.Logger, url string, configJSONPath string, timeout time.Duration) (*APIStore, error)

NewAPIStore creates a new api-based store

func (*APIStore) Create

func (s *APIStore) Create(_ context.Context, server *config.MCPConfig) error

Create implements Store.Create

func (*APIStore) Delete

func (s *APIStore) Delete(_ context.Context, tenant, name string) error

Delete implements Store.Delete

func (*APIStore) DeleteVersion

func (s *APIStore) DeleteVersion(_ context.Context, tenant, name string, version int) error

DeleteVersion implements Store.DeleteVersion

func (*APIStore) Get

func (s *APIStore) Get(_ context.Context, tenant, name string, includeDeleted ...bool) (*config.MCPConfig, error)

Get implements Store.Get

func (*APIStore) GetVersion

func (s *APIStore) GetVersion(_ context.Context, tenant, name string, version int) (*config.MCPConfigVersion, error)

GetVersion implements Store.GetVersion

func (*APIStore) List

func (s *APIStore) List(_ context.Context, _ ...bool) ([]*config.MCPConfig, error)

List implements Store.List

func (*APIStore) ListUpdated

func (s *APIStore) ListUpdated(_ context.Context, since time.Time) ([]*config.MCPConfig, error)

ListUpdated implements Store.ListUpdated

func (*APIStore) ListVersions

func (s *APIStore) ListVersions(_ context.Context, tenant, name string) ([]*config.MCPConfigVersion, error)

ListVersions implements Store.ListVersions

func (*APIStore) SetActiveVersion

func (s *APIStore) SetActiveVersion(_ context.Context, tenant, name string, version int) error

SetActiveVersion implements Store.SetActiveVersion

func (*APIStore) Update

func (s *APIStore) Update(_ context.Context, _ *config.MCPConfig) error

Update implements Store.Update

type ActiveVersion

type ActiveVersion struct {
	ID        uint           `gorm:"primarykey"`
	Tenant    string         `gorm:"type:varchar(50);not null;uniqueIndex:idx_tenant_name,priority:1"`
	Name      string         `gorm:"type:varchar(50);not null;uniqueIndex:idx_tenant_name,priority:2"`
	Version   int            `gorm:"not null"`
	UpdatedAt time.Time      `gorm:"not null"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

ActiveVersion represents the currently active version of an MCP configuration

type DBStore

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

DBStore implements the Store interface using a database

func NewDBStore

func NewDBStore(logger *zap.Logger, cfg *config.StorageConfig) (*DBStore, error)

NewDBStore creates a new database-based store

func (*DBStore) Create

func (s *DBStore) Create(_ context.Context, server *config.MCPConfig) error

Create implements Store.Create

func (*DBStore) Delete

func (s *DBStore) Delete(ctx context.Context, tenant, name string) error

Delete implements Store.Delete

func (*DBStore) DeleteVersion

func (s *DBStore) DeleteVersion(ctx context.Context, tenant, name string, version int) error

DeleteVersion deletes a specific version

func (*DBStore) Get

func (s *DBStore) Get(_ context.Context, tenant, name string, includeDeleted ...bool) (*config.MCPConfig, error)

Get implements Store.Get

func (*DBStore) GetVersion

func (s *DBStore) GetVersion(ctx context.Context, tenant, name string, version int) (*config.MCPConfigVersion, error)

GetVersion gets a specific version of the configuration

func (*DBStore) List

func (s *DBStore) List(_ context.Context, includeDeleted ...bool) ([]*config.MCPConfig, error)

List implements Store.List

func (*DBStore) ListUpdated

func (s *DBStore) ListUpdated(_ context.Context, since time.Time) ([]*config.MCPConfig, error)

ListUpdated implements Store.ListUpdated

func (*DBStore) ListVersions

func (s *DBStore) ListVersions(ctx context.Context, tenant, name string) ([]*config.MCPConfigVersion, error)

ListVersions lists all versions of a configuration

func (*DBStore) SetActiveVersion

func (s *DBStore) SetActiveVersion(ctx context.Context, tenant, name string, version int) error

SetActiveVersion sets a specific version as the active version

func (*DBStore) Update

func (s *DBStore) Update(ctx context.Context, server *config.MCPConfig) error

Update implements Store.Update

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database

const (
	PostgreSQL DatabaseType = "postgres"
	MySQL      DatabaseType = "mysql"
	SQLite     DatabaseType = "sqlite"
)

type DiskStore

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

func NewDiskStore

func NewDiskStore(logger *zap.Logger, cfg *config.StorageConfig) (*DiskStore, error)

NewDiskStore creates a new disk-based store

func (*DiskStore) Create

func (s *DiskStore) Create(_ context.Context, server *config.MCPConfig) error

func (*DiskStore) Delete

func (s *DiskStore) Delete(_ context.Context, tenant, name string) error

func (*DiskStore) DeleteVersion

func (s *DiskStore) DeleteVersion(_ context.Context, tenant, name string, version int) error

func (*DiskStore) Get

func (s *DiskStore) Get(_ context.Context, tenant, name string, includeDeleted ...bool) (*config.MCPConfig, error)

func (*DiskStore) GetActiveVersion

func (s *DiskStore) GetActiveVersion(_ context.Context, tenant, name string) (*config.MCPConfig, error)

func (*DiskStore) GetVersion

func (s *DiskStore) GetVersion(_ context.Context, tenant, name string, version int) (*config.MCPConfigVersion, error)

func (*DiskStore) List

func (s *DiskStore) List(_ context.Context, _ ...bool) ([]*config.MCPConfig, error)

func (*DiskStore) ListUpdated

func (s *DiskStore) ListUpdated(_ context.Context, since time.Time) ([]*config.MCPConfig, error)

ListUpdated implements Store.ListUpdated

func (*DiskStore) ListVersions

func (s *DiskStore) ListVersions(_ context.Context, tenant, name string) ([]*config.MCPConfigVersion, error)

func (*DiskStore) SetActiveVersion

func (s *DiskStore) SetActiveVersion(_ context.Context, tenant, name string, version int) error

func (*DiskStore) Update

func (s *DiskStore) Update(_ context.Context, server *config.MCPConfig) error

type MCPConfig

type MCPConfig struct {
	ID         int64  `gorm:"primaryKey;autoIncrement"`
	Name       string `gorm:"column:name; type:varchar(50); uniqueIndex:idx_name_tenant,priority:2"`
	Tenant     string `gorm:"column:tenant; type:varchar(50); default:''; uniqueIndex:idx_name_tenant,priority:1"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Routers    string         `gorm:"type:text; column:routers"`
	Servers    string         `gorm:"type:text; column:servers"`
	Tools      string         `gorm:"type:text; column:tools"`
	McpServers string         `gorm:"type:text; column:mcp_servers"`
	DeletedAt  gorm.DeletedAt `gorm:"index"`
}

MCPConfig represents the database model for MCPConfig

func FromMCPConfig

func FromMCPConfig(cfg *config.MCPConfig) (*MCPConfig, error)

FromMCPConfig converts MCPConfig to database model

func (*MCPConfig) BeforeCreate

func (m *MCPConfig) BeforeCreate(_ *gorm.DB) error

BeforeCreate is a GORM hook that sets timestamps

func (*MCPConfig) BeforeUpdate

func (m *MCPConfig) BeforeUpdate(_ *gorm.DB) error

BeforeUpdate is a GORM hook that updates the UpdatedAt timestamp

func (*MCPConfig) ToMCPConfig

func (m *MCPConfig) ToMCPConfig() (*config.MCPConfig, error)

ToMCPConfig converts the database model to MCPConfig

type MCPConfigVersion

type MCPConfigVersion struct {
	ID         int64           `gorm:"primaryKey;autoIncrement"`
	Name       string          `gorm:"column:name;type:varchar(50);index:idx_name_tenant_version,uniqueIndex"`
	Tenant     string          `gorm:"column:tenant;type:varchar(50);index:idx_name_tenant_version,uniqueIndex"`
	Version    int             `gorm:"column:version;index:idx_name_tenant_version,uniqueIndex"`
	ActionType cnst.ActionType `gorm:"column:action_type;not null"` // Create, Update, Delete, Revert
	CreatedBy  string          `gorm:"column:created_by"`
	CreatedAt  time.Time       `gorm:"column:created_at;"`
	Routers    string          `gorm:"type:text;column:routers"`
	Servers    string          `gorm:"type:text;column:servers"`
	Tools      string          `gorm:"type:text;column:tools"`
	McpServers string          `gorm:"type:text;column:mcp_servers"`
	Hash       string          `gorm:"column:hash;not null"` // hash of the configuration content
	DeletedAt  gorm.DeletedAt  `gorm:"index"`
}

MCPConfigVersion represents the database model for MCPConfigVersion

func FromMCPConfigVersion

func FromMCPConfigVersion(cfg *config.MCPConfig, version int, createdBy string, actionType cnst.ActionType) (*MCPConfigVersion, error)

FromMCPConfigVersion converts MCPConfig to database model

func (*MCPConfigVersion) ToConfigVersion

func (m *MCPConfigVersion) ToConfigVersion() *config.MCPConfigVersion

func (*MCPConfigVersion) ToMCPConfig

func (m *MCPConfigVersion) ToMCPConfig() (*config.MCPConfig, error)

ToMCPConfig converts the database model to MCPConfig

type Store

type Store interface {
	// Create creates a new MCP configuration
	Create(ctx context.Context, cfg *config.MCPConfig) error

	// Get gets an MCP configuration by tenant and name
	Get(ctx context.Context, tenant, name string, includeDeleted ...bool) (*config.MCPConfig, error)

	// List lists all MCP configurations
	// includeDeleted: if true, includes soft deleted records
	List(ctx context.Context, includeDeleted ...bool) ([]*config.MCPConfig, error)

	// ListUpdated lists all MCP configurations updated since a given time
	ListUpdated(ctx context.Context, since time.Time) ([]*config.MCPConfig, error)

	// Update updates an existing MCP configuration
	Update(ctx context.Context, cfg *config.MCPConfig) error

	// Delete deletes an MCP configuration by tenant and name
	Delete(ctx context.Context, tenant, name string) error

	// GetVersion gets a specific version of the configuration by tenant and name
	GetVersion(ctx context.Context, tenant, name string, version int) (*config.MCPConfigVersion, error)

	// ListVersions lists all versions of a configuration by tenant and name
	ListVersions(ctx context.Context, tenant, name string) ([]*config.MCPConfigVersion, error)

	// DeleteVersion deletes a specific version by tenant and name
	DeleteVersion(ctx context.Context, tenant, name string, version int) error

	// SetActiveVersion sets a specific version as the active version by tenant and name
	SetActiveVersion(ctx context.Context, tenant, name string, version int) error
}

Store defines the interface for MCP configuration storage

func NewStore

func NewStore(logger *zap.Logger, cfg *config.StorageConfig) (Store, error)

NewStore creates a new store based on configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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