registry

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 21 Imported by: 5

Documentation

Overview

Package registry provides access to the MCP server registry

Index

Constants

View Source
const ToolhiveExtensionKey = "x-dev.toolhive"

ToolhiveExtensionKey is the key used for ToolHive-specific metadata in the x-publisher field

Variables

This section is empty.

Functions

func ConvertServerJSON added in v0.6.3

func ConvertServerJSON(serverJSON *v0.ServerJSON) (types.ServerMetadata, error)

ConvertServerJSON converts an MCP Registry API ServerJSON to ToolHive ServerMetadata Uses converters from converters.go (same package) Note: Only handles OCI packages and remote servers, skips npm/pypi by design

func ConvertServersToMetadata added in v0.6.3

func ConvertServersToMetadata(servers []*v0.ServerJSON) ([]types.ServerMetadata, error)

ConvertServersToMetadata converts a slice of ServerJSON to a slice of ServerMetadata Skips servers that cannot be converted (e.g., incomplete entries) Uses official converters from toolhive-registry package

func ConvertUpstreamToToolhive added in v0.2.12

func ConvertUpstreamToToolhive(upstream *UpstreamServerDetail) (types.ServerMetadata, error)

ConvertUpstreamToToolhive converts an upstream server detail to toolhive format

func ResetDefaultProvider added in v0.2.4

func ResetDefaultProvider()

ResetDefaultProvider clears the cached default provider instance This allows the provider to be recreated with updated configuration. This function is thread-safe and can be called concurrently. The mutex is required here because we're modifying the sync.Once itself, which is not a thread-safe operation.

func ValidateEmbeddedRegistry added in v0.2.8

func ValidateEmbeddedRegistry() error

ValidateEmbeddedRegistry validates the embedded registry.json against the schema

func ValidateRegistrySchema added in v0.2.8

func ValidateRegistrySchema(registryData []byte) error

ValidateRegistrySchema validates registry JSON data against the registry schema

Types

type APIRegistryProvider added in v0.6.3

type APIRegistryProvider struct {
	*BaseProvider
	// contains filtered or unexported fields
}

APIRegistryProvider provides registry data from an MCP Registry API endpoint It queries the API on-demand for each operation, ensuring fresh data.

func NewAPIRegistryProvider added in v0.6.3

func NewAPIRegistryProvider(apiURL string, allowPrivateIp bool) (*APIRegistryProvider, error)

NewAPIRegistryProvider creates a new API registry provider

func (*APIRegistryProvider) GetImageServer added in v0.6.3

func (p *APIRegistryProvider) GetImageServer(name string) (*types.ImageMetadata, error)

GetImageServer returns a specific container server by name (overrides BaseProvider) This override is necessary because BaseProvider.GetImageServer calls p.GetServer, which would call BaseProvider.GetServer instead of APIRegistryProvider.GetServer

func (*APIRegistryProvider) GetRegistry added in v0.6.3

func (p *APIRegistryProvider) GetRegistry() (*types.Registry, error)

GetRegistry returns the registry data by fetching all servers from the API This method queries the API and converts all servers to ToolHive format. Note: This can be slow for large registries as it fetches everything.

func (*APIRegistryProvider) GetServer added in v0.6.3

func (p *APIRegistryProvider) GetServer(name string) (types.ServerMetadata, error)

GetServer returns a specific server by name (queries API directly)

func (*APIRegistryProvider) ListServers added in v0.6.3

func (p *APIRegistryProvider) ListServers() ([]types.ServerMetadata, error)

ListServers returns all servers from the API

func (*APIRegistryProvider) SearchServers added in v0.6.3

func (p *APIRegistryProvider) SearchServers(query string) ([]types.ServerMetadata, error)

SearchServers searches for servers matching the query (queries API directly)

type BaseProvider added in v0.2.6

type BaseProvider struct {
	// GetRegistryFunc is a function that fetches the registry data
	// This allows different providers to implement their own data fetching logic
	GetRegistryFunc func() (*types.Registry, error)
}

