config

package
v0.0.0-...-5b49586 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Package config provides configuration management for the application.

Package config provides configuration management for MCP Any.

Index

Constants

View Source
const (
	// SkipSecretValidationKey is the context key to skip secret validation (e.g. for config check API).
	// Value should be a boolean.
	// Summary: Defines SkipSecretValidationKey.
	SkipSecretValidationKey contextKey = "skip_secret_validation"

	// SkipFilesystemCheckKey is the context key to skip filesystem existence checks (e.g. for config check API).
	// Value should be a boolean.
	// Summary: Defines SkipFilesystemCheckKey.
	SkipFilesystemCheckKey contextKey = "skip_filesystem_check"
)
View Source
const MergeStrategyReplace = "replace"

MergeStrategyReplace indicates that the new configuration list should replace the existing one.

Summary: Constant for "replace" merge strategy.

Variables

This section is empty.

Functions

func BindFlags

func BindFlags(cmd *cobra.Command)

BindFlags binds both root and server-specific command line flags to the Viper configuration registry.

This is a helper function that orchestrates the binding of all necessary flags by delegating to BindRootFlags and BindServerFlags.

Parameters:

  • cmd (*cobra.Command): The command instance to which the flags will be attached.

Returns:

None.

Side Effects:

  • Modifies the global Viper configuration state.
  • Registers flags on the provided Cobra command.

Summary: Executes BindFlags operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func BindRootFlags

func BindRootFlags(cmd *cobra.Command)

BindRootFlags binds the global and persistent command-line flags to the Viper configuration registry.

It establishes the connection between Cobra command flags and Viper's configuration management, enabling flag parsing and environment variable overrides (using the "MCPANY_" prefix).

Parameters:

  • cmd (*cobra.Command): The command instance to which the persistent flags will be attached.

Returns:

  • None.

Side Effects:

  • Modifies the global Viper configuration state.
  • Registers flags on the provided Cobra command.
  • Exits the application on error.

Summary: Executes BindRootFlags operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func BindServerFlags

func BindServerFlags(cmd *cobra.Command)

BindServerFlags binds server-specific command-line flags to the Viper configuration registry.

It defines flags specific to the server operation, such as port configurations, authentication keys, and runtime modes (e.g., stdio).

Parameters:

  • cmd (*cobra.Command): The command instance to which the server flags will be attached.

Returns:

None.

Side Effects:

  • Modifies the global Viper configuration state.
  • Registers flags on the provided Cobra command.
  • Exits the application on error.

Summary: Executes BindServerFlags operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func CompileSchema

func CompileSchema(schemaMap map[string]interface{}) (*jsonschema.Schema, error)

CompileSchema compiles a raw JSON schema map into a jsonschema.Schema object.

Summary: Compiles a JSON schema map into a valid schema object.

Parameters:

  • schemaMap: map[string]interface{}. The schema map to compile.

Returns:

  • *jsonschema.Schema: The compiled schema.
  • error: An error if compilation fails.

func GenerateDocumentation

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

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

Summary: Generates Markdown documentation for configured tools.

It iterates through the configured upstream services, registers their tools, and produces a Markdown formatted string describing each tool and its input schema.

Parameters:

  • ctx (context.Context): The context for the operation.
  • cfg (*configv1.McpAnyServerConfig): The server configuration containing upstream service definitions.

Returns:

  • string: A string containing the generated Markdown documentation.
  • error: An error if documentation generation fails (e.g., if a service cannot be initialized).

Errors:

  • Returns an error if an upstream service factory fails to create an upstream.

Side Effects:

  • Initializes upstream services which may have side effects (though typically only on execution).
  • Prints warnings to stderr if service registration fails.

func GenerateJSONSchemaBytes

func GenerateJSONSchemaBytes() ([]byte, error)

GenerateJSONSchemaBytes returns the JSON schema for McpAnyServerConfig as a byte slice. Side Effects: - None.

Parameters:

  • None

Returns:

  • []byte: The resulting []byte.
  • error: An error if the operation fails.

Errors:

  • Returns an error if the operation fails or is invalid.

Side Effects:

  • None

Summary: Executes GenerateJSONSchemaBytes operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func GenerateSchemaFromProto

func GenerateSchemaFromProto(msg protoreflect.Message) (*jsonschema.Schema, error)

GenerateSchemaFromProto generates a jsonschema from a protobuf message using reflection.

Summary: Generates a JSON schema object from a protobuf message descriptor.

Parameters:

  • msg: protoreflect.Message. The protobuf message to generate the schema from.

