config

package
v0.0.105 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package config provides configuration loading and parsing. This file defines the core configuration types that are stable and rarely change.

Package config provides configuration loading and parsing. This file defines the feature registration framework for modular config handling.

Package config provides configuration loading and parsing. This file defines payload-related configuration and defaults.

Package config provides configuration loading and parsing. This file defines stdin (JSON) configuration types.

Index

Constants

View Source
const (
	DefaultPort           = 3000
	DefaultStartupTimeout = 60  // seconds
	DefaultToolTimeout    = 120 // seconds
)

Core constants for configuration defaults

View Source
const DefaultPayloadDir = "/tmp/jq-payloads"

DefaultPayloadDir is the default directory for storing large payloads.

Variables

View Source
var RequiredEnvVars = []string{
	"MCP_GATEWAY_PORT",
	"MCP_GATEWAY_DOMAIN",
	"MCP_GATEWAY_API_KEY",
}

RequiredEnvVars lists the environment variables that must be set for the gateway to operate

Functions

func ExpandRawJSONVariables

func ExpandRawJSONVariables(data []byte) ([]byte, error)

ExpandRawJSONVariables expands all ${VAR} expressions in JSON data before schema validation. This ensures the schema validates the expanded values, not the variable syntax. It collects all undefined variables and reports them in a single error.

func GetGatewayAPIKeyFromEnv

func GetGatewayAPIKeyFromEnv() string

GetGatewayAPIKeyFromEnv returns the MCP_GATEWAY_API_KEY value

func GetGatewayDomainFromEnv

func GetGatewayDomainFromEnv() string

GetGatewayDomainFromEnv returns the MCP_GATEWAY_DOMAIN value

func GetGatewayPortFromEnv

func GetGatewayPortFromEnv() (int, error)

GetGatewayPortFromEnv returns the MCP_GATEWAY_PORT value, parsed as int

func RegisterDefaults

func RegisterDefaults(fn DefaultsSetter)

RegisterDefaults registers a function that sets defaults for a config feature. Called during init() in feature-specific config files.

func RegisterStdinConverter

func RegisterStdinConverter(fn StdinConverter)

RegisterStdinConverter registers a function that converts stdin config for a feature. Called during init() in feature-specific config files.

func SetDebug

func SetDebug(enabled bool)

SetDebug enables debug logging for config package

Types

type Config

type Config struct {
	// Servers maps server names to their configurations
	Servers map[string]*ServerConfig `toml:"servers" json:"servers"`

	// Gateway holds global gateway settings
	Gateway *GatewayConfig `toml:"gateway" json:"gateway,omitempty"`

	// EnableDIFC enables Decentralized Information Flow Control
	EnableDIFC bool `toml:"enable_difc" json:"enable_difc,omitempty"`

	// SequentialLaunch launches servers sequentially instead of in parallel
	SequentialLaunch bool `toml:"sequential_launch" json:"sequential_launch,omitempty"`
}

Config represents the internal gateway configuration. Feature-specific fields are added in their respective config_*.go files.

func LoadFromFile

func LoadFromFile(path string) (*Config, error)

LoadFromFile loads configuration from a TOML file.

func LoadFromStdin

func LoadFromStdin() (*Config, error)

LoadFromStdin loads configuration from stdin JSON.

type DefaultsSetter

type DefaultsSetter func(cfg *Config)

DefaultsSetter sets default values for a Config. Features register these to apply their defaults during loading.

type EnvValidationResult

type EnvValidationResult struct {
	IsContainerized    bool
	ContainerID        string
	DockerAccessible   bool
	MissingEnvVars     []string
	PortMapped         bool
	StdinInteractive   bool
	LogDirMounted      bool
	ValidationErrors   []string
	ValidationWarnings []string
}

EnvValidationResult holds the result of environment validation. It captures various aspects of the execution environment including containerization status, Docker accessibility, and validation errors/warnings.

This type implements the error interface through its Error() method, which returns a formatted error message containing all validation failures. Use IsValid() to check if all critical validations passed before attempting to start the gateway.

Fields:

  • IsContainerized: Whether the gateway is running inside a Docker container
  • ContainerID: The Docker container ID if containerized
  • DockerAccessible: Whether the Docker daemon is accessible
  • MissingEnvVars: List of required environment variables that are not set
  • PortMapped: Whether the gateway port is mapped to the host (containerized mode)
  • StdinInteractive: Whether stdin is interactive (containerized mode)
  • LogDirMounted: Whether the log directory is mounted (containerized mode)
  • ValidationErrors: Critical errors that prevent the gateway from starting
  • ValidationWarnings: Non-critical issues that should be addressed

func ValidateContainerizedEnvironment

func ValidateContainerizedEnvironment(containerID string) *EnvValidationResult

ValidateContainerizedEnvironment performs additional validation for containerized mode This is called by run_containerized.sh through the binary or by the Go code directly

func ValidateExecutionEnvironment

func ValidateExecutionEnvironment() *EnvValidationResult

