64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// Package config loads runtime configuration from environment variables.
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
const (
|
|
AppVersion = "1.0.1"
|
|
DefaultEmptyResponse = "call this tool `get_user_request` again to fetch latest user input..."
|
|
)
|
|
|
|
// Config holds all runtime configuration values for local-mcp.
|
|
type Config struct {
|
|
Host string
|
|
HTTPPort string
|
|
DBPath string
|
|
LogLevel string
|
|
DefaultWaitSeconds int
|
|
AgentStaleAfterSeconds int
|
|
MCPStateless bool
|
|
APIToken string
|
|
}
|
|
|
|
// Load reads configuration from environment variables with sensible defaults.
|
|
func Load() Config {
|
|
return Config{
|
|
Host: getEnv("HOST", "0.0.0.0"),
|
|
HTTPPort: getEnv("HTTP_PORT", "8000"),
|
|
DBPath: getEnv("DB_PATH", "data/local_mcp.sqlite3"),
|
|
LogLevel: getEnv("LOG_LEVEL", "INFO"),
|
|
DefaultWaitSeconds: getEnvInt("DEFAULT_WAIT_SECONDS", 10),
|
|
AgentStaleAfterSeconds: getEnvInt("AGENT_STALE_AFTER_SECONDS", 30),
|
|
MCPStateless: getEnvBool("MCP_STATELESS", true),
|
|
APIToken: getEnv("API_TOKEN", ""),
|
|
}
|
|
}
|
|
|
|
func getEnv(key, defaultVal string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
func getEnvInt(key string, defaultVal int) int {
|
|
if v := os.Getenv(key); v != "" {
|
|
if i, err := strconv.Atoi(v); err == nil {
|
|
return i
|
|
}
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
func getEnvBool(key string, defaultVal bool) bool {
|
|
if v := os.Getenv(key); v != "" {
|
|
if b, err := strconv.ParseBool(v); err == nil {
|
|
return b
|
|
}
|
|
}
|
|
return defaultVal
|
|
}
|