Returns:

  • *jsonschema.Schema: The generated JSON schema.
  • error: An error if the schema generation fails.

func GenerateSchemaMapFromProto

func GenerateSchemaMapFromProto(msg protoreflect.Message) map[string]interface{}

GenerateSchemaMapFromProto generates a raw JSON schema map from a protobuf message using reflection. This is useful if you want to export the schema as JSON.

Summary: Generates a raw JSON schema map from a protobuf message.

Parameters:

  • msg: protoreflect.Message. The protobuf message to generate the schema from.

Returns:

  • map[string]interface{}: The generated JSON schema map.

func HydrateSecretsInService

func HydrateSecretsInService(svc *configv1.UpstreamServiceConfig, secrets map[string]*configv1.SecretValue)

HydrateSecretsInService populates the service configuration with resolved secret values.

Summary: Populates service configuration with resolved secret values.

Parameters:

  • svc (*configv1.UpstreamServiceConfig): The upstream service configuration to modify.
  • secrets (map[string]*configv1.SecretValue): The resolved secret values map.

Returns:

None.

Errors:

None.

Side Effects:

  • Modifies the provided service configuration in place.

func LoadResolvedConfig

func LoadResolvedConfig(ctx context.Context, store Store) (*configv1.McpAnyServerConfig, error)

LoadResolvedConfig loads key resolved configuration (merging services, setting defaults) without performing strict validation.

Summary: Loads configuration with merging and defaults but without strict validation.

Parameters:

  • ctx: context.Context. The context for the operation.
  • store: Store. The configuration store.

Returns:

  • *configv1.McpAnyServerConfig: The resolved configuration.
  • error: An error if loading fails.

func LoadServices

func LoadServices(ctx context.Context, store Store, binaryType string) (*configv1.McpAnyServerConfig, error)

LoadServices loads, validates, and processes the MCP Any server configuration from a given store.

Summary: Loads and validates the server configuration.

Parameters:

  • ctx: context.Context. The context for the operation.
  • store: Store. The configuration store from which to load the configuration.
  • binaryType: string. The type of binary running the code (e.g., "server", "worker").

Returns:

  • *configv1.McpAnyServerConfig: A validated configuration object.
  • error: An error if loading or validation fails.

func StripSecretsFromAuth

func StripSecretsFromAuth(auth *configv1.Authentication)

StripSecretsFromAuth removes sensitive values from the authentication config.

Summary: Removes sensitive values from authentication config.

Parameters:

  • auth (*configv1.Authentication): The authentication configuration to modify.

Returns:

None.

Errors:

None.

Side Effects:

  • Modifies the provided authentication configuration in place.

func StripSecretsFromCollection

func StripSecretsFromCollection(collection *configv1.Collection)

StripSecretsFromCollection removes sensitive information from the service collection.

Summary: Removes sensitive information from service collection.

Parameters:

  • collection (*configv1.Collection): The service collection to modify.

Returns:

None.

Errors:

None.

Side Effects:

  • Modifies the provided service collection in place.

func StripSecretsFromProfile

func StripSecretsFromProfile(profile *configv1.ProfileDefinition)

StripSecretsFromProfile removes sensitive information from the profile definition.

Summary: Removes sensitive information from profile definition.

Parameters:

  • profile (*configv1.ProfileDefinition): The profile definition to modify.

Returns:

None.

Errors:

None.

Side Effects:

  • Modifies the provided profile definition in place.

func StripSecretsFromService

func StripSecretsFromService(svc *configv1.UpstreamServiceConfig)

StripSecretsFromService removes sensitive information from the service configuration.

Summary: Removes sensitive information from service configuration.

Parameters:

  • svc (*configv1.UpstreamServiceConfig): The upstream service configuration to modify.

Returns:

None.

Errors:

None.

Side Effects:

  • Modifies the provided service configuration in place.

func ValidateConfigAgainstSchema

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

ValidateConfigAgainstSchema validates the raw configuration map against the generated JSON schema.

Summary: Validates configuration against the JSON schema.

Parameters:

  • rawConfig: map[string]interface{}. The raw configuration data as a map.

Returns:

  • error: An error if validation fails.

func ValidateOrError

func ValidateOrError(ctx context.Context, service *configv1.UpstreamServiceConfig) error

ValidateOrError validates a single upstream service configuration and returns an error if it's invalid.

Summary: Validates a single upstream service.

Parameters:

  • ctx (context.Context): The context for the validation.
  • service (*configv1.UpstreamServiceConfig): The upstream service configuration to validate.

Returns:

  • (error): An error if validation fails.

func WrapActionableError

