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 ¶
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 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 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 string) *K8sRegistryDataProvider
NewK8sRegistryDataProvider creates a new Kubernetes-based registry data provider. It requires a Kubernetes client and the ConfigMap details where registry data is stored.
func (*K8sRegistryDataProvider) GetRegistryData ¶
GetRegistryData implements RegistryDataProvider.GetRegistryData. It fetches the ConfigMap from Kubernetes and extracts the registry.json data.
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
}
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 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.