BaseProvider provides common implementation for registry providers

func NewBaseProvider added in v0.2.6

func NewBaseProvider(getRegistry func() (*types.Registry, error)) *BaseProvider

NewBaseProvider creates a new base provider with the given registry function

func (*BaseProvider) GetImageServer added in v0.2.6

func (p *BaseProvider) GetImageServer(name string) (*types.ImageMetadata, error)

GetImageServer returns a specific container server by name (legacy method)

func (*BaseProvider) GetServer added in v0.2.6

func (p *BaseProvider) GetServer(name string) (types.ServerMetadata, error)

GetServer returns a specific server by name (container or remote)

func (*BaseProvider) ListImageServers added in v0.2.6

func (p *BaseProvider) ListImageServers() ([]*types.ImageMetadata, error)

ListImageServers returns all container servers (legacy method)

func (*BaseProvider) ListServers added in v0.2.6

func (p *BaseProvider) ListServers() ([]types.ServerMetadata, error)

ListServers returns all servers (both container and remote)

func (*BaseProvider) SearchImageServers added in v0.2.6

func (p *BaseProvider) SearchImageServers(query string) ([]*types.ImageMetadata, error)

SearchImageServers searches for container servers matching the query (legacy method)

func (*BaseProvider) SearchServers added in v0.2.6

func (p *BaseProvider) SearchServers(query string) ([]types.ServerMetadata, error)

SearchServers searches for servers matching the query (both container and remote)

type CachedAPIRegistryProvider added in v0.6.3

type CachedAPIRegistryProvider struct {
	*APIRegistryProvider
	// contains filtered or unexported fields
}

CachedAPIRegistryProvider wraps APIRegistryProvider with caching support. Provides both in-memory and optional persistent file caching. Works for both CLI (with persistent cache) and API server (memory only).

func NewCachedAPIRegistryProvider added in v0.6.3

func NewCachedAPIRegistryProvider(apiURL string, allowPrivateIp bool, usePersistent bool) (*CachedAPIRegistryProvider, error)

NewCachedAPIRegistryProvider creates a new cached API registry provider. If usePersistent is true, it will use a file cache in ~/.toolhive/cache/

func (*CachedAPIRegistryProvider) ConvertServerJSON added in v0.6.3

func (*CachedAPIRegistryProvider) ConvertServerJSON(serverJSON *v0.ServerJSON) (types.ServerMetadata, error)

ConvertServerJSON wraps ConvertServerJSON for cached provider

func (*CachedAPIRegistryProvider) ConvertServersToMetadataWithCache added in v0.6.3

func (*CachedAPIRegistryProvider) ConvertServersToMetadataWithCache(servers []*v0.ServerJSON) ([]types.ServerMetadata, error)

ConvertServersToMetadataWithCache wraps ConvertServersToMetadata for cached provider

func (*CachedAPIRegistryProvider) ForceRefresh added in v0.6.3

func (p *CachedAPIRegistryProvider) ForceRefresh() error

ForceRefresh forces a cache refresh, ignoring TTL.

func (*CachedAPIRegistryProvider) GetImageServer added in v0.6.3

func (p *CachedAPIRegistryProvider) GetImageServer(name string) (*types.ImageMetadata, error)

GetImageServer returns a specific container server by name (uses cache).

func (*CachedAPIRegistryProvider) GetRegistry added in v0.6.3

func (p *CachedAPIRegistryProvider) GetRegistry() (*types.Registry, error)

GetRegistry returns the registry data, using cache if valid. Falls back to stale cache if API is unavailable.

func (*CachedAPIRegistryProvider) GetRemoteServer added in v0.6.3

func (p *CachedAPIRegistryProvider) GetRemoteServer(name string) (*types.RemoteServerMetadata, error)

GetRemoteServer returns a specific remote server by name (uses cache).

func (*CachedAPIRegistryProvider) GetServer added in v0.6.3