func WrapActionableError(context string, err error) error

WrapActionableError wraps an error with context, preserving ActionableError semantics if present.

Summary: Wraps an error with context, preserving ActionableError semantics.

If the cause is an ActionableError, it returns a new ActionableError with the context added to the error message. Otherwise, it returns a standard wrapped error.

Parameters:

  • context (string): The context message to prefix to the error.
  • err (error): The error to wrap.

Returns:

  • error: The wrapped error.

Side Effects:

  • None.

Types

type ActionableError

type ActionableError struct {
	Err        error
	Suggestion string
}

ActionableError is an error that includes a suggestion for fixing the issue.

Summary: An error type that pairs an underlying error with a user-facing suggestion.

Fields:

  • Err: error. The original error that occurred.
  • Suggestion: string. A human-readable suggestion on how to resolve the error.

func (*ActionableError) Error

func (e *ActionableError) Error() string

Error implements the error interface. Side Effects: - None.

Parameters:

  • None

Returns:

  • string: The resulting string.

Errors:

  • None

Side Effects:

  • None

Summary: Executes Error operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*ActionableError) Unwrap

func (e *ActionableError) Unwrap() error

Unwrap returns the underlying error. Side Effects: - None.

Parameters:

  • None

Returns:

  • error: An error if the operation fails.

Errors:

  • Returns an error if the operation fails or is invalid.

Side Effects:

  • None

Summary: Executes Unwrap operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type AuthValidationContext

type AuthValidationContext int

AuthValidationContext defines the context for authentication validation.

Summary: Enumeration of authentication validation contexts.

const (
	// AuthValidationContextIncoming represents incoming authentication (e.g., Users).
	// Summary: Defines AuthValidationContextIncomin.
	AuthValidationContextIncoming AuthValidationContext = iota
	// AuthValidationContextOutgoing represents outgoing authentication (e.g., Upstream Services).
	// Summary: Defines AuthValidationContextOutgoin.
	AuthValidationContextOutgoing
)

type BinaryType

type BinaryType int

BinaryType defines the type of the binary being validated.

Summary: Enumeration of binary types for validation context.

const (
	// Server represents the server binary.
	// Summary: Defines Serve.
	Server BinaryType = iota
	// Worker represents the worker binary.
	// Summary: Defines Worke.
	Worker
	// Client represents the client binary.
	// Summary: Defines Clien.
	Client
)

type ConfigurableEngine

type ConfigurableEngine interface {
	Engine
	// SetSkipValidation sets whether to skip schema validation.
	//
	// Summary: Configures the engine to skip schema validation.
	//
	// Parameters:
	//   - skip (bool): True to skip validation.
	SetSkipValidation(skip bool)

	// SetIgnoreEnv sets whether to ignore environment variables and other external overrides.
	//
	// Summary: Configures the engine to ignore environment variables.
	//
	// Parameters:
	//   - ignore (bool): True to ignore environment variables.
	SetIgnoreEnv(ignore bool)
}

ConfigurableEngine defines an interface for engines that support configuration options.

Summary: Interface for engines that can be configured (e.g. skip validation).

type Content

type Content struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	HTMLURL     string `json:"html_url"`
	DownloadURL string `json:"download_url"`
}

Content represents a file or directory in a GitHub repository.

Summary: Metadata for a file or directory in a GitHub repository.

Fields:

  • Name (string): The name of the file or directory.
  • Type (string): The type of content (e.g., "file", "dir").
  • HTMLURL (string): The URL to view the content on GitHub.
  • DownloadURL (string): The URL to download the content (only for files).

type Engine

type Engine interface {
	// Unmarshal parses the given byte slice and populates the provided proto.Message.
	//
	// Summary: Parses bytes into a protobuf message.
	//
	// Parameters:
	//   - b ([]byte): The raw bytes to parse.
	//   - v (proto.Message): The destination protobuf message.
	//
	// Returns:
	//   - (error): An error if parsing fails.
	Unmarshal(b []byte, v proto.Message) error
}

Engine defines the interface for configuration unmarshaling from different file formats.

Summary: Abstraction for parsing configuration files into protobuf messages.

func NewEngine

func NewEngine(path string) (Engine, error)

NewEngine returns a configuration engine capable of unmarshaling the format indicated by the file extension.

Summary: Factory function to create the appropriate Engine for a given file path.

Parameters:

  • path (string): The file path used to determine the configuration format.

Returns:

  • (Engine): An initialized Engine implementation.
  • (error): An error if the file extension is not supported.

type FileStore

type FileStore struct {
	IgnoreMissingEnv bool
	// contains filtered or unexported fields
}

