sources

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package sources provides interfaces and implementations for retrieving MCP registry data from various external sources.

The package defines the SourceHandler interface which abstracts the process of validating source configurations and fetching registry data from external sources such as ConfigMaps, HTTP endpoints, Git repositories, or external registries.

Architecture:

  • SourceHandler: Interface for fetching and validating registry data
  • StorageManager: Interface for persisting registry data to ConfigMaps
  • SourceDataValidator: Validates and parses registry data in different formats
  • FetchResult: Strongly-typed result containing Registry instances with metadata

Current implementations:

  • ConfigMapSourceHandler: Retrieves registry data from Kubernetes ConfigMaps Supports both ToolHive and Upstream registry formats with format validation
  • ConfigMapStorageManager: Persists Registry data to Kubernetes ConfigMaps

Future implementations may include:

  • URLSourceHandler: HTTP/HTTPS endpoints
  • GitSourceHandler: Git repositories
  • RegistrySourceHandler: External registries

The package provides a factory pattern for creating appropriate source handlers based on the source type configuration, and uses strongly-typed Registry instances throughout for type safety.

Index

Constants

View Source
const (
	// ConfigMapStorageDataKey is the key used to store registry data in ConfigMaps by the storage manager
	ConfigMapStorageDataKey = "registry.json"
	// RegistryStorageComponent is the component label for the registry storage
	RegistryStorageComponent = "registry-storage"

	// StorageTypeConfigMap identifies the ConfigMap storage manager implementation
	StorageTypeConfigMap = "configmap"
)
View Source
const (
	// ConfigMapSourceDataKey is the default key used for registry data in ConfigMap sources
	ConfigMapSourceDataKey = "registry.json"
)
View Source
const (
	// DefaultRegistryDataFile is the default file name for the registry data in Git sources
	DefaultRegistryDataFile = "registry.json"
)

Variables

This section is empty.

Functions

func EmptyJSON

func EmptyJSON(format string) []byte

EmptyJSON returns empty JSON object/array based on format

func InvalidJSON

func InvalidJSON() []byte

InvalidJSON returns intentionally malformed JSON for testing error cases

Types

type ConfigMapSourceHandler

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

ConfigMapSourceHandler handles registry data from Kubernetes ConfigMaps

func NewConfigMapSourceHandler

func NewConfigMapSourceHandler(k8sClient client.Client) *ConfigMapSourceHandler

NewConfigMapSourceHandler creates a new ConfigMap source handler

func (*ConfigMapSourceHandler) CurrentHash

