sources

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: 21 Imported by: 0

Documentation

Overview

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

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

Architecture:

  • RegistryHandler: Interface for fetching and validating registry data
  • StorageManager: Interface for persisting registry data to local storage
  • RegistryDataValidator: Validates and parses registry data in different formats
  • FetchResult: Strongly-typed result containing Registry instances with metadata

Current implementations:

  • GitRegistryHandler: Retrieves registry data from Git repositories Supports public repos via HTTPS with branch/tag/commit checkout
  • APIRegistryHandler: Retrieves registry data from HTTP/HTTPS endpoints Delegates to format-specific handlers (ToolHiveAPIHandler, UpstreamAPIHandler)
  • FileRegistryHandler: Retrieves registry data from local filesystem Supports both absolute and relative file paths for development and production
  • FileStorageManager: Persists Registry data to local file storage for serving

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

Index

Constants

View Source
const (
	// DefaultRegistryDataFile is the default file name for the registry data in Git sources
	DefaultRegistryDataFile = "registry.json"
)
View Source
const (
	// DefaultURLTimeout is the default timeout for URL requests
	DefaultURLTimeout = 30 * time.Second
)
View Source
const (
	// RegistryFileName is the name of the registry data file
	RegistryFileName = "registry.json"
)

Variables

This section is empty.

Functions

func NewUpstreamAPIHandler

func NewUpstreamAPIHandler(httpClient httpclient.Client) *upstreamAPIHandler

NewUpstreamAPIHandler creates a new upstream MCP Registry API handler

Types

type FetchResult

type FetchResult struct {
	// Registry is the parsed registry data in unified UpstreamRegistry format
	Registry *toolhivetypes.UpstreamRegistry

	// 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 *toolhivetypes.UpstreamRegistry, hash string, format string) *FetchResult

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

type RegistryDataValidator added in v0.3.0

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

RegistryDataValidator is an interface for validating registry source configurations

func NewRegistryDataValidator added in v0.3.0

func NewRegistryDataValidator() RegistryDataValidator

NewRegistryDataValidator creates a new default registry data validator

type RegistryHandler added in v0.3.0

type RegistryHandler interface {
	// FetchRegistry retrieves data from the source and returns the result
	FetchRegistry(ctx context.Context, regCfg *config.RegistryConfig) (*FetchResult, error)

	// Validate validates the registry configuration
	Validate(regCfg *config.RegistryConfig) error

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

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

func NewAPIRegistryHandler added in v0.3.0

func NewAPIRegistryHandler() RegistryHandler

NewAPIRegistryHandler creates a new API registry handler

func NewFileRegistryHandler added in v0.3.0

func NewFileRegistryHandler() RegistryHandler

NewFileRegistryHandler creates a new file registry handler

func NewFileRegistryHandlerWithClient added in v0.4.0

func NewFileRegistryHandlerWithClient(client httpclient.Client) RegistryHandler

NewFileRegistryHandlerWithClient creates a new file registry handler with a custom HTTP client This is useful for testing

func NewGitRegistryHandler added in v0.3.0

func NewGitRegistryHandler() RegistryHandler

NewGitRegistryHandler creates a new Git registry handler

type RegistryHandlerFactory added in v0.3.0

type RegistryHandlerFactory interface {
	// CreateHandler creates a registry handler for the given registry configuration
	// The source type is inferred from which field is present (Git/API/File)
	CreateHandler(regCfg *config.RegistryConfig) (RegistryHandler, error)
}

RegistryHandlerFactory creates registry handlers based on registry configuration

func NewRegistryHandlerFactory added in v0.3.0

func NewRegistryHandlerFactory() RegistryHandlerFactory

NewRegistryHandlerFactory creates a new registry handler factory

type StorageManager

type StorageManager interface {
	// Store saves a UpstreamRegistry instance to persistent storage for a specific registry
	Store(ctx context.Context, registryName string, reg *toolhivetypes.UpstreamRegistry) error

	// Get retrieves and parses registry data from persistent storage for a specific registry
	Get(ctx context.Context, registryName string) (*toolhivetypes.UpstreamRegistry, error)

	// GetAll retrieves and parses registry data from all registries
	GetAll(ctx context.Context) (map[string]*toolhivetypes.UpstreamRegistry, error)

	// Delete removes registry data from persistent storage for a specific registry
	Delete(ctx context.Context, registryName string) error
}

StorageManager defines the interface for registry data persistence

func NewFileStorageManager

func NewFileStorageManager(basePath string) StorageManager

NewFileStorageManager creates a new file-based storage manager

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