GetServer returns a specific server by name (overrides base to use cache).

func (*CachedAPIRegistryProvider) GetServerWithContext added in v0.6.3

func (p *CachedAPIRegistryProvider) GetServerWithContext(ctx context.Context, name string) (types.ServerMetadata, error)

GetServerWithContext returns a specific server by name with context support

func (*CachedAPIRegistryProvider) ListServers added in v0.6.3

func (p *CachedAPIRegistryProvider) ListServers() ([]types.ServerMetadata, error)

ListServers returns all servers from cache.

func (*CachedAPIRegistryProvider) SearchServers added in v0.6.3

func (p *CachedAPIRegistryProvider) SearchServers(query string) ([]types.ServerMetadata, error)

SearchServers searches for servers, using cached data.

type LocalRegistryProvider added in v0.2.2

type LocalRegistryProvider struct {
	*BaseProvider
	// contains filtered or unexported fields
}

LocalRegistryProvider provides registry data from embedded JSON files or local files

func NewLocalRegistryProvider added in v0.2.2

func NewLocalRegistryProvider(filePath ...string) *LocalRegistryProvider

NewLocalRegistryProvider creates a new local registry provider If filePath is provided, it will read from that file; otherwise uses embedded data

func (*LocalRegistryProvider) GetRegistry added in v0.2.2

func (p *LocalRegistryProvider) GetRegistry() (*types.Registry, error)

GetRegistry returns the registry data from file path or embedded data

type Provider added in v0.0.43

type Provider interface {
	// GetRegistry returns the complete registry data
	GetRegistry() (*types.Registry, error)

	// GetServer returns a specific server by name (container or remote)
	GetServer(name string) (types.ServerMetadata, error)

	// SearchServers searches for servers matching the query (both container and remote)
	SearchServers(query string) ([]types.ServerMetadata, error)

	// ListServers returns all available servers (both container and remote)
	ListServers() ([]types.ServerMetadata, error)

	// Legacy methods for backward compatibility
	// GetImageServer returns a specific container server by name
	GetImageServer(name string) (*types.ImageMetadata, error)

	// SearchImageServers searches for container servers matching the query
	SearchImageServers(query string) ([]*types.ImageMetadata, error)

	// ListImageServers returns all available container servers
	ListImageServers() ([]*types.ImageMetadata, error)
}

Provider defines the interface for registry storage implementations

func GetDefaultProvider added in v0.0.43

func GetDefaultProvider() (Provider, error)

GetDefaultProvider returns the default registry provider instance This maintains backward compatibility with the existing singleton pattern

func GetDefaultProviderWithConfig added in v0.2.16

func GetDefaultProviderWithConfig(configProvider config.Provider) (Provider, error)

GetDefaultProviderWithConfig returns a registry provider using the given config provider This allows tests to inject their own config provider

func NewRegistryProvider added in v0.0.43

func NewRegistryProvider(cfg *config.Config) Provider

NewRegistryProvider creates a new registry provider based on the configuration

type RemoteRegistryProvider added in v0.0.43

type RemoteRegistryProvider struct {
	*BaseProvider
	// contains filtered or unexported fields
}

RemoteRegistryProvider provides registry data from a remote HTTP endpoint

func NewRemoteRegistryProvider added in v0.0.43

func NewRemoteRegistryProvider(registryURL string, allowPrivateIp bool) *RemoteRegistryProvider

NewRemoteRegistryProvider creates a new remote registry provider

func (*RemoteRegistryProvider) GetRegistry added in v0.0.43

func (p *RemoteRegistryProvider) GetRegistry() (*types.Registry, error)

GetRegistry returns the remote registry data

type ToolhivePublisherExtension added in v0.2.12