FileStore implements the `Store` interface for loading configurations from files.

Summary: Loads configurations from the filesystem.

func NewFileStore

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

NewFileStore creates a new FileStore with the given filesystem and paths.

Summary: Initializes a new FileStore.

Parameters:

  • fs (afero.Fs): The filesystem to use.
  • paths ([]string): The list of paths to scan.

Returns:

  • (*FileStore): A new instance of FileStore.

func NewFileStoreWithSkipErrors

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

NewFileStoreWithSkipErrors creates a new FileStore that skips malformed config files.

Summary: Initializes a new FileStore that tolerates errors in config files.

Parameters:

  • fs (afero.Fs): The filesystem to use.
  • paths ([]string): The list of paths to scan.

Returns:

  • (*FileStore): A new instance of FileStore.

func (*FileStore) HasConfigSources

func (s *FileStore) HasConfigSources() bool

HasConfigSources returns true if the store has configuration paths configured. Side Effects: - None.

Parameters:

  • None

Returns:

  • bool: True if successful, false otherwise.

Errors:

  • None

Side Effects:

  • None

Summary: Checks HasConfigSources operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*FileStore) Load

Load scans the configured paths and merges them into a single configuration.

Summary: Loads and merges configurations from all configured paths.

Parameters:

  • ctx (context.Context): The context for the request.

Returns:

  • (*configv1.McpAnyServerConfig): The merged configuration.
  • (error): An error if loading or merging fails.

func (*FileStore) SetIgnoreMissingEnv

func (s *FileStore) SetIgnoreMissingEnv(ignore bool)

SetIgnoreMissingEnv configures whether to ignore missing environment variables during loading.

Returns:

  • None.

Side Effects:

  • None.

Summary: Updates SetIgnoreMissingEnv operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*FileStore) SetSkipValidation

func (s *FileStore) SetSkipValidation(skip bool)

SetSkipValidation configures whether to skip schema validation during loading.

Returns:

  • None.

Side Effects:

  • None.

Summary: Updates SetSkipValidation operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Summary: Data context for generating gRPC service configuration.

Fields:

  • Name (string): The name of the service.
  • Address (string): The address of the gRPC service (host:port).
  • ReflectionEnabled (bool): Indicates whether gRPC reflection should be enabled.

type Generator

type Generator struct {
	Reader *bufio.Reader
}

Generator handles the interactive generation of configuration files.

Summary: Interactive configuration generator.

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

Fields:

  • Reader (*bufio.Reader): The reader to use for user input.

func NewGenerator

func NewGenerator() *Generator

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

Parameters:

  • None

Returns:

  • *Generator: The resulting *Generator.

Errors:

  • None

Side Effects:

  • None

Summary: Initializes NewGenerator operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Parameters:

  • None

Returns:

  • []byte: The resulting []byte.
  • error: An error if the operation fails.

Errors:

  • Returns an error if the operation fails or is invalid.

Side Effects:

  • None

Summary: Executes Generate operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Summary: A client for fetching configuration from GitHub.

Fields:

  • Owner (string): The owner of the repository (user or organization).
  • Repo (string): The repository name.
  • Path (string): The path to the file or directory within the repository.
  • Ref (string): The branch, tag, or commit hash.
  • URLType (string): The type of URL (tree or blob).

func NewGitHub

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

NewGitHub creates a new GitHub client by parsing a GitHub URL.

Summary: Creates a new GitHub client from a URL.

It supports standard GitHub URLs for repositories, trees, and blobs.

Parameters:

  • ctx (context.Context): The context for the client creation (unused in this function but kept for signature consistency).
  • rawURL (string): The GitHub URL to parse.

Returns:

  • *GitHub: A pointer to a new GitHub client.
  • error: An error if the URL is invalid.

Errors:

  • Returns an error if the URL cannot be parsed or does not match the GitHub URL format.

Side Effects:

  • None.

func (*GitHub) List

func (g *GitHub) List(ctx context.Context, auth *configv1.Authentication) ([]Content, error)

List fetches the contents of the configured GitHub path.

Summary: Lists contents of the configured GitHub path.

It handles authentication if provided and returns a list of Content objects.

Parameters:

  • ctx (context.Context): The context for the request.
  • auth (*configv1.Authentication): Optional authentication configuration for accessing private repos.

Returns:

  • []Content: A slice of Content objects.
  • error: An error if the fetch fails.

Errors:

  • Returns an error if the HTTP request creation fails, authentication application fails, or the API returns a non-200 status code.

Side Effects:

  • Makes an HTTP GET request to the GitHub API.

