service

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: Apache-2.0 Imports: 9 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")
)

Functions

This section is empty.

Types

type DefaultRegistryProviderFactory

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

DefaultRegistryProviderFactory is the default implementation of RegistryProviderFactory

func (*DefaultRegistryProviderFactory) CreateProvider

CreateProvider implements RegistryProviderFactory.CreateProvider

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 DeploymentProvider

type DeploymentProvider interface {
	// ListDeployedServers returns all currently deployed MCP servers.
	// Returns an empty slice if no servers are deployed
	ListDeployedServers(ctx context.Context) ([]*DeployedServer, error)

	// GetDeployedServer returns all deployed servers matching the server registry name.
	// Returns an empty slice if no servers are found.
	GetDeployedServer(ctx context.Context, name string) ([]*DeployedServer, error)
}

DeploymentProvider abstracts access to deployed MCP servers.

type FileRegistryDataProvider

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

FileRegistryDataProvider implements RegistryDataProvider by delegating to StorageManager. This implementation uses the adapter pattern to reuse storage infrastructure instead of duplicating file reading logic. It delegates to StorageManager for all file operations.

func NewFileRegistryDataProvider

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

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.

func (*FileRegistryDataProvider) GetRegistryData

GetRegistryData implements RegistryDataProvider.GetRegistryData. It delegates to the StorageManager to retrieve and parse registry data. This eliminates code duplication and provides a single source of truth for file operations.

NOTE: In PR 1, StorageManager returns UpstreamRegistry but RegistryDataProvider interface still expects toolhive Registry. This method converts at the boundary to maintain backward compatibility until PR 2.

func (*FileRegistryDataProvider) GetRegistryName

func (p *FileRegistryDataProvider) GetRegistryName() string

GetRegistryName implements RegistryDataProvider.GetRegistryName. It returns the injected registry name identifier.

func (*FileRegistryDataProvider) GetSource

func (p *FileRegistryDataProvider) GetSource() string

GetSource implements RegistryDataProvider.GetSource. It returns a descriptive string indicating the file source from the configuration.

type Option

type Option func(*regSvc)

Option is a functional option for configuring the regSvc

func WithCacheDuration

func WithCacheDuration(duration time.Duration) Option

WithCacheDuration sets a custom cache duration for registry data

type RegistryDataProvider

type RegistryDataProvider interface {
	// GetRegistryData fetches the current registry data.
	// Returns the registry data and any error encountered.
	// NOTE: In PR 1, this still returns ToolHive Registry for backward compatibility.
	// PR 2 will change this to return UpstreamRegistry.
	GetRegistryData(ctx context.Context) (*toolhivetypes.Registry, 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.

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.Registry, string, error) // returns registry, source, error

	// ListServers returns all servers in the registry
	ListServers(ctx context.Context) ([]toolhivetypes.ServerMetadata, error)

	// GetServer returns a specific server by name
	GetServer(ctx context.Context, name string) (toolhivetypes.ServerMetadata, error)

	// ListDeployedServers returns all deployed MCP servers
	ListDeployedServers(ctx context.Context) ([]*DeployedServer, error)

	// GetDeployedServer returns all deployed servers matching the server registry name
	GetDeployedServer(ctx context.Context, name string) ([]*DeployedServer, error)
}

RegistryService defines the interface for registry operations

func NewService

func NewService(
	ctx context.Context,
	registryProvider RegistryDataProvider,
	deploymentProvider DeploymentProvider,
	opts ...Option,
) (RegistryService, error)

NewService creates a new registry regSvc with the given providers and options. registryProvider is required for registry data access. deploymentProvider can be nil if deployed servers functionality is not needed.

Directories

Path Synopsis
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