config

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig[T Type](filename string) (*T, string, error)

LoadConfig loads configuration from a YAML file with environment variable support

func ValidateMCPConfig added in v0.2.11

func ValidateMCPConfig(cfg *MCPConfig) error

ValidateMCPConfig validates a single MCP configuration

func ValidateMCPConfigs added in v0.2.11

func ValidateMCPConfigs(configs []*MCPConfig) error

ValidateMCPConfigs validates a list of MCP configurations

Types

type APIConfig added in v0.2.6

type APIConfig struct {
	Port      int    `yaml:"port"`
	TargetURL string `yaml:"target_url"`
}

APIConfig represents the configuration for API-based notifier

type APIServerConfig

type APIServerConfig struct {
	Database   DatabaseConfig   `yaml:"database"`
	OpenAI     OpenAIConfig     `yaml:"openai"`
	Storage    StorageConfig    `yaml:"storage"`
	Notifier   NotifierConfig   `yaml:"notifier"`
	Logger     LoggerConfig     `yaml:"logger"`
	JWT        JWTConfig        `yaml:"jwt"`
	SuperAdmin SuperAdminConfig `yaml:"super_admin"`
	I18n       I18nConfig       `yaml:"i18n"`
}

type APIStorageConfig added in v0.4.0

type APIStorageConfig struct {
	Url            string        `yaml:"url"`            // http url for api
	ConfigJSONPath string        `yaml:"configJSONPath"` // configJSONPath for config in http response
	Timeout        time.Duration `yaml:"timeout"`        // timeout for http request
}

type ArgConfig

type ArgConfig struct {
	Name        string      `json:"name" yaml:"name"`
	Position    string      `json:"position" yaml:"position"` // header, query, path, body
	Required    bool        `json:"required" yaml:"required"`
	Type        string      `json:"type" yaml:"type"`
	Description string      `json:"description" yaml:"description"`
	Default     string      `json:"default" yaml:"default"`
	Items       ItemsConfig `json:"items,omitempty" yaml:"items,omitempty"`
}

type Auth added in v0.6.0

type Auth struct {
	Mode cnst.AuthMode `json:"mode" yaml:"mode"`
}

Auth represents authentication configuration

type AuthConfig added in v0.6.0

type AuthConfig struct {
	OAuth2 *OAuth2Config `yaml:"oauth2"`
	CORS   *CORSConfig   `yaml:"cors,omitempty"`
}

AuthConfig defines the authentication configuration

type CORSConfig