func (h *ConfigMapSourceHandler) CurrentHash(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (string, error)

CurrentHash returns the current hash of the source data without performing a full fetch

func (*ConfigMapSourceHandler) FetchRegistry

func (h *ConfigMapSourceHandler) FetchRegistry(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (*FetchResult, error)

FetchRegistry retrieves registry data from the ConfigMap source

func (*ConfigMapSourceHandler) Validate

Validate validates the ConfigMap source configuration

type ConfigMapStorageManager

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

ConfigMapStorageManager implements StorageManager using Kubernetes ConfigMaps

func NewConfigMapStorageManager

func NewConfigMapStorageManager(k8sClient client.Client, scheme *runtime.Scheme) *ConfigMapStorageManager

NewConfigMapStorageManager creates a new ConfigMap-based storage manager

func (*ConfigMapStorageManager) Delete

func (s *ConfigMapStorageManager) Delete(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) error

Delete removes the storage ConfigMap

func (*ConfigMapStorageManager) Get

Get retrieves and parses registry data from a ConfigMap

func (*ConfigMapStorageManager) GetStorageReference

func (s *ConfigMapStorageManager) GetStorageReference(mcpRegistry *mcpv1alpha1.MCPRegistry) *mcpv1alpha1.StorageReference

GetStorageReference returns a reference to the ConfigMap storage

func (*ConfigMapStorageManager) GetType added in v0.3.6

func (*ConfigMapStorageManager) GetType() string

GetType returns the storage manager type

func (*ConfigMapStorageManager) Store

Store saves a Registry instance to a ConfigMap

type DefaultSourceDataValidator

type DefaultSourceDataValidator struct{}

DefaultSourceDataValidator is the default implementation of SourceValidator

func (*DefaultSourceDataValidator) ValidateData

func (*DefaultSourceDataValidator) ValidateData(data []byte, format string) (*registry.Registry, error)

ValidateData validates raw data and returns a parsed Registry

type DefaultSourceHandlerFactory

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

DefaultSourceHandlerFactory is the default implementation of SourceHandlerFactory

func (*DefaultSourceHandlerFactory) CreateHandler

func (f *DefaultSourceHandlerFactory) CreateHandler(sourceType string) (SourceHandler, error)

CreateHandler creates a source handler for the given source type

type FetchResult

type FetchResult struct {
	// Registry is the parsed registry data (replaces raw Data field)
	Registry *registry.Registry

	// Hash is the SHA256 hash of the serialized data for change detection
	Hash string

	// ServerCount is the number of servers found in the registry data
	ServerCount int

	// Format indicates the original format of the source data
	Format string
}

FetchResult contains the result of a fetch operation

func NewFetchResult

func NewFetchResult(reg *registry.Registry, hash string, format string) *FetchResult

NewFetchResult creates a new FetchResult from a Registry instance and pre-calculated hash The hash should be calculated by the source handler to ensure consistency with CurrentHash

type GitSourceHandler added in v0.3.6

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

GitSourceHandler handles registry data from Git repositories

func NewGitSourceHandler added in v0.3.6

func NewGitSourceHandler() *GitSourceHandler

NewGitSourceHandler creates a new Git source handler

func (*GitSourceHandler) CurrentHash added in v0.3.6

func (h *GitSourceHandler) CurrentHash(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (string, error)

CurrentHash returns the current hash of the source data without performing a full fetch

func (*GitSourceHandler) FetchRegistry added in v0.3.6

func (h *GitSourceHandler) FetchRegistry(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (*FetchResult, error)

FetchRegistry retrieves registry data from the Git repository

func (*GitSourceHandler) Validate added in v0.3.6

Validate validates the Git source configuration

type SourceDataValidator

type SourceDataValidator interface {
	// ValidateData validates raw data and returns a parsed Registry
	ValidateData(data []byte, format string) (*registry.Registry, error)
}

SourceDataValidator is an interface for validating registry source configurations

func NewSourceDataValidator

func NewSourceDataValidator() SourceDataValidator

NewSourceDataValidator creates a new default source validator

type SourceHandler

type SourceHandler interface {
	// FetchRegistry retrieves data from the source and returns the result
	FetchRegistry(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (*FetchResult, error)

	// Validate validates the source configuration
	Validate(source *mcpv1alpha1.MCPRegistrySource) error

	// CurrentHash returns the current hash of the source data without performing a full fetch
	CurrentHash(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (string, error)
}

SourceHandler is an interface with methods to fetch data from external data sources

type SourceHandlerFactory

type SourceHandlerFactory interface {
	// CreateHandler creates a source handler for the given source type
	CreateHandler(sourceType string) (SourceHandler, error)
}

SourceHandlerFactory creates source handlers based on source type

func NewSourceHandlerFactory

func NewSourceHandlerFactory(k8sClient client.Client) SourceHandlerFactory

NewSourceHandlerFactory creates a new source handler factory

type StorageError

type StorageError struct {
	Operation string
	Registry  string
	Message   string
	Cause     error
}

StorageError represents an error that occurred during storage operations

func NewStorageError

func NewStorageError(operation, mcpRegistry, message string, cause error) *StorageError

NewStorageError creates a new StorageError

func (*StorageError) Error

func (e *StorageError) Error() string

func (*StorageError) Unwrap

func (e *StorageError) Unwrap() error

type StorageManager

type StorageManager interface {
	// Store saves a Registry instance to persistent storage
	Store(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry, reg *registry.Registry) error

	// Get retrieves and parses registry data from persistent storage
	Get(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) (*registry.Registry, error)

	// Delete removes registry data from persistent storage
	Delete(ctx context.Context, mcpRegistry *mcpv1alpha1.MCPRegistry) error

	// GetStorageReference returns a reference to where the data is stored
	GetStorageReference(mcpRegistry *mcpv1alpha1.MCPRegistry) *mcpv1alpha1.StorageReference

	// GetType returns the storage manager type as a string
	GetType() string
}

StorageManager defines the interface for registry data persistence

type TestRegistryBuilder

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

TestRegistryBuilder provides a fluent interface for building test registry data

func NewTestRegistryBuilder

func NewTestRegistryBuilder(format string) *TestRegistryBuilder

NewTestRegistryBuilder creates a new test registry builder for the specified format

func (*TestRegistryBuilder) BuildJSON

func (b *TestRegistryBuilder) BuildJSON() []byte

BuildJSON returns the JSON representation of the built registry

func (*TestRegistryBuilder) BuildPrettyJSON

func (b *TestRegistryBuilder) BuildPrettyJSON() []byte

BuildPrettyJSON returns the JSON representation with indentation for readability

func (*TestRegistryBuilder) ContainerServerCount

func (b *TestRegistryBuilder) ContainerServerCount() int

ContainerServerCount returns the number of container servers only

func (*TestRegistryBuilder) Empty

Empty creates an empty registry with minimal required fields

func (*TestRegistryBuilder) GetRegistry

func (b *TestRegistryBuilder) GetRegistry() *registry.Registry

GetRegistry returns the built registry (for ToolHive format only)

func (*TestRegistryBuilder) GetUpstreamData

func (b *TestRegistryBuilder) GetUpstreamData() []registry.UpstreamServerDetail

GetUpstreamData returns the built upstream data (for Upstream format only)

func (*TestRegistryBuilder) RemoteServerCount

func (b *TestRegistryBuilder) RemoteServerCount() int

RemoteServerCount returns the number of remote servers only (ToolHive format only)

func (*TestRegistryBuilder) ServerCount

func (b *TestRegistryBuilder) ServerCount() int

ServerCount returns the number of servers (both container and remote for ToolHive format)

func (*TestRegistryBuilder) WithLastUpdated

func (b *TestRegistryBuilder) WithLastUpdated(timestamp string) *TestRegistryBuilder

WithLastUpdated sets a custom last updated timestamp (ToolHive format only)

func (*TestRegistryBuilder) WithRemoteServer

func (b *TestRegistryBuilder) WithRemoteServer(url string) *TestRegistryBuilder

WithRemoteServer adds a remote server with the given URL (only for ToolHive format)

func (*TestRegistryBuilder) WithRemoteServerName

func (b *TestRegistryBuilder) WithRemoteServerName(name, url string) *TestRegistryBuilder

WithRemoteServerName adds a remote server with a specific name and URL

func (*TestRegistryBuilder) WithServer

func (b *TestRegistryBuilder) WithServer(name string) *TestRegistryBuilder

WithServer adds a container server with the given name and default valid values

func (*TestRegistryBuilder) WithServerName

func (b *TestRegistryBuilder) WithServerName(name string) *TestRegistryBuilder

WithServerName adds a server with a specific name

func (*TestRegistryBuilder) WithVersion

func (b *TestRegistryBuilder) WithVersion(version string) *TestRegistryBuilder

WithVersion sets a custom version (ToolHive format only)

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