Documentation
¶
Overview ¶
Package config provides configuration management for the application.
Index ¶
- func BindFlags(cmd *cobra.Command)
- func BindRootFlags(cmd *cobra.Command)
- func BindServerFlags(cmd *cobra.Command)
- func GenerateSchemaFromProto(msg protoreflect.Message) (*jsonschema.Schema, error)
- func LoadServices(store Store, binaryType string) (*configv1.McpAnyServerConfig, error)
- func ValidateConfigAgainstSchema(rawConfig map[string]interface{}) error
- func ValidateOrError(service *configv1.UpstreamServiceConfig) error
- type BinaryType
- type Content
- type Engine
- type FileStore
- type GRPCServiceData
- type Generator
- type GitHub
- type GraphQLServiceData
- type HTTPServiceData
- type MockWatcher
- type OpenAPIServiceData
- type Settings
- func (s *Settings) APIKey() string
- func (s *Settings) ConfigPaths() []string
- func (s *Settings) GRPCPort() string
- func (s *Settings) IsDebug() bool
- func (s *Settings) Load(cmd *cobra.Command, fs afero.Fs) error
- func (s *Settings) LogFile() string
- func (s *Settings) LogLevel() configv1.GlobalSettings_LogLevel
- func (s *Settings) MCPListenAddress() string
- func (s *Settings) MetricsListenAddress() string
- func (s *Settings) Profiles() []string
- func (s *Settings) SetAPIKey(key string)
- func (s *Settings) ShutdownTimeout() time.Duration
- func (s *Settings) Stdio() bool
- type Store
- type UpstreamServiceManager
- type ValidationError
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindRootFlags ¶
BindRootFlags binds the global/persistent flags to viper.
func BindServerFlags ¶
BindServerFlags binds server-specific flags to viper.
func GenerateSchemaFromProto ¶
func GenerateSchemaFromProto(msg protoreflect.Message) (*jsonschema.Schema, error)
GenerateSchemaFromProto generates a jsonschema from a protobuf message using reflection.
func LoadServices ¶
func LoadServices(store Store, binaryType string) (*configv1.McpAnyServerConfig, error)
LoadServices loads, validates, and processes the MCP Any server configuration from a given store. It orchestrates the reading of the configuration, validates its contents, and returns a sanitized configuration object.
If the provided store is empty or contains no configuration files, a default, empty configuration is returned.
Parameters:
- store: The configuration store from which to load the configuration.
Returns a validated `McpAnyServerConfig` or an error if loading or validation fails.
func ValidateConfigAgainstSchema ¶
ValidateConfigAgainstSchema validates the raw configuration map against the generated JSON schema.
func ValidateOrError ¶
func ValidateOrError(service *configv1.UpstreamServiceConfig) error
ValidateOrError validates a single upstream service configuration and returns an error if it's invalid.
Types ¶
type BinaryType ¶
type BinaryType int
BinaryType defines the type of the binary being validated.
const ( // Server represents the server binary. Server BinaryType = iota // Worker represents the worker binary. Worker // Client represents the client binary. Client )
type Content ¶
type Content struct {
Type string `json:"type"`
HTMLURL string `json:"html_url"`
DownloadURL string `json:"download_url"`
}
Content represents a file or directory in a GitHub repository.
type Engine ¶
type Engine interface {
// Unmarshal parses the given byte slice and populates the provided
// proto.Message.
Unmarshal(b []byte, v proto.Message) error
}
Engine defines the interface for configuration unmarshaling from different file formats. Implementations of this interface are responsible for parsing a byte slice and populating a protobuf message.
func NewEngine ¶
NewEngine returns a configuration engine capable of unmarshaling the format indicated by the file extension of the given path. It supports `.json`, `.yaml`, `.yml`, and `.textproto` file formats.
Parameters:
- path: The file path used to determine the configuration format.
Returns an `Engine` implementation for the corresponding file format, or an error if the format is not supported.
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore implements the `Store` interface for loading configurations from one or more files or directories on a filesystem. It supports multiple file formats (JSON, YAML, and textproto) and merges the configurations into a single `McpAnyServerConfig`.
func NewFileStore ¶
NewFileStore creates a new FileStore with the given filesystem and a list of paths to load configurations from.
Parameters:
- fs: The filesystem interface to use for file operations.
- paths: A slice of file or directory paths to scan for configuration files.
Returns a new instance of `FileStore`.
func (*FileStore) Load ¶
func (s *FileStore) Load() (*configv1.McpAnyServerConfig, error)
Load scans the configured paths for supported configuration files (JSON, YAML, and textproto), reads them, unmarshals their contents, and merges them into a single `McpAnyServerConfig`.
The files are processed in alphabetical order, and configurations from later files are merged into earlier ones. This allows for a cascading configuration setup where base configurations can be overridden by more specific ones.
Returns the merged `McpAnyServerConfig` or an error if any part of the process fails.
type GRPCServiceData ¶
GRPCServiceData holds the data required to generate a gRPC service configuration.
type Generator ¶
Generator handles the interactive generation of configuration files. It prompts the user for input and uses templates to generate YAML configuration.
func NewGenerator ¶
func NewGenerator() *Generator
NewGenerator creates a new Generator instance that reads from standard input.
type GitHub ¶
type GitHub struct {
Owner string
Repo string
Path string
Ref string
URLType string
// contains filtered or unexported fields
}
GitHub represents a client for interacting with the GitHub API to fetch configuration files or directories.
func NewGitHub ¶
NewGitHub creates a new GitHub client by parsing a GitHub URL. It supports standard GitHub URLs for repositories, trees, and blobs.
Parameters:
- ctx: The context for the client creation.
- rawURL: The GitHub URL to parse.
Returns a new GitHub client or an error if the URL is invalid.
func (*GitHub) List ¶
func (g *GitHub) List(ctx context.Context, auth *configv1.UpstreamAuthentication) ([]Content, error)
List fetches the contents of the configured GitHub path. It handles authentication if provided and returns a list of Content objects.
Parameters:
- ctx: The context for the request.
- auth: Optional authentication configuration for accessing private repos.
Returns a slice of Content or an error if the fetch fails.
func (*GitHub) ToRawContentURL ¶
ToRawContentURL constructs the raw content URL for the configured GitHub path.
type GraphQLServiceData ¶
GraphQLServiceData holds the data required to generate a GraphQL service configuration.
type HTTPServiceData ¶
type HTTPServiceData struct {
Name string
Address string
OperationID string
Description string
Method string
EndpointPath string
}
HTTPServiceData holds the data required to generate an HTTP service configuration.
type MockWatcher ¶
type MockWatcher struct {
WatchFunc func(paths []string, reloadFunc func())
CloseFunc func()
}
MockWatcher is a mock implementation of the Watcher for testing.
func (*MockWatcher) Watch ¶
func (m *MockWatcher) Watch(paths []string, reloadFunc func()) error
Watch mocks the Watch method.
type OpenAPIServiceData ¶
OpenAPIServiceData holds the data required to generate an OpenAPI service configuration.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings defines the global configuration for the application.
func GlobalSettings ¶
func GlobalSettings() *Settings
GlobalSettings returns the singleton instance of the global settings.
func (*Settings) ConfigPaths ¶
ConfigPaths returns the paths to the configuration files.
func (*Settings) Load ¶
Load initializes the global settings from the command line and config files.
func (*Settings) LogLevel ¶
func (s *Settings) LogLevel() configv1.GlobalSettings_LogLevel
LogLevel returns the current log level as a protobuf enum.
func (*Settings) MCPListenAddress ¶
MCPListenAddress returns the MCP listen address.
func (*Settings) MetricsListenAddress ¶
MetricsListenAddress returns the metrics listen address.
func (*Settings) ShutdownTimeout ¶
ShutdownTimeout returns the graceful shutdown timeout.
type Store ¶
type Store interface {
// Load retrieves and returns the McpAnyServerConfig.
Load() (*configv1.McpAnyServerConfig, error)
}
Store defines the interface for loading MCP-X server configurations. Implementations of this interface provide a way to retrieve the complete server configuration from a source, such as a file or a remote service.
type UpstreamServiceManager ¶
type UpstreamServiceManager struct {
// contains filtered or unexported fields
}
UpstreamServiceManager manages the loading and merging of upstream services.
func NewUpstreamServiceManager ¶
func NewUpstreamServiceManager(enabledProfiles []string) *UpstreamServiceManager
NewUpstreamServiceManager creates a new UpstreamServiceManager.
func (*UpstreamServiceManager) LoadAndMergeServices ¶
func (m *UpstreamServiceManager) LoadAndMergeServices(ctx context.Context, config *configv1.McpAnyServerConfig) ([]*configv1.UpstreamServiceConfig, error)
LoadAndMergeServices loads all upstream services from the given configuration, including local and remote collections, and merges them.
type ValidationError ¶
ValidationError encapsulates a validation error for a specific service.
func Validate ¶
func Validate(config *configv1.McpAnyServerConfig, binaryType BinaryType) []ValidationError
Validate inspects the given McpAnyServerConfig for correctness and consistency. It iterates through the list of upstream services, checking for valid service definitions, addresses, cache settings, and authentication configurations.
Invalid services are not removed from the configuration; instead, a list of validation errors is returned.
config is the server configuration to be validated.
It returns a slice of ValidationErrors, which will be empty if the configuration is valid.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error returns the formatted error message.