type CORSConfig struct {
	AllowOrigins     []string `json:"allowOrigins,omitempty" yaml:"allowOrigins,omitempty"`
	AllowMethods     []string `json:"allowMethods,omitempty" yaml:"allowMethods,omitempty"`
	AllowHeaders     []string `json:"allowHeaders,omitempty" yaml:"allowHeaders,omitempty"`
	ExposeHeaders    []string `json:"exposeHeaders,omitempty" yaml:"exposeHeaders,omitempty"`
	AllowCredentials bool     `json:"allowCredentials" yaml:"allowCredentials"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Type     string `yaml:"type"`     // mysql, postgres, sqlite, etc.
	Host     string `yaml:"host"`     // localhost
	Port     int    `yaml:"port"`     // 3306 (for mysql), 5432 (for postgres)
	User     string `yaml:"user"`     // root (for mysql), postgres (for postgres)
	Password string `yaml:"password"` // password
	DBName   string `yaml:"dbname"`   // database name
	SSLMode  string `yaml:"sslmode"`  // disable (for postgres)
}

func (*DatabaseConfig) GetDSN

func (c *DatabaseConfig) GetDSN() string

GetDSN returns the database connection string

type DiskStorageConfig added in v0.2.5

type DiskStorageConfig struct {
	Path string `yaml:"path"` // path for disk storage
}

type I18nConfig added in v0.4.0

type I18nConfig struct {
	Path string `yaml:"path"` // Path to i18n translation files
}

I18nConfig represents the internationalization configuration

type ItemsConfig added in v0.3.0

type ItemsConfig struct {
	Type       string         `json:"type" yaml:"type"`
	Enum       []string       `json:"enum,omitempty" yaml:"enum,omitempty"`
	Properties map[string]any `json:"properties,omitempty" yaml:"properties,omitempty"`
}

type JWTConfig added in v0.3.1

type JWTConfig struct {
	SecretKey string        `yaml:"secret_key"`
	Duration  time.Duration `yaml:"duration"`
}

type Location added in v0.2.11

type Location struct {
	File string
}

Location represents a configuration location

type LoggerConfig added in v0.2.11

type LoggerConfig struct {
	Level      string `yaml:"level"`       // debug, info, warn, error
	Format     string `yaml:"format"`      // json, console
	Output     string `yaml:"output"`      // stdout, file
	FilePath   string `yaml:"file_path"`   // path to log file when output is file
	MaxSize    int    `yaml:"max_size"`    // max size of log file in MB
	MaxBackups int    `yaml:"max_backups"` // max number of backup files
	MaxAge     int    `yaml:"max_age"`     // max age of backup files in days
	Compress   bool   `yaml:"compress"`    // whether to compress backup files
	Color      bool   `yaml:"color"`       // whether to use color in console output
	Stacktrace bool   `yaml:"stacktrace"`  // whether to include stacktrace in error logs
	TimeZone   string `yaml:"time_zone"`   // time zone for log timestamps, e.g., "UTC", default is local
	TimeFormat string `yaml:"time_format"` // time format for log timestamps, default is "2006-01-02 15:04:05"
}

LoggerConfig represents the logger configuration

type MCPConfig

type MCPConfig struct {
	Name       string            `json:"name" yaml:"name"`
	Tenant     string            `json:"tenant" yaml:"tenant"`
	CreatedAt  time.Time         `json:"createdAt" yaml:"createdAt"`
	UpdatedAt  time.Time         `json:"updatedAt" yaml:"updatedAt"`
	DeletedAt  time.Time         `json:"deletedAt,omitempty" yaml:"deletedAt,omitempty"` // non-zero indicates that all information has been deleted
	Routers    []RouterConfig    `json:"routers,omitempty" yaml:"routers,omitempty"`
	Servers    []ServerConfig    `json:"servers,omitempty" yaml:"servers,omitempty"`
	Tools      []ToolConfig      `json:"tools,omitempty" yaml:"tools,omitempty"`
	McpServers []MCPServerConfig `json:"mcpServers,omitempty" yaml:"mcpServers,omitempty"` // proxy mcp servers
}

func MergeConfigs added in v0.4.6

func MergeConfigs(existingConfigs []*MCPConfig, newConfig *MCPConfig) []*MCPConfig

MergeConfigs merges a new configuration with existing configurations It will update the existing config if it exists, or append the new config if it doesn't exist If the new config has DeletedAt set, it will remove the config from the list

type MCPConfigVersion added in v0.4.7

type MCPConfigVersion struct {
	Version    int             `json:"version" yaml:"version"`
	CreatedBy  string          `json:"created_by" yaml:"created_by"`
	CreatedAt  time.Time       `json:"created_at" yaml:"created_at"`
	ActionType cnst.ActionType `json:"action_type" yaml:"action_type"` // Create, Update, Delete, Revert
	Name       string          `json:"name" yaml:"name"`
	Tenant     string          `json:"tenant" yaml:"tenant"`
	Routers    string          `json:"routers" yaml:"routers"`
	Servers    string          `json:"servers" yaml:"servers"`
	Tools      string          `json:"tools" yaml:"tools"`
	McpServers string          `json:"mcp_servers" yaml:"mcp_servers"`
	IsActive   bool            `json:"is_active" yaml:"is_active"` // indicates if this version is currently active
	Hash       string          `json:"hash" yaml:"hash"`           // hash of the configuration content
}

MCPConfigVersion represents a version of an MCP configuration

type MCPGatewayConfig

type MCPGatewayConfig struct {
	Port           int              `yaml:"port"`
	ReloadPort     int              `yaml:"reload_port"`
	ReloadInterval time.Duration    `yaml:"reload_interval"`
	ReloadSwitch   bool             `yaml:"reload_switch"`
	PID            string           `yaml:"pid"`
	SuperAdmin     SuperAdminConfig `yaml:"super_admin"`
	Logger         LoggerConfig     `yaml:"logger"`
	Storage        StorageConfig    `yaml:"storage"`
	Notifier       NotifierConfig   `yaml:"notifier"`
	Session        SessionConfig    `yaml:"session"`
	Auth           AuthConfig       `yaml:"auth"`
}

MCPGatewayConfig represents the MCP gateway configuration

type MCPServer

type MCPServer struct {
	Name      string    `json:"name" yaml:"name"`
	Content   MCPConfig `json:"content" yaml:"content"`
	CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" yaml:"updatedAt"`
}

MCPServer represents the MCP server data structure

type MCPServerConfig added in v0.4.0

type MCPServerConfig struct {
	Type         string                `json:"type" yaml:"type"`                           // sse, stdio and streamable-http
	Name         string                `json:"name" yaml:"name"`                           // server name
	Command      string                `json:"command,omitempty" yaml:"command,omitempty"` // for stdio
	Args         []string              `json:"args,omitempty" yaml:"args,omitempty"`       // for stdio
	Env          map[string]string     `json:"env,omitempty" yaml:"env,omitempty"`         // for stdio
	URL          string                `json:"url,omitempty" yaml:"url,omitempty"`         // for sse and streamable-http
	Policy       cnst.MCPStartupPolicy `json:"policy" yaml:"policy"`                       // onStart or onDemand
	Preinstalled bool                  `json:"preinstalled" yaml:"preinstalled"`           // whether to install this MCP server when mcp-gateway starts
}

type NotifierConfig added in v0.2.6

type NotifierConfig struct {
	Role   string       `yaml:"role"` // receiver, sender, or both
	Type   string       `yaml:"type"`
	Signal SignalConfig `yaml:"signal"`
	API    APIConfig    `yaml:"api"`
	Redis  RedisConfig  `yaml:"redis"`
}

NotifierConfig represents the configuration for notifier

type NotifierRole added in v0.2.6

type NotifierRole string