type ToolhivePublisherExtension struct {
	// Tier represents the tier classification level of the server
	Tier string `json:"tier,omitempty" yaml:"tier,omitempty"`
	// Transport defines the communication protocol for the server
	Transport string `json:"transport,omitempty" yaml:"transport,omitempty"`
	// Tools is a list of tool names provided by this MCP server
	Tools []string `json:"tools,omitempty" yaml:"tools,omitempty"`
	// Metadata contains additional information about the server
	Metadata *types.Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	// Tags are categorization labels for the server
	Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
	// CustomMetadata allows for additional user-defined metadata
	CustomMetadata map[string]any `json:"custom_metadata,omitempty" yaml:"custom_metadata,omitempty"`
	// Permissions defines the security profile and access permissions for the server
	Permissions *permissions.Profile `json:"permissions,omitempty" yaml:"permissions,omitempty"`
	// TargetPort is the port for the container to expose (only applicable to SSE and Streamable HTTP transports)
	TargetPort int `json:"target_port,omitempty" yaml:"target_port,omitempty"`
	// DockerTags lists the available Docker tags for this server image
	DockerTags []string `json:"docker_tags,omitempty" yaml:"docker_tags,omitempty"`
	// Provenance contains verification and signing metadata
	Provenance *types.Provenance `json:"provenance,omitempty" yaml:"provenance,omitempty"`
}

ToolhivePublisherExtension contains toolhive-specific metadata in the x-publisher field

type UpstreamArgument added in v0.2.12

type UpstreamArgument struct {
	// Type is the argument type
	Type UpstreamArgumentType `json:"type" yaml:"type"`
	// Name is the flag name for named arguments (including leading dashes)
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// ValueHint is an identifier-like hint for positional arguments
	ValueHint string `json:"value_hint,omitempty" yaml:"value_hint,omitempty"`
	// Description describes the argument's purpose
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// IsRequired indicates if the argument is required
	IsRequired bool `json:"is_required,omitempty" yaml:"is_required,omitempty"`
	// IsRepeated indicates if the argument can be repeated
	IsRepeated bool `json:"is_repeated,omitempty" yaml:"is_repeated,omitempty"`
	// Format specifies the input format
	Format UpstreamInputFormat `json:"format,omitempty" yaml:"format,omitempty"`
	// Value is the default or fixed value
	Value string `json:"value,omitempty" yaml:"value,omitempty"`
	// IsSecret indicates if the value is sensitive
	IsSecret bool `json:"is_secret,omitempty" yaml:"is_secret,omitempty"`
	// Default is the default value
	Default string `json:"default,omitempty" yaml:"default,omitempty"`
	// Choices are valid values for the argument
	Choices []string `json:"choices,omitempty" yaml:"choices,omitempty"`
	// Variables are variable substitutions for the value
	Variables map[string]UpstreamInput `json:"variables,omitempty" yaml:"variables,omitempty"`
}

UpstreamArgument represents a command-line argument

type UpstreamArgumentType added in v0.2.12

type UpstreamArgumentType string

UpstreamArgumentType represents the type of command-line argument

const (
	// UpstreamArgumentTypePositional represents a positional argument
	UpstreamArgumentTypePositional UpstreamArgumentType = "positional"
	// UpstreamArgumentTypeNamed represents a named argument (flag)
	UpstreamArgumentTypeNamed UpstreamArgumentType = "named"
)

type UpstreamInput added in v0.2.12

type UpstreamInput struct {
	// Description describes the input's purpose
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// IsRequired indicates if the input is required
	IsRequired bool `json:"is_required,omitempty" yaml:"is_required,omitempty"`
	// Format specifies the input format
	Format UpstreamInputFormat `json:"format,omitempty" yaml:"format,omitempty"`
	// Value is the default or fixed value
	Value string `json:"value,omitempty" yaml:"value,omitempty"`
	// IsSecret indicates if the value is sensitive
	IsSecret bool `json:"is_secret,omitempty" yaml:"is_secret,omitempty"`
	// Default is the default value
	Default string `json:"default,omitempty" yaml:"default,omitempty"`
	// Choices are valid values for the input
	Choices []string `json:"choices,omitempty" yaml:"choices,omitempty"`
}

