service

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 8 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

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")
	// ErrConfigRegistry is returned when attempting to modify a CONFIG-created registry via API
	ErrConfigRegistry = errors.New("cannot modify config-created registry via API")
	// ErrInvalidRegistryConfig is returned when registry configuration is invalid
	ErrInvalidRegistryConfig = errors.New("invalid registry configuration")
	// ErrRegistryAlreadyExists is returned when attempting to create a registry that already exists
	ErrRegistryAlreadyExists = errors.New("registry already exists")
	// ErrSourceTypeChangeNotAllowed is returned when attempting to change a registry's source type
	ErrSourceTypeChangeNotAllowed = errors.New("changing registry source type is not allowed")
)

Functions

func ValidateInlineDataBasic added in v0.4.7

func ValidateInlineDataBasic(data string) error

ValidateInlineDataBasic performs basic validation on inline registry data. It uses the existing registry data validator to parse and validate both toolhive and upstream formats.

func ValidateInlineDataWithFormat added in v0.4.7

func ValidateInlineDataWithFormat(data string, format string) error

ValidateInlineDataWithFormat validates inline registry data with a specific format. If format is empty, it tries upstream format first, then falls back to toolhive.

func ValidateRegistryConfig added in v0.4.7

func ValidateRegistryConfig(req *RegistryCreateRequest) error

ValidateRegistryConfig validates a RegistryCreateRequest

Types

type CreationType added in v0.4.7

type CreationType string

CreationType indicates how the registry was created

const (
	// CreationTypeAPI indicates the registry was created via API
	CreationTypeAPI CreationType = "API"
	// CreationTypeCONFIG indicates the registry was created from config file
	CreationTypeCONFIG CreationType = "CONFIG"
)

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 RegistryCreateRequest added in v0.4.7

type RegistryCreateRequest struct {
	Format     string                   `json:"format,omitempty"`     // "toolhive" or "upstream"
	Git        *config.GitConfig        `json:"git,omitempty"`        // Git repository source
	API        *config.APIConfig        `json:"api,omitempty"`        // API endpoint source
	File       *config.FileConfig       `json:"file,omitempty"`       // Local file or URL source
	Managed    *config.ManagedConfig    `json:"managed,omitempty"`    // Managed registry (no sync)
	Kubernetes *config.KubernetesConfig `json:"kubernetes,omitempty"` // Kubernetes discovery source
	SyncPolicy *config.SyncPolicyConfig `json:"syncPolicy,omitempty"` // Sync schedule configuration
	Filter     *config.FilterConfig     `json:"filter,omitempty"`     // Name/tag filtering rules
}

RegistryCreateRequest represents the request body for PUT /registries/{name}

func (*RegistryCreateRequest) CountSourceTypes added in v0.4.7

func (r *RegistryCreateRequest) CountSourceTypes() int

CountSourceTypes returns the number of source types configured

func (*RegistryCreateRequest) GetSourceConfig added in v0.4.7

func (r *RegistryCreateRequest) GetSourceConfig() interface{}

GetSourceConfig returns the active source configuration

func (*RegistryCreateRequest) GetSourceType added in v0.4.7

func (r *RegistryCreateRequest) GetSourceType() config.SourceType

GetSourceType returns the source type based on which config is set

func (*RegistryCreateRequest) IsInlineData added in v0.4.7

func (r *RegistryCreateRequest) IsInlineData() bool

IsInlineData returns true if this is a file source with inline data

func (*RegistryCreateRequest) IsNonSyncedType added in v0.4.7

func (r *RegistryCreateRequest) IsNonSyncedType() bool

IsNonSyncedType returns true if the source type doesn't require syncing

type RegistryInfo added in v0.3.2

type RegistryInfo struct {
	Name         string               `json:"name"`
	Type         string               `json:"type"`                   // MANAGED, FILE, REMOTE, KUBERNETES
	CreationType CreationType         `json:"creationType,omitempty"` // API or CONFIG
	SourceType   config.SourceType    `json:"sourceType,omitempty"`   // git, api, file, managed, kubernetes
	Format       string               `json:"format,omitempty"`       // toolhive or upstream
	SourceConfig interface{}          `json:"sourceConfig,omitempty"` // Type-specific source configuration
	FilterConfig *config.FilterConfig `json:"filterConfig,omitempty"` // Filtering rules
	SyncSchedule string               `json:"syncSchedule,omitempty"` // Sync interval string
	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 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)

	// CreateRegistry creates a new API-managed registry
	CreateRegistry(ctx context.Context, name string, req *RegistryCreateRequest) (*RegistryInfo, error)

	// UpdateRegistry updates an existing API-managed registry
	UpdateRegistry(ctx context.Context, name string, req *RegistryCreateRequest) (*RegistryInfo, error)

	// DeleteRegistry deletes an API-managed registry
	DeleteRegistry(ctx context.Context, name string) error

	// ProcessInlineRegistryData processes inline data for a managed/file registry
	ProcessInlineRegistryData(ctx context.Context, name string, data string, format string) 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 factory provides factory functions for creating service implementations.
Package factory provides factory functions for creating service implementations.
Package inmemory provides the business logic for the MCP registry API
Package inmemory provides the business logic for the MCP registry API
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
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