service

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package service provides the business logic for the MCP registry API

Package service provides the business logic for the MCP registry API

Package service provides the business logic for the MCP registry API

Package service provides the business logic for the MCP registry API

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServerNotFound is returned when a server is not found
	ErrServerNotFound = errors.New("server not found")
	// ErrNotImplemented is returned when a feature is not implemented
	ErrNotImplemented = errors.New("not implemented")
	// ErrRegistryNotFound is returned when a registry is not found
	ErrRegistryNotFound = errors.New("registry not found")
	// ErrNotManagedRegistry is returned when attempting write operations on a non-managed registry
	ErrNotManagedRegistry = errors.New("registry is not managed")
	// ErrVersionAlreadyExists is returned when attempting to publish a version that already exists
	ErrVersionAlreadyExists = errors.New("version already exists")
)

Functions

This section is empty.

Types

type DeleteServerVersionOptions added in v0.3.0

type DeleteServerVersionOptions struct {
	RegistryName string
	ServerName   string
	Version      string
}

DeleteServerVersionOptions is the options for the DeleteServerVersion operation

type DeployedServer

type DeployedServer struct {
	Name        string `json:"name"`
	Namespace   string `json:"namespace"`
	Status      string `json:"status"`
	Image       string `json:"image"`
	Transport   string `json:"transport"`
	Ready       bool   `json:"ready"`
	EndpointURL string `json:"endpoint_url,omitempty"`
}

DeployedServer represents a deployed MCP server in Kubernetes

type GetServerVersionOptions added in v0.3.0

type GetServerVersionOptions struct {
	RegistryName *string
	Name         string
	Version      string
}

GetServerVersionOptions is the options for the GetServerVersion operation

type ListServerVersionsOptions added in v0.3.0

type ListServerVersionsOptions struct {
	RegistryName *string
	Name         string
	Next         *time.Time
	Prev         *time.Time
	Limit        int
}

ListServerVersionsOptions is the options for the ListServerVersions operation

type ListServersOptions added in v0.3.0

type ListServersOptions struct {
	RegistryName *string
	Cursor       string
	Limit        int
	Search       string
	UpdatedSince time.Time
	Version      string
}

ListServersOptions is the options for the ListServers operation

type Option

Option is a function that sets an option for the ListServersOptions, ListServerVersionsOptions, GetServerVersionOptions, PublishServerVersionOptions, or DeleteServerVersionOptions

func WithCursor added in v0.3.0

func WithCursor(cursor string) Option[ListServersOptions]

WithCursor sets the cursor for the ListServers operation

func WithLimit added in v0.3.0

func WithLimit[T ListServersOptions | ListServerVersionsOptions](limit int) Option[T]

WithLimit sets the limit for the ListServers or ListServerVersions operation

func WithName added in v0.3.0

WithName sets the name for the ListServerVersions, GetServerVersion, or DeleteServerVersion operation

func WithNext added in v0.3.0

func WithNext(next time.Time) Option[ListServerVersionsOptions]

WithNext sets the next time for the ListServerVersions operation

func WithPrev added in v0.3.0

func WithPrev(prev time.Time) Option[ListServerVersionsOptions]

WithPrev sets the prev time for the ListServerVersions operation

func WithRegistryName added in v0.3.0

WithRegistryName sets the registry name for the ListServers, ListServerVersions, GetServerVersion, PublishServerVersion, or DeleteServerVersion operation

func WithSearch added in v0.3.0

func WithSearch(search string) Option[ListServersOptions]

WithSearch sets the search for the ListServers operation

func WithServerData added in v0.3.0

func WithServerData(serverData *upstreamv0.ServerJSON) Option[PublishServerVersionOptions]

WithServerData sets the server data for the PublishServerVersion operation

func WithUpdatedSince added in v0.3.0

func WithUpdatedSince(updatedSince time.Time) Option[ListServersOptions]

WithUpdatedSince sets the updated since for the ListServers operation

func WithVersion added in v0.3.0

WithVersion sets the version for the ListServers, GetServerVersion, or DeleteServerVersion operation

type PublishServerVersionOptions added in v0.3.0

type PublishServerVersionOptions struct {
	RegistryName string
	ServerData   *upstreamv0.ServerJSON
}

PublishServerVersionOptions is the options for the PublishServerVersion operation

type RegistryDataProvider

