config

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package config provides configuration management for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFlags

func BindFlags(cmd *cobra.Command)

BindFlags binds both root and server-specific command line flags to viper. This is a helper function that calls BindRootFlags and BindServerFlags.

Parameters:

  • cmd: The cobra command to bind flags to.

func BindRootFlags

func BindRootFlags(cmd *cobra.Command)

BindRootFlags binds the global/persistent flags to viper. It sets up environment variable reading (MCPANY_ prefix) and defines flags for: - mcp-listen-address - config-path - metrics-listen-address - debug - log-level - logfile

Parameters:

  • cmd: The cobra command to bind flags to.

func BindServerFlags

func BindServerFlags(cmd *cobra.Command)

BindServerFlags binds server-specific flags to viper. It defines flags for: - grpc-port - stdio - shutdown-timeout - api-key - profiles

Parameters:

  • cmd: The cobra command to bind flags to.

func GenerateDocumentation added in v0.0.2

func GenerateDocumentation(ctx context.Context, cfg *configv1.McpAnyServerConfig) (string, error)

GenerateDocumentation generates Markdown documentation for the tools defined in the configuration.

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.
  • binaryType: The type of binary running the code (e.g., "server", "worker").

Returns:

  • A validated `McpAnyServerConfig` object.
  • An error if loading or validation fails.

func ValidateConfigAgainstSchema

func ValidateConfigAgainstSchema(rawConfig map[string]interface{}) error

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 is the type of content (e.g., "file", "dir").
	Type string `json:"type"`
	// HTMLURL is the URL to view the content on GitHub.
	HTMLURL string `json:"html_url"`
	// DownloadURL is the URL to download the content (only for files).
	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

func NewEngine(path string) (Engine, error)

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

func NewFileStore(fs afero.Fs, paths []string) *FileStore

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

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

type GRPCServiceData struct {
	Name              string
	Address           string
	ReflectionEnabled bool
}

GRPCServiceData holds the data required to generate a gRPC service configuration. It is used as the data context for the grpcServiceTemplate.

type Generator

type Generator struct {
	Reader *bufio.Reader
}

Generator handles the interactive generation of configuration files. It prompts the user for input and uses templates to generate YAML configuration for different types of services (HTTP, gRPC, OpenAPI, GraphQL).

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new Generator instance that reads from standard input.

Returns:

  • A pointer to a new Generator initialized with os.Stdin.

func (*Generator) Generate

func (g *Generator) Generate() ([]byte, error)

Generate prompts the user for service details and returns the generated configuration as a byte slice. It supports multiple service types including HTTP, gRPC, OpenAPI, and GraphQL.

Returns:

  • A byte slice containing the generated YAML configuration.
  • An error if the generation fails or the user provides invalid 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

func NewGitHub(_ context.Context, rawURL string) (*GitHub, error)

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 pointer to a new GitHub client.
  • An error if the URL is invalid.

func (*GitHub) List

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 objects.
  • An error if the fetch fails.

func (*GitHub) ToRawContentURL

func (g *GitHub) ToRawContentURL() string

ToRawContentURL constructs the raw content URL for the configured GitHub path.

Returns:

  • The raw content URL string.

type GraphQLServiceData

type GraphQLServiceData struct {
	Name         string
	Address      string
	CallName     string
	SelectionSet string
}

GraphQLServiceData holds the data required to generate a GraphQL service configuration. It is used as the data context for the graphqlServiceTemplate.

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. It is used as the data context for the httpServiceTemplate.

type MockWatcher

type MockWatcher struct {
	WatchFunc func(paths []string, reloadFunc func())
	CloseFunc func()
}

MockWatcher is a mock implementation of the Watcher for testing.

func NewMockWatcher

func NewMockWatcher() *MockWatcher

NewMockWatcher creates a new mock watcher.

func (*MockWatcher) Close

func (m *MockWatcher) Close()

Close mocks the Close method.

func (*MockWatcher) Watch

func (m *MockWatcher) Watch(paths []string, reloadFunc func()) error

Watch mocks the Watch method.

type OpenAPIServiceData

type OpenAPIServiceData struct {
	Name     string
	SpecPath string
}

OpenAPIServiceData holds the data required to generate an OpenAPI service configuration. It is used as the data context for the openapiServiceTemplate.

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) APIKey

func (s *Settings) APIKey() string

APIKey returns the API key for the server.

func (*Settings) ConfigPaths

func (s *Settings) ConfigPaths() []string

ConfigPaths returns the paths to the configuration files.

func (*Settings) GRPCPort

func (s *Settings) GRPCPort() string

GRPCPort returns the gRPC port.

func (*Settings) IsDebug

func (s *Settings) IsDebug() bool

IsDebug returns whether debug mode is enabled.

func (*Settings) Load

func (s *Settings) Load(cmd *cobra.Command, fs afero.Fs) error

Load initializes the global settings from the command line and config files.

func (*Settings) LogFile

func (s *Settings) LogFile() string

LogFile returns the path to the log file.

func (*Settings) LogFormat added in v0.0.2

LogFormat returns the current log format as a protobuf enum.

func (*Settings) LogLevel

LogLevel returns the current log level as a protobuf enum.

func (*Settings) MCPListenAddress

func (s *Settings) MCPListenAddress() string

MCPListenAddress returns the MCP listen address.

func (*Settings) MetricsListenAddress

func (s *Settings) MetricsListenAddress() string

MetricsListenAddress returns the metrics listen address.

func (*Settings) Profiles

func (s *Settings) Profiles() []string

Profiles returns the active profiles.

func (*Settings) SetAPIKey

func (s *Settings) SetAPIKey(key string)

SetAPIKey sets the Global API key.

func (*Settings) ShutdownTimeout

func (s *Settings) ShutdownTimeout() time.Duration

ShutdownTimeout returns the graceful shutdown timeout.

func (*Settings) Stdio

func (s *Settings) Stdio() bool

Stdio returns whether stdio mode is enabled.

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

LoadAndMergeServices loads all upstream services from the given configuration, including local and remote collections, and merges them.

type ValidationError

type ValidationError struct {
	ServiceName string
	Err         error
}

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.

type Watcher

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

Watcher monitors configuration files for changes and triggers a reload.

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher creates a new file watcher.

Returns:

  • A pointer to a new Watcher.
  • An error if the watcher creation fails.

func (*Watcher) Close

func (w *Watcher) Close()

Close stops the file watcher.

func (*Watcher) Watch

func (w *Watcher) Watch(paths []string, reloadFunc func()) error

Watch starts monitoring the specified configuration paths.

Parameters:

  • paths: A slice of file or directory paths to watch.
  • reloadFunc: The function to call when a change is detected.

Returns:

  • An error if watching fails.

Jump to

Keyboard shortcuts

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