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 ¶
Package service provides the business logic for the MCP registry API
Index ¶
- Constants
- Variables
- type ConfigMapProviderConfig
- type DefaultRegistryProviderFactory
- type DeployedServer
- type DeploymentProvider
- type FileProviderConfig
- type FileRegistryDataProvider
- type K8sDeploymentProvider
- type K8sRegistryDataProvider
- type Option
- type RegistryDataProvider
- type RegistryProviderConfig
- type RegistryProviderFactory
- type RegistryProviderType
- type RegistryService
Constants ¶
const ( // LabelRegistryName is the label key for the registry name LabelRegistryName = "toolhive.stacklok.io/registry-name" // LabelRegistryNamespace is the label key for the registry namespace LabelRegistryNamespace = "toolhive.stacklok.io/registry-namespace" // LabelServerRegistryName is the label key for the server's registry name LabelServerRegistryName = "toolhive.stacklok.io/server-name" )
Label constants for deployed server identification
Variables ¶
var ( // ErrServerNotFound is returned when a server is not found ErrServerNotFound = errors.New("server not found") )
Functions ¶
This section is empty.
Types ¶
type ConfigMapProviderConfig ¶
type ConfigMapProviderConfig struct {
Name string
Namespace string
Clientset kubernetes.Interface
RegistryName string
}
ConfigMapProviderConfig holds configuration for ConfigMap-based registry provider
func (*ConfigMapProviderConfig) Validate ¶
func (c *ConfigMapProviderConfig) Validate() error
Validate validates the ConfigMapProviderConfig
type DefaultRegistryProviderFactory ¶
type DefaultRegistryProviderFactory struct{}
DefaultRegistryProviderFactory is the default implementation of RegistryProviderFactory
func (*DefaultRegistryProviderFactory) CreateProvider ¶
func (f *DefaultRegistryProviderFactory) CreateProvider(config *RegistryProviderConfig) (RegistryDataProvider, error)
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 FileProviderConfig ¶
FileProviderConfig holds configuration for file-based registry provider
func (*FileProviderConfig) Validate ¶
func (c *FileProviderConfig) Validate() error
Validate validates the FileProviderConfig
type FileRegistryDataProvider ¶
type FileRegistryDataProvider struct {
// contains filtered or unexported fields
}
FileRegistryDataProvider implements RegistryDataProvider using local file system. This implementation reads registry data from a mounted file instead of calling the Kubernetes API. It is designed to work with ConfigMaps mounted as volumes in Kubernetes deployments.
func NewFileRegistryDataProvider ¶
func NewFileRegistryDataProvider(filePath, registryName string) *FileRegistryDataProvider
NewFileRegistryDataProvider creates a new file-based registry data provider. The filePath parameter should point to the registry.json file, typically mounted from a ConfigMap. The registryName parameter specifies the registry identifier for business logic purposes.
func (*FileRegistryDataProvider) GetRegistryData ¶
GetRegistryData implements RegistryDataProvider.GetRegistryData. It reads the registry.json file from the local filesystem and parses it into a Registry struct.
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.
type K8sDeploymentProvider ¶
type K8sDeploymentProvider struct {
// contains filtered or unexported fields
}
K8sDeploymentProvider implements DeploymentProvider using Kubernetes API. This implementation queries Kubernetes MCPServer custom resources to find deployed MCP servers.
func NewK8sDeploymentProvider ¶
func NewK8sDeploymentProvider(config *rest.Config, registryName string) (*K8sDeploymentProvider, error)
NewK8sDeploymentProvider creates a new Kubernetes-based deployment provider.
func (*K8sDeploymentProvider) GetDeployedServer ¶
func (p *K8sDeploymentProvider) GetDeployedServer(ctx context.Context, name string) ([]*DeployedServer, error)
GetDeployedServer implements DeploymentProvider.GetDeployedServer. It finds all deployed servers that have the specified name as their server-registry-name label value.
func (*K8sDeploymentProvider) ListDeployedServers ¶
func (p *K8sDeploymentProvider) ListDeployedServers(ctx context.Context) ([]*DeployedServer, error)
ListDeployedServers implements DeploymentProvider.ListDeployedServers. It queries Kubernetes MCPServer custom resources across all namespaces to find deployed MCP servers.
type K8sRegistryDataProvider ¶
type K8sRegistryDataProvider struct {
// contains filtered or unexported fields
}
K8sRegistryDataProvider implements RegistryDataProvider using Kubernetes ConfigMaps. This implementation fetches registry data from a ConfigMap in a Kubernetes cluster.
func NewK8sRegistryDataProvider ¶
func NewK8sRegistryDataProvider( kubeClient kubernetes.Interface, configMapName, namespace, registryName string, ) *K8sRegistryDataProvider
NewK8sRegistryDataProvider creates a new Kubernetes-based registry data provider. It requires a Kubernetes client, the ConfigMap details where registry data is stored, and the registry name identifier for business logic purposes.
func (*K8sRegistryDataProvider) GetRegistryData ¶
GetRegistryData implements RegistryDataProvider.GetRegistryData. It fetches the ConfigMap from Kubernetes and extracts the registry.json data.
func (*K8sRegistryDataProvider) GetRegistryName ¶
func (p *K8sRegistryDataProvider) GetRegistryName() string
GetRegistryName implements RegistryDataProvider.GetRegistryName. It returns the injected registry name identifier.
func (*K8sRegistryDataProvider) GetSource ¶
func (p *K8sRegistryDataProvider) GetSource() string
GetSource implements RegistryDataProvider.GetSource. It returns a descriptive string indicating the ConfigMap source.
type Option ¶
type Option func(*regSvc)
Option is a functional option for configuring the regSvc
func WithCacheDuration ¶
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.
GetRegistryData(ctx context.Context) (*registry.Registry, error)
// GetSource returns a descriptive string about where the registry data comes from.
// Examples: "configmap:namespace/name", "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 RegistryProviderConfig ¶
type RegistryProviderConfig struct {
Type RegistryProviderType
ConfigMap *ConfigMapProviderConfig
File *FileProviderConfig
}
RegistryProviderConfig holds configuration for creating a registry data provider
func (*RegistryProviderConfig) Validate ¶
func (c *RegistryProviderConfig) Validate() error
Validate validates the RegistryProviderConfig
type RegistryProviderFactory ¶
type RegistryProviderFactory interface {
// CreateProvider creates a registry data provider based on the provided configuration
CreateProvider(config *RegistryProviderConfig) (RegistryDataProvider, error)
}
RegistryProviderFactory creates registry data providers based on configuration
func NewRegistryProviderFactory ¶
func NewRegistryProviderFactory() RegistryProviderFactory
NewRegistryProviderFactory creates a new default registry provider factory
type RegistryProviderType ¶
type RegistryProviderType string
RegistryProviderType represents the type of registry data provider
const ( // RegistryProviderTypeConfigMap represents a ConfigMap-based registry provider RegistryProviderTypeConfigMap RegistryProviderType = "configmap" // RegistryProviderTypeFile represents a file-based registry provider RegistryProviderTypeFile RegistryProviderType = "file" )
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) (*registry.Registry, string, error) // returns registry, source, error
// ListServers returns all servers in the registry
ListServers(ctx context.Context) ([]registry.ServerMetadata, error)
// GetServer returns a specific server by name
GetServer(ctx context.Context, name string) (registry.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.