ValidateExecutionEnvironment performs comprehensive validation of the execution environment It checks Docker accessibility, required environment variables, and containerization status

func (*EnvValidationResult) Error

func (r *EnvValidationResult) Error() string

Error returns a combined error message for all validation errors

func (*EnvValidationResult) IsValid

func (r *EnvValidationResult) IsValid() bool

IsValid returns true if all critical validations passed

type FeatureConfig

type FeatureConfig interface {
	// FeatureName returns the name of the feature for logging
	FeatureName() string
}

FeatureConfig represents a modular configuration feature. Each feature defines its own config processing in a separate file.

type GatewayConfig

type GatewayConfig struct {
	// Port is the HTTP port to listen on
	Port int `toml:"port" json:"port,omitempty"`

	// APIKey is the authentication key for the gateway
	APIKey string `toml:"api_key" json:"api_key,omitempty"`

	// Domain is the gateway domain for external access
	Domain string `toml:"domain" json:"domain,omitempty"`

	// StartupTimeout is the maximum time (seconds) to wait for server startup
	StartupTimeout int `toml:"startup_timeout" json:"startup_timeout,omitempty"`

	// ToolTimeout is the maximum time (seconds) to wait for tool execution
	ToolTimeout int `toml:"tool_timeout" json:"tool_timeout,omitempty"`

	// PayloadDir is the directory for storing large payloads
	PayloadDir string `toml:"payload_dir" json:"payload_dir,omitempty"`
}

GatewayConfig holds global gateway settings. Feature-specific fields are added in their respective config_*.go files.

type ServerConfig

type ServerConfig struct {
	// Type is the server type: "stdio" or "http"
	Type string `toml:"type" json:"type,omitempty"`

	// Command is the executable command (for stdio servers)
	Command string `toml:"command" json:"command,omitempty"`

	// Args are the command arguments (for stdio servers)
	Args []string `toml:"args" json:"args,omitempty"`

	// Env holds environment variables for the server
	Env map[string]string `toml:"env" json:"env,omitempty"`

	// WorkingDirectory is the working directory for the server
	WorkingDirectory string `toml:"working_directory" json:"working_directory,omitempty"`

	// URL is the HTTP endpoint (for http servers)
	URL string `toml:"url" json:"url,omitempty"`

	// Headers are HTTP headers to send (for http servers)
	Headers map[string]string `toml:"headers" json:"headers,omitempty"`

	// Tools is an optional list of tools to filter/expose
	Tools []string `toml:"tools" json:"tools,omitempty"`
}

ServerConfig represents an individual MCP server configuration.

type StdinConfig

type StdinConfig struct {
	// MCPServers maps server names to their configurations
	MCPServers map[string]*StdinServerConfig `json:"mcpServers"`

	// Gateway holds global gateway settings
	Gateway *StdinGatewayConfig `json:"gateway,omitempty"`

	// CustomSchemas defines custom server types
	CustomSchemas map[string]interface{} `json:"customSchemas,omitempty"`
}

StdinConfig represents the JSON configuration format read from stdin.

type StdinConverter

type StdinConverter func(cfg *Config, stdinCfg *StdinConfig)

StdinConverter converts stdin-specific config to internal Config. Features register these to handle their stdin config fields.

type StdinGatewayConfig

type StdinGatewayConfig struct {
	Port           *int   `json:"port,omitempty"`
	APIKey         string `json:"apiKey,omitempty"`
	Domain         string `json:"domain,omitempty"`
	StartupTimeout *int   `json:"startupTimeout,omitempty"`
	ToolTimeout    *int   `json:"toolTimeout,omitempty"`
	PayloadDir     string `json:"payloadDir,omitempty"`
}

StdinGatewayConfig represents gateway configuration in stdin JSON format. Uses pointers for optional fields to distinguish between unset and zero values.

type StdinServerConfig

type StdinServerConfig struct {
	// Type is the server type: "stdio", "local", or "http"
	Type string `json:"type"`

	// Container is the Docker image for stdio servers
	Container string `json:"container,omitempty"`

	// Entrypoint overrides the container entrypoint
	Entrypoint string `json:"entrypoint,omitempty"`

	// EntrypointArgs are additional arguments to the entrypoint
	EntrypointArgs []string `json:"entrypointArgs,omitempty"`

	// Args are additional Docker runtime arguments (passed before container image)
	Args []string `json:"args,omitempty"`

	// Mounts are volume mounts for the container
	Mounts []string `json:"mounts,omitempty"`

	// Env holds environment variables
	Env map[string]string `json:"env,omitempty"`

	// URL is the HTTP endpoint (for http servers)
	URL string `json:"url,omitempty"`

	// Headers are HTTP headers to send (for http servers)
	Headers map[string]string `json:"headers,omitempty"`

	// Tools is an optional list of tools to filter/expose
	Tools []string `json:"tools,omitempty"`
}

StdinServerConfig represents a single server configuration in stdin JSON format.

type ValidationError

type ValidationError = rules.ValidationError

ValidationError is an alias for rules.ValidationError for backward compatibility

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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