func (*GitHub) ToRawContentURL

func (g *GitHub) ToRawContentURL() string

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

Parameters:

  • None

Returns:

  • string: The resulting string.

Errors:

  • None

Side Effects:

  • None

Summary: Executes ToRawContentURL operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Summary: Data context for generating GraphQL service configuration.

Fields:

  • Name (string): The name of the service.
  • Address (string): The URL of the GraphQL endpoint.
  • CallName (string): The name of the GraphQL query or mutation to expose.
  • SelectionSet (string): The GraphQL selection set for the operation.

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.

Summary: Data context for generating HTTP service configuration.

Fields:

  • Name (string): The name of the service.
  • Address (string): The base URL/address of the service.
  • OperationID (string): The unique identifier for the operation.
  • Description (string): A human-readable description of the service operation.
  • Method (string): The HTTP method to use (e.g., "GET", "POST").
  • EndpointPath (string): The path of the endpoint (e.g., "/api/v1/users").

type MockWatcher

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

MockWatcher is a mock implementation of the Watcher for testing.

Summary: Represents a MockWatcher.

func NewMockWatcher

func NewMockWatcher() *MockWatcher

NewMockWatcher creates a new mock watcher.

Returns:

  • *MockWatcher: The result.

Side Effects:

  • None.

Summary: Initializes NewMockWatcher operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*MockWatcher) Close

func (m *MockWatcher) Close()

Close mocks the Close method.

Parameters:

  • None.

Side Effects:

  • None.

Summary: Executes Close operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*MockWatcher) Watch

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

Watch mocks the Watch method.

Parameters:

  • paths ([]string): The parameter.
  • reloadFunc (func(): The parameter.

Returns:

  • ) (error): An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes Watch operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type MultiStore

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

MultiStore implements the Store interface for loading configurations from multiple stores.

Summary: Combines multiple stores into a single logical store.

func NewMultiStore

func NewMultiStore(stores ...Store) *MultiStore

NewMultiStore creates a new MultiStore with the given stores.

Summary: Initializes a new MultiStore.

Parameters:

  • stores: ...Store. The stores to aggregate.

Returns:

  • *MultiStore: A new instance of MultiStore.

func (*MultiStore) HasConfigSources

func (ms *MultiStore) HasConfigSources() bool

HasConfigSources returns true if any of the underlying stores have configuration sources. Side Effects: - None.

Parameters:

  • None

Returns:

  • bool: True if successful, false otherwise.

Errors:

  • None

Side Effects:

  • None

Summary: Checks HasConfigSources operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*MultiStore) Load

Load loads configurations from all stores and merges them into a single config.

Summary: Loads and merges configurations from all underlying stores.

Parameters:

  • ctx: context.Context. The context for the request.

Returns:

  • *configv1.McpAnyServerConfig: The merged configuration.
  • error: An error if loading fails.

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.

Summary: Data context for generating OpenAPI service configuration.

Fields:

  • Name (string): The name of the service.
  • SpecPath (string): The path or URL to the OpenAPI specification file.

type ServiceStore

type ServiceStore interface {
	Store
	// SaveService saves or updates a service configuration.
	//
	// Summary: Persists a service configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - service (*configv1.UpstreamServiceConfig): The service configuration to save.
	//
	// Returns:
	//   - (error): An error if the operation fails.
	SaveService(ctx context.Context, service *configv1.UpstreamServiceConfig) error

	// GetService retrieves a service configuration by name.
	//
	// Summary: Retrieves a service configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The name of the service to retrieve.
	//
	// Returns:
	//   - (*configv1.UpstreamServiceConfig): The service configuration.
	//   - (error): An error if the service is not found or the operation fails.
	GetService(ctx context.Context, name string) (*configv1.UpstreamServiceConfig, error)

	// ListServices retrieves all stored service configurations.
	//
	// Summary: Lists all services.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - ([]*configv1.UpstreamServiceConfig): A slice of service configurations.
	//   - (error): An error if the operation fails.
	ListServices(ctx context.Context) ([]*configv1.UpstreamServiceConfig, error)

	// DeleteService removes a service configuration by name.
	//
	// Summary: Deletes a service configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The name of the service to delete.
	//
	// Returns:
	//   - (error): An error if the operation fails.
	DeleteService(ctx context.Context, name string) error
}

ServiceStore extends Store to provide CRUD operations for UpstreamServices.

Summary: Interface for stores that support managing individual services.

type Settings

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

Settings defines the global configuration for the application.

Summary: Represents a Settings.

func GlobalSettings