UpstreamInput represents a generic input with validation and formatting

type UpstreamInputFormat added in v0.2.12

type UpstreamInputFormat string

UpstreamInputFormat represents the format of an input value

const (
	// UpstreamInputFormatString represents a string input
	UpstreamInputFormatString UpstreamInputFormat = "string"
	// UpstreamInputFormatNumber represents a numeric input
	UpstreamInputFormatNumber UpstreamInputFormat = "number"
	// UpstreamInputFormatBoolean represents a boolean input
	UpstreamInputFormatBoolean UpstreamInputFormat = "boolean"
	// UpstreamInputFormatFilepath represents a file path input
	UpstreamInputFormatFilepath UpstreamInputFormat = "filepath"
)

type UpstreamKeyValueInput added in v0.2.12

type UpstreamKeyValueInput struct {
	// Name is the variable or header name
	Name string `json:"name" yaml:"name"`
	// Description describes the input's purpose
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// IsRequired indicates if the input is required
	IsRequired bool `json:"is_required,omitempty" yaml:"is_required,omitempty"`
	// Format specifies the input format
	Format UpstreamInputFormat `json:"format,omitempty" yaml:"format,omitempty"`
	// Value is the default or fixed value
	Value string `json:"value,omitempty" yaml:"value,omitempty"`
	// IsSecret indicates if the value is sensitive
	IsSecret bool `json:"is_secret,omitempty" yaml:"is_secret,omitempty"`
	// Default is the default value
	Default string `json:"default,omitempty" yaml:"default,omitempty"`
	// Choices are valid values for the input
	Choices []string `json:"choices,omitempty" yaml:"choices,omitempty"`
	// Variables are variable substitutions for the value
	Variables map[string]UpstreamInput `json:"variables,omitempty" yaml:"variables,omitempty"`
}

UpstreamKeyValueInput represents a key-value input (environment variable or header)

type UpstreamPackage added in v0.2.12

type UpstreamPackage struct {
	// RegistryName is the package registry type (e.g., "npm", "pypi", "docker", "nuget")
	RegistryName string `json:"registry_name" yaml:"registry_name"`
	// Name is the package name in the registry
	Name string `json:"name" yaml:"name"`
	// Version is the package version
	Version string `json:"version" yaml:"version"`
	// RuntimeHint provides a hint for the appropriate runtime (e.g., "npx", "uvx", "dnx")
	RuntimeHint string `json:"runtime_hint,omitempty" yaml:"runtime_hint,omitempty"`
	// RuntimeArguments are arguments passed to the package's runtime command
	RuntimeArguments []UpstreamArgument `json:"runtime_arguments,omitempty" yaml:"runtime_arguments,omitempty"`
	// PackageArguments are arguments passed to the package's binary
	PackageArguments []UpstreamArgument `json:"package_arguments,omitempty" yaml:"package_arguments,omitempty"`
	// EnvironmentVariables are environment variables for the package
	EnvironmentVariables []UpstreamKeyValueInput `json:"environment_variables,omitempty" yaml:"environment_variables,omitempty"`
}

UpstreamPackage represents a package installation option

type UpstreamPublisher added in v0.2.12

type UpstreamPublisher struct {
	// XDevToolhive contains ToolHive-specific extension data
	XDevToolhive *ToolhivePublisherExtension `json:"x-dev.toolhive,omitempty" yaml:"x-dev.toolhive,omitempty"`
}

UpstreamPublisher contains optional publisher metadata (extension field)

type UpstreamRemote added in v0.2.12

type UpstreamRemote struct {
	// TransportType is the transport protocol type
	TransportType UpstreamTransportType `json:"transport_type" yaml:"transport_type"`
	// URL is the remote server URL
	URL string `json:"url" yaml:"url"`
	// Headers are HTTP headers to include
	Headers []UpstreamKeyValueInput `json:"headers,omitempty" yaml:"headers,omitempty"`
}