type RegistryDataProvider interface {
	// GetRegistryData fetches the current registry data.
	// Returns the registry data and any error encountered.
	GetRegistryData(ctx context.Context) (*toolhivetypes.UpstreamRegistry, error)

	// GetSource returns a descriptive string about where the registry data comes from.
	// Examples: "file:/path/to/registry.json", "remote:https://example.com/registry"
	GetSource() string

	// GetRegistryName returns the registry name/identifier for this provider.
	// This name is used for business logic such as finding related Kubernetes resources.
	GetRegistryName() string
}

RegistryDataProvider abstracts the source of registry data. This interface follows the Go principle of small, focused interfaces and enables easy testing and multiple implementations.

func NewFileRegistryDataProvider

func NewFileRegistryDataProvider(storageManager sources.StorageManager, cfg *config.Config) RegistryDataProvider

NewFileRegistryDataProvider creates a new file-based registry data provider. It accepts a StorageManager to delegate file operations and a Config for registry metadata. This design eliminates code duplication and improves testability through dependency injection.

type RegistryInfo added in v0.3.2

type RegistryInfo struct {
	Name       string              `json:"name"`
	Type       string              `json:"type"` // MANAGED, FILE, REMOTE
	SyncStatus *RegistrySyncStatus `json:"syncStatus,omitempty"`
	CreatedAt  time.Time           `json:"createdAt"`
	UpdatedAt  time.Time           `json:"updatedAt"`
}

RegistryInfo represents detailed information about a registry

type RegistryListResponse added in v0.3.2

type RegistryListResponse struct {
	Registries []RegistryInfo `json:"registries"`
}

RegistryListResponse represents the response for listing registries

type RegistryProviderFactory

type RegistryProviderFactory interface {
	// CreateProvider creates a registry data provider based on the provided configuration
	CreateProvider(cfg *config.Config) (RegistryDataProvider, error)
}

RegistryProviderFactory creates registry data providers based on configuration

func NewRegistryProviderFactory

func NewRegistryProviderFactory(storageManager sources.StorageManager) RegistryProviderFactory

NewRegistryProviderFactory creates a new default registry provider factory

type RegistryService

type RegistryService interface {
	// CheckReadiness checks if the regSvc is ready to serve requests
	CheckReadiness(ctx context.Context) error

	// GetRegistry returns the registry data with metadata
	GetRegistry(ctx context.Context) (*toolhivetypes.UpstreamRegistry, string, error) // returns registry, source, error

	// ListServers returns all servers in the registry
	ListServers(ctx context.Context, opts ...Option[ListServersOptions]) ([]*upstreamv0.ServerJSON, error)

	// ListServerVersions returns all versions of a specific server
	ListServerVersions(ctx context.Context, opts ...Option[ListServerVersionsOptions]) ([]*upstreamv0.ServerJSON, error)

	// GetServer returns a specific server by name
	GetServerVersion(ctx context.Context, opts ...Option[GetServerVersionOptions]) (*upstreamv0.ServerJSON, error)

	// PublishServerVersion publishes a server version to a managed registry
	PublishServerVersion(ctx context.Context, opts ...Option[PublishServerVersionOptions]) (*upstreamv0.ServerJSON, error)

	// DeleteServerVersion removes a server version from a managed registry
	DeleteServerVersion(ctx context.Context, opts ...Option[DeleteServerVersionOptions]) error

	// ListRegistries returns all configured registries
	ListRegistries(ctx context.Context) ([]RegistryInfo, error)

	// GetRegistryByName returns a single registry by name
	GetRegistryByName(ctx context.Context, name string) (*RegistryInfo, error)
}

RegistryService defines the interface for registry operations

type RegistrySyncStatus added in v0.3.2

type RegistrySyncStatus struct {
	Phase        string     `json:"phase"`                  // complete, syncing, failed
	LastSyncTime *time.Time `json:"lastSyncTime,omitempty"` // Last successful sync
	LastAttempt  *time.Time `json:"lastAttempt,omitempty"`  // Last sync attempt
	AttemptCount int        `json:"attemptCount"`           // Number of sync attempts
	ServerCount  int        `json:"serverCount"`            // Number of servers in registry
	Message      string     `json:"message,omitempty"`      // Status or error message
}

RegistrySyncStatus represents the sync status of a registry

Directories

Path Synopsis
Package database provides a database-backed implementation of the RegistryService interface
Package database provides a database-backed implementation of the RegistryService interface
Package inmemory provides an in-memory implementation of the RegistryService interface
Package inmemory provides an in-memory implementation of the RegistryService interface
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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