func GlobalSettings() *Settings

GlobalSettings returns the singleton instance of the global settings.

Summary: Retrieves the global settings singleton.

Parameters:

  • None.

Returns:

  • *Settings: The singleton instance.

Side Effects:

  • Initializes the singleton if it doesn't exist.

func (*Settings) APIKey

func (s *Settings) APIKey() string

APIKey returns the API key for the server.

Summary: Retrieves the API key.

Parameters:

  • None.

Returns:

  • string: The API key.

Side Effects:

  • None.

func (*Settings) ConfigPaths

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

ConfigPaths returns the paths to the configuration files.

Summary: Retrieves configuration file paths.

Parameters:

  • None.

Returns:

  • []string: List of paths.

Side Effects:

  • None.

func (*Settings) DBPath

func (s *Settings) DBPath() string

DBPath returns the path to the SQLite database.

Summary: Retrieves the database path.

Parameters:

  • None.

Returns:

  • string: The database path.

Side Effects:

  • None.

func (*Settings) GRPCPort

func (s *Settings) GRPCPort() string

GRPCPort returns the gRPC port.

Summary: Retrieves the gRPC port.

Parameters:

  • None.

Returns:

  • string: The gRPC port.

Side Effects:

  • None.

func (*Settings) GetDbDriver

func (s *Settings) GetDbDriver() string

GetDbDriver returns the database driver.

Summary: Retrieves the database driver.

Parameters:

  • None.

Returns:

  • string: The driver name.

Side Effects:

  • None.

func (*Settings) GetDbDsn

func (s *Settings) GetDbDsn() string

GetDbDsn returns the database DSN.

Summary: Retrieves the database DSN.

Parameters:

  • None.

Returns:

  • string: The DSN.

Side Effects:

  • None.

func (*Settings) GetDlp

func (s *Settings) GetDlp() *configv1.DLPConfig

GetDlp returns the DLP configuration.

Summary: Retrieves the DLP configuration.

Parameters:

  • None.

Returns:

  • *configv1.DLPConfig: The DLP config.

Side Effects:

  • None.

func (*Settings) GetOidc

func (s *Settings) GetOidc() *configv1.OIDCConfig

GetOidc returns the OIDC configuration.

Summary: Retrieves the OIDC configuration.

Parameters:

  • None.

Returns:

  • *configv1.OIDCConfig: The OIDC config.

Side Effects:

  • None.

func (*Settings) GetProfileDefinitions

func (s *Settings) GetProfileDefinitions() []*configv1.ProfileDefinition

GetProfileDefinitions returns the profile definitions.

Summary: Retrieves the profile definitions.

Parameters:

  • None.

Returns:

  • []*configv1.ProfileDefinition: List of profiles.

Side Effects:

  • None.

func (*Settings) GetSso

func (s *Settings) GetSso() *configv1.SSOConfig

GetSso returns the SSO configuration.

Summary: Retrieves the SSO configuration.

Parameters:

  • None.

Returns:

  • *configv1.SSOConfig: The SSO config.

Side Effects:

  • None.

func (*Settings) GithubAPIURL

func (s *Settings) GithubAPIURL() string

GithubAPIURL returns the GitHub API URL.

Summary: Retrieves the GitHub API URL.

Parameters:

  • None.

Returns:

  • string: The URL.

Side Effects:

  • None.

func (*Settings) IsDebug

func (s *Settings) IsDebug() bool

IsDebug returns whether debug mode is enabled.

Summary: Checks if debug mode is enabled.

Parameters:

  • None.

Returns:

  • bool: True if enabled.

Side Effects:

  • None.

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.

Summary: Loads configuration from flags and files.

Parameters:

  • cmd: *cobra.Command. The cobra command containing flags.
  • fs: afero.Fs. The file system interface for reading config files.

Returns:

  • error: An error if loading fails.

Side Effects:

  • Modifies the global settings instance.
  • Initializes logging.
  • Reads environment variables.

func (*Settings) LogFile

func (s *Settings) LogFile() string

LogFile returns the path to the log file.

Summary: Retrieves the log file path.

Parameters:

  • None.

Returns:

  • string: The log file path.

Side Effects:

  • None.

func (*Settings) LogFormat

LogFormat returns the current log format as a protobuf enum.

Summary: Retrieves the log format.

Parameters:

  • None.

Returns:

  • configv1.GlobalSettings_LogFormat: The log format enum.

Side Effects:

  • None.

func (*Settings) LogLevel

LogLevel returns the current log level as a protobuf enum.

Summary: Retrieves the log level.

Parameters:

  • None.