UpstreamRemote represents a remote server connection option

type UpstreamRepository added in v0.2.12

type UpstreamRepository struct {
	// URL is the repository URL
	URL string `json:"url" yaml:"url"`
	// Source is the repository hosting service (e.g., "github")
	Source string `json:"source" yaml:"source"`
	// ID is an optional repository identifier
	ID string `json:"id,omitempty" yaml:"id,omitempty"`
}

UpstreamRepository contains repository information

type UpstreamServer added in v0.2.12

type UpstreamServer struct {
	// Name is the server name/identifier (e.g., "io.modelcontextprotocol/filesystem")
	Name string `json:"name" yaml:"name"`
	// Description is a human-readable description of the server's functionality
	Description string `json:"description" yaml:"description"`
	// Status indicates the server lifecycle status
	Status UpstreamServerStatus `json:"status,omitempty" yaml:"status,omitempty"`
	// Repository contains repository information
	Repository *UpstreamRepository `json:"repository,omitempty" yaml:"repository,omitempty"`
	// VersionDetail contains version information
	VersionDetail UpstreamVersionDetail `json:"version_detail" yaml:"version_detail"`
	// Packages contains package installation options
	Packages []UpstreamPackage `json:"packages,omitempty" yaml:"packages,omitempty"`
	// Remotes contains remote server connection options
	Remotes []UpstreamRemote `json:"remotes,omitempty" yaml:"remotes,omitempty"`
}

UpstreamServer represents the core server information in the upstream format

type UpstreamServerDetail added in v0.2.12

type UpstreamServerDetail struct {
	// Server contains the core server information
	Server UpstreamServer `json:"server" yaml:"server"`
	// XPublisher contains optional publisher metadata (extension field)
	XPublisher *UpstreamPublisher `json:"x-publisher,omitempty" yaml:"x-publisher,omitempty"`
}

UpstreamServerDetail represents the upstream MCP server format as defined in the community registry This follows the schema at https://modelcontextprotocol.io/schemas/draft/2025-07-09/server.json

func ConvertToolhiveToUpstream added in v0.2.12

func ConvertToolhiveToUpstream(server types.ServerMetadata) (*UpstreamServerDetail, error)

ConvertToolhiveToUpstream converts toolhive format to upstream format

type UpstreamServerStatus added in v0.2.12

type UpstreamServerStatus string

UpstreamServerStatus represents the server lifecycle status

const (
	// UpstreamServerStatusActive indicates the server is actively maintained
	UpstreamServerStatusActive UpstreamServerStatus = "active"
	// UpstreamServerStatusDeprecated indicates the server is deprecated
	UpstreamServerStatusDeprecated UpstreamServerStatus = "deprecated"
)

type UpstreamTransportType added in v0.2.12

type UpstreamTransportType string

UpstreamTransportType represents the transport protocol type

const (
	// UpstreamTransportTypeStreamable represents streamable HTTP transport
	UpstreamTransportTypeStreamable UpstreamTransportType = "streamable"
	// UpstreamTransportTypeSSE represents Server-Sent Events transport
	UpstreamTransportTypeSSE UpstreamTransportType = "sse"
)

type UpstreamVersionDetail added in v0.2.12

type UpstreamVersionDetail struct {
	// Version is the server version (equivalent to Implementation.version in MCP spec)
	Version string `json:"version" yaml:"version"`
}

UpstreamVersionDetail contains version information

Directories

Path Synopsis
Package api provides client functionality for interacting with MCP Registry API endpoints
Package api provides client functionality for interacting with MCP Registry API endpoints
Package converters provides bidirectional conversion between toolhive registry formats and the upstream MCP (Model Context Protocol) ServerJSON format.
Package converters provides bidirectional conversion between toolhive registry formats and the upstream MCP (Model Context Protocol) ServerJSON format.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package types contains the core type definitions for the MCP registry system.
Package types contains the core type definitions for the MCP registry system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL