config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

internal/config/config.go

internal/config/file.go

Index

Constants

View Source
const (
	DefaultMaxRows             = 200
	DefaultQueryTimeoutSecs    = 30
	DefaultMaxOpenConns        = 10
	DefaultMaxIdleConns        = 5
	DefaultConnMaxLifetimeMins = 30
	DefaultConnMaxIdleTimeMins = 5
	DefaultPingTimeoutSecs     = 5
	DefaultHTTPPort            = 9306
	DefaultHTTPRequestTimeoutS = 60
	DefaultRateLimitRPS        = 100 // requests per second
	DefaultRateLimitBurst      = 200 // burst size
)

Default values for configuration.

Variables

View Source
var ConfigFilePath string

ConfigFilePath holds the path to the config file (set by command line flag).

Functions

func ApplySSLToDSN added in v1.5.0

func ApplySSLToDSN(dsn, ssl string) string

ApplySSLToDSN appends TLS configuration to a DSN based on the SSL setting. SSL values:

  • "true" or "1": Enable TLS with certificate verification (tls=true)
  • "skip-verify": Enable TLS without certificate verification (tls=skip-verify)
  • "preferred": Maps to skip-verify (Go MySQL driver doesn't support tls=preferred)
  • "false", "0", or "": No change to DSN (use DSN as-is)

Note: The go-sql-driver/mysql only supports tls=true, tls=false, tls=skip-verify, or a custom TLS config name. The "preferred" option from MySQL client is not supported, so we map it to "skip-verify" as the closest equivalent behavior.

If the DSN already contains a tls= parameter, it is not modified.

func FindConfigFile added in v1.4.0

func FindConfigFile() string

FindConfigFile searches for a config file in standard locations. Returns the path to the first config file found, or empty string if none found.

func GetEnvBool added in v1.2.0

func GetEnvBool(key string) bool

GetEnvBool is exported for use by other packages.

func GetEnvInt added in v1.2.0

func GetEnvInt(key string, def int) int

GetEnvInt is exported for use by other packages.

func PrintConfig added in v1.4.0

func PrintConfig(cfg *Config) string

PrintConfig outputs the current configuration as YAML.

func ValidateConfigFile added in v1.4.0

func ValidateConfigFile(path string) error

ValidateConfigFile validates a config file without loading it into the server.

Types

type Config

type Config struct {
	// Connection settings
	Connections []ConnectionConfig

	// Query limits
	MaxRows      int
	QueryTimeout time.Duration

	// Connection pool settings
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
	PingTimeout     time.Duration

	// Feature flags
	ExtendedMode bool
	VectorMode   bool
	HTTPMode     bool
	JSONLogging  bool

	// Token estimation (optional, disabled by default)
	TokenTracking bool
	TokenModel    string

	// HTTP settings
	HTTPPort           int
	HTTPRequestTimeout time.Duration

	// Rate limiting (HTTP mode only)
	RateLimitEnabled bool
	RateLimitRPS     float64 // requests per second
	RateLimitBurst   int     // burst size

	// Audit logging
	AuditLogPath string
}

Config holds all configuration for the MySQL MCP server.

func Load

func Load() (*Config, error)

Load reads configuration from config file (if present) and environment variables. Priority: Environment variables > Config file > Defaults

type ConnectionConfig added in v1.2.0

type ConnectionConfig struct {
	Name        string `json:"name"`
	DSN         string `json:"dsn"`
	Description string `json:"description,omitempty"`
	ReadOnly    bool   `json:"read_only,omitempty"`
	SSL         string `json:"ssl,omitempty"` // "true", "false", "skip-verify", or empty (use DSN as-is)
}

ConnectionConfig represents a single MySQL connection configuration.

type FileConfig added in v1.4.0

type FileConfig struct {
	// Database connections
	Connections map[string]FileConnectionConfig `yaml:"connections" json:"connections"`

	// Query settings
	Query FileQueryConfig `yaml:"query" json:"query"`

	// Connection pool settings
	Pool FilePoolConfig `yaml:"pool" json:"pool"`

	// Feature flags
	Features FileFeatureConfig `yaml:"features" json:"features"`

	// Logging settings
	Logging FileLoggingConfig `yaml:"logging" json:"logging"`

	// HTTP/REST API settings
	HTTP FileHTTPConfig `yaml:"http" json:"http"`
}

FileConfig represents the structure of a configuration file. This mirrors the Config struct but with file-friendly field names.

func LoadConfigFile added in v1.4.0

func LoadConfigFile(path string) (*FileConfig, error)

LoadConfigFile loads configuration from a file (YAML or JSON).

func (*FileConfig) ToConfig added in v1.4.0

func (fc *FileConfig) ToConfig() *Config

ToConfig converts a FileConfig to the runtime Config struct. Values from FileConfig are used as base, can be overridden by env vars.

type FileConnectionConfig added in v1.4.0

type FileConnectionConfig struct {
	DSN         string `yaml:"dsn" json:"dsn"`
	Description string `yaml:"description" json:"description"`
	ReadOnly    bool   `yaml:"read_only" json:"read_only"`
	SSL         string `yaml:"ssl" json:"ssl"` // "true", "false", "skip-verify", or empty
}

FileConnectionConfig represents a connection in the config file.

type FileFeatureConfig added in v1.4.0

type FileFeatureConfig struct {
	ExtendedTools bool `yaml:"extended_tools" json:"extended_tools"`
	VectorTools   bool `yaml:"vector_tools" json:"vector_tools"`
}

FileFeatureConfig represents feature flags in the config file.

type FileHTTPConfig added in v1.4.0

type FileHTTPConfig struct {
	Enabled               bool                `yaml:"enabled" json:"enabled"`
	Port                  int                 `yaml:"port" json:"port"`
	RequestTimeoutSeconds int                 `yaml:"request_timeout_seconds" json:"request_timeout_seconds"`
	RateLimit             FileRateLimitConfig `yaml:"rate_limit" json:"rate_limit"`
}

FileHTTPConfig represents HTTP settings in the config file.

type FileLoggingConfig added in v1.4.0

type FileLoggingConfig struct {
	JSONFormat    bool   `yaml:"json_format" json:"json_format"`
	AuditLogPath  string `yaml:"audit_log_path" json:"audit_log_path"`
	TokenTracking bool   `yaml:"token_tracking" json:"token_tracking"`
	TokenModel    string `yaml:"token_model" json:"token_model"`
}

FileLoggingConfig represents logging settings in the config file.

type FilePoolConfig added in v1.4.0

type FilePoolConfig struct {
	MaxOpenConns           int `yaml:"max_open_conns" json:"max_open_conns"`
	MaxIdleConns           int `yaml:"max_idle_conns" json:"max_idle_conns"`
	ConnMaxLifetimeMinutes int `yaml:"conn_max_lifetime_minutes" json:"conn_max_lifetime_minutes"`
	ConnMaxIdleTimeMinutes int `yaml:"conn_max_idle_time_minutes" json:"conn_max_idle_time_minutes"`
	PingTimeoutSeconds     int `yaml:"ping_timeout_seconds" json:"ping_timeout_seconds"`
}

FilePoolConfig represents connection pool settings in the config file.

type FileQueryConfig added in v1.4.0

type FileQueryConfig struct {
	MaxRows        int `yaml:"max_rows" json:"max_rows"`
	TimeoutSeconds int `yaml:"timeout_seconds" json:"timeout_seconds"`
}

FileQueryConfig represents query settings in the config file.

type FileRateLimitConfig added in v1.4.0

type FileRateLimitConfig struct {
	Enabled bool `yaml:"enabled" json:"enabled"`
	RPS     int  `yaml:"rps" json:"rps"`
	Burst   int  `yaml:"burst" json:"burst"`
}

FileRateLimitConfig represents rate limiting settings in the config file.

Jump to

Keyboard shortcuts

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