Returns:

  • configv1.GlobalSettings_LogLevel: The log level enum.

Side Effects:

  • Logs a warning if the log level is invalid.

func (*Settings) MCPListenAddress

func (s *Settings) MCPListenAddress() string

MCPListenAddress returns the MCP listen address.

Summary: Retrieves the MCP listen address.

Parameters:

  • None.

Returns:

  • string: The listen address.

Side Effects:

  • None.

func (*Settings) MetricsListenAddress

func (s *Settings) MetricsListenAddress() string

MetricsListenAddress returns the metrics listen address.

Summary: Retrieves the metrics listen address.

Parameters:

  • None.

Returns:

  • string: The metrics address.

Side Effects:

  • None.

func (*Settings) Middlewares

func (s *Settings) Middlewares() []*configv1.Middleware

Middlewares returns the configured middlewares.

Summary: Retrieves the configured middlewares.

Parameters:

  • None.

Returns:

  • []*configv1.Middleware: List of middlewares.

Side Effects:

  • None.

func (*Settings) PersistentLog

func (s *Settings) PersistentLog() string

PersistentLog returns the path to the persistent log file used for hydration.

Summary: Retrieves the persistent log file path.

Parameters:

  • None.

Returns:

  • string: The persistent log path.

Side Effects:

  • None.

func (*Settings) Profiles

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

Profiles returns the active profiles.

Summary: Retrieves the active profiles.

Parameters:

  • None.

Returns:

  • []string: List of profile names.

Side Effects:

  • None.

func (*Settings) SetAPIKey

func (s *Settings) SetAPIKey(key string)

SetAPIKey sets the Global API key.

Summary: Sets the API key.

Parameters:

  • key: string. The API key.

Returns:

None.

Side Effects:

  • Updates the API key setting.

func (*Settings) SetDlp

func (s *Settings) SetDlp(dlp *configv1.DLPConfig)

SetDlp sets the DLP configuration.

Summary: Sets the DLP configuration.

Parameters:

  • dlp: *configv1.DLPConfig. The DLP config.

Returns:

None.

Side Effects:

  • Updates the DLP setting.

func (*Settings) SetMiddlewares

func (s *Settings) SetMiddlewares(middlewares []*configv1.Middleware)

SetMiddlewares sets the middlewares for the global settings.

Summary: Sets the middlewares.

Parameters:

  • middlewares: []*configv1.Middleware. The list of middlewares.

Returns:

None.

Side Effects:

  • Updates the middlewares setting.

func (*Settings) SetSso

func (s *Settings) SetSso(sso *configv1.SSOConfig)

SetSso sets the SSO configuration.

Summary: Sets the SSO configuration.

Parameters:

  • sso: *configv1.SSOConfig. The SSO config.

Returns:

  • None.

Side Effects:

  • Updates the SSO setting.

func (*Settings) SetValues

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

SetValues returns configuration values to override.

Summary: Retrieves configuration override values.

Parameters:

  • None.

Returns:

  • []string: List of key=value strings.

Side Effects:

  • None.

func (*Settings) ShutdownTimeout

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

ShutdownTimeout returns the graceful shutdown timeout.

Summary: Retrieves the shutdown timeout.

Parameters:

  • None.

Returns:

  • time.Duration: The timeout duration.

Side Effects:

  • None.

func (*Settings) Stdio

func (s *Settings) Stdio() bool

Stdio returns whether stdio mode is enabled.

Summary: Checks if stdio mode is enabled.

Parameters:

  • None.

Returns:

  • bool: True if enabled.

Side Effects:

  • None.

func (*Settings) ToProto

func (s *Settings) ToProto() *configv1.GlobalSettings

ToProto returns the underlying GlobalSettings protobuf message.

Summary: Converts the settings to a protobuf message.

Parameters:

  • None.

Returns:

  • *configv1.GlobalSettings: The protobuf representation.

Side Effects:

  • None.

type Store

type Store interface {
	// Load retrieves and returns the McpAnyServerConfig.
	//
	// Summary: Loads the complete server configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - (*configv1.McpAnyServerConfig): The loaded configuration.
	//   - (error): An error if loading fails.
	Load(ctx context.Context) (*configv1.McpAnyServerConfig, error)

	// HasConfigSources returns true if the store has configuration sources (e.g., file paths) configured.
	//
	// Summary: Checks if the store has any configured sources.
	//
	// Returns:
	//   - (bool): True if sources are configured, false otherwise.
	HasConfigSources() bool
}

Store defines the interface for loading MCP-X server configurations.

Summary: Abstraction for configuration sources.

type StructuredEngine

type StructuredEngine interface {
	Engine
	// UnmarshalFromMap populates the provided proto.Message from a raw map.
	//
	// Summary: Parses a map into a protobuf message.
	//
	// Parameters:
	//   - m (map[string]interface{}): The raw map data.
	//   - v (proto.Message): The destination protobuf message.
	//   - originalBytes ([]byte): Optional original bytes for error reporting (line numbers).
	//
	// Returns:
	//   - (error): An error if parsing fails.
	UnmarshalFromMap(m map[string]interface{}, v proto.Message, originalBytes []byte) error
}

StructuredEngine defines an interface for engines that can unmarshal directly from a map structure.

Summary: Abstraction for parsing configurations from map structures, avoiding double parsing.

type UpstreamServiceManager

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

UpstreamServiceManager manages the lifecycle and configuration of upstream services.

Summary: Handles loading, validating, and merging service configurations from various sources.

Side Effects:

  • Stores the final, merged UpstreamServiceConfig objects.
  • Makes HTTP requests to fetch remote configurations.

func NewUpstreamServiceManager

func NewUpstreamServiceManager(enabledProfiles []string) *UpstreamServiceManager

NewUpstreamServiceManager creates a new instance of UpstreamServiceManager.

Summary: Initializes a new UpstreamServiceManager with the specified profiles.

Parameters:

  • enabledProfiles ([]string): A list of profile names that are active. Services must match one of these profiles to be loaded.

Returns:

  • (*UpstreamServiceManager): A pointer to a fully initialized UpstreamServiceManager.

func (*UpstreamServiceManager) LoadAndMergeServices

LoadAndMergeServices loads all upstream services from the provided configuration.

Summary: Processes local and remote service configurations, merging them based on priority and name.

Parameters:

  • ctx (context.Context): The context for the operation.
  • config (*configv1.McpAnyServerConfig): The main server configuration containing service definitions and collection references.

Returns:

  • ([]*configv1.UpstreamServiceConfig): A slice of merged service configurations.
  • (error): An error if any critical failure occurs during loading or merging.

Side Effects:

  • May clear existing services if a replace strategy is configured.
  • Fetches remote collections via HTTP.

type ValidationError

type ValidationError struct {
	ServiceName string
	Err         error
}

ValidationError encapsulates a validation error for a specific service.

Summary: Represents a configuration validation error.

func Validate

func Validate(ctx context.Context, config *configv1.McpAnyServerConfig, binaryType BinaryType) []ValidationError

Validate inspects the given McpAnyServerConfig for correctness and consistency.

Summary: Validates the entire server configuration.

Parameters:

  • ctx (context.Context): The context for the validation (used for secret resolution).
  • config (*configv1.McpAnyServerConfig): The server configuration to be validated.
  • binaryType (BinaryType): The type of binary (server, worker) which might affect validation rules.

Returns:

  • ([]ValidationError): 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. Side Effects: - None.

Parameters:

  • None

Returns:

  • string: The resulting string.

Errors:

  • None

Side Effects:

  • None

Summary: Executes Error operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type Watcher

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

Watcher monitors configuration files for changes and triggers a reload.

Summary: A file system watcher for configuration reloading.

It watches the parent directory of specified files to handle atomic saves (rename/move) commonly used by text editors.

Fields:

  • watcher (*fsnotify.Watcher): The underlying fsnotify watcher.
  • done (chan bool): Channel to signal shutdown.
  • mu (sync.Mutex): Mutex to protect concurrent access.
  • timer (*time.Timer): Timer for debouncing reload events.

func NewWatcher

func NewWatcher() (*Watcher, error)

NewWatcher creates a new file watcher.

Parameters:

  • None

Returns:

  • *Watcher: The resulting *Watcher.
  • error: An error if the operation fails.

Errors:

  • Returns an error if the operation fails or is invalid.

Side Effects:

  • None

Summary: Initializes NewWatcher operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*Watcher) Close

func (w *Watcher) Close()

Close stops the file watcher and releases resources.

Parameters:

  • None.

Summary: Executes Close operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*Watcher) Watch

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

Watch starts monitoring the specified configuration paths.

Summary: Starts watching the specified paths for changes.

Parameters:

  • paths ([]string): A slice of file or directory paths to watch.
  • reloadFunc (func()): The function to call when a change is detected.

Returns:

  • error: An error if adding paths to the watcher fails.

Errors:

  • Returns an error if adding a path to the watcher fails.

Side Effects:

  • Starts a goroutine to process file events.
  • Registers directories with the OS watcher.

Jump to

Keyboard shortcuts

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