NotifierRole represents the role of a notifier

const (
	// RoleReceiver represents a notifier that can only receive updates
	RoleReceiver NotifierRole = "receiver"
	// RoleSender represents a notifier that can only send updates
	RoleSender NotifierRole = "sender"
	// RoleBoth represents a notifier that can both send and receive updates
	RoleBoth NotifierRole = "both"
)

type OAuth2Config added in v0.6.0

type OAuth2Config struct {
	Issuer  string              `yaml:"issuer"`
	Storage OAuth2StorageConfig `yaml:"storage"`
}

type OAuth2RedisConfig added in v0.6.0

type OAuth2RedisConfig struct {
	Addr     string `yaml:"addr"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
}

type OAuth2StorageConfig added in v0.6.0

type OAuth2StorageConfig struct {
	Type  string            `yaml:"type"`
	Redis OAuth2RedisConfig `yaml:"redis"`
}

type OpenAIConfig

type OpenAIConfig struct {
	APIKey  string `yaml:"api_key"`
	Model   string `yaml:"model"`
	BaseURL string `yaml:"base_url"`
}

type ProxyConfig added in v0.5.0

type ProxyConfig struct {
	Host string `json:"host" yaml:"host"`
	Port int    `json:"port" yaml:"port"`
	Type string `json:"type" yaml:"type"` // http, https, socks5
}

type RedisConfig added in v0.2.6

type RedisConfig struct {
	Addr     string `yaml:"addr"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
	Topic    string `yaml:"topic"`
}

RedisConfig represents the configuration for Redis-based notifier

type RouterConfig

type RouterConfig struct {
	Server    string      `json:"server" yaml:"server"`
	Prefix    string      `json:"prefix" yaml:"prefix"`
	SSEPrefix string      `json:"ssePrefix" yaml:"ssePrefix"`
	CORS      *CORSConfig `json:"cors,omitempty" yaml:"cors,omitempty"`
	Auth      *Auth       `json:"auth,omitempty" yaml:"auth,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	Name         string            `json:"name" yaml:"name"`
	Description  string            `json:"description" yaml:"description"`
	AllowedTools []string          `json:"allowedTools,omitempty" yaml:"allowedTools,omitempty"`
	Config       map[string]string `json:"config,omitempty" yaml:"config,omitempty"`
}

type SessionConfig added in v0.2.8

type SessionConfig struct {
	Type  string             `yaml:"type"`  // "memory" or "redis"
	Redis SessionRedisConfig `yaml:"redis"` // Redis configuration
}

SessionConfig represents the session storage configuration

type SessionRedisConfig added in v0.2.8

type SessionRedisConfig struct {
	Addr     string        `yaml:"addr"`
	Username string        `yaml:"username"`
	Password string        `yaml:"password"`
	DB       int           `yaml:"db"`
	Topic    string        `yaml:"topic"`
	Prefix   string        `yaml:"prefix"`
	TTL      time.Duration `yaml:"ttl"` // TTL for session data in Redis
}

SessionRedisConfig represents the Redis configuration for session storage

type SignalConfig added in v0.2.6

type SignalConfig struct {
	Signal string `yaml:"signal"`
	PID    string `yaml:"pid"`
}

SignalConfig represents the configuration for signal-based notifier

type StorageConfig added in v0.2.5

type StorageConfig struct {
	Type                 string            `yaml:"type"`                   // disk or db
	RevisionHistoryLimit int               `yaml:"revision_history_limit"` // number of versions to keep
	Database             DatabaseConfig    `yaml:"database"`               // database configuration for db type
	Disk                 DiskStorageConfig `yaml:"disk"`                   // disk configuration for disk type
	API                  APIStorageConfig  `yaml:"api"`                    // disk configuration for api type
}

type SuperAdminConfig added in v0.3.2

type SuperAdminConfig struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

SuperAdminConfig represents the super admin configuration

type ToolConfig

type ToolConfig struct {
	Name         string            `json:"name" yaml:"name"`
	Description  string            `json:"description,omitempty" yaml:"description,omitempty"`
	Method       string            `json:"method" yaml:"method"`
	Endpoint     string            `json:"endpoint" yaml:"endpoint"`
	Proxy        *ProxyConfig      `json:"proxy,omitempty" yaml:"proxy,omitempty"`
	Headers      map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
	Args         []ArgConfig       `json:"args,omitempty" yaml:"args,omitempty"`
	RequestBody  string            `json:"requestBody"  yaml:"requestBody"`
	ResponseBody string            `json:"responseBody" yaml:"responseBody"`
	InputSchema  map[string]any    `json:"inputSchema,omitempty" yaml:"inputSchema,omitempty"`
}

func (*ToolConfig) ToToolSchema

func (t *ToolConfig) ToToolSchema() mcp.ToolSchema

ToToolSchema converts a ToolConfig to a ToolSchema

type Type

type Type interface {
	MCPGatewayConfig | APIServerConfig
}

type ValidationError added in v0.2.11

type ValidationError struct {
	Message   string
	Locations []Location
}

ValidationError represents a configuration validation error

func (*ValidationError) Error added in v0.2.11

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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