diff --git a/transports/bifrost-http/lib/config.go b/transports/bifrost-http/lib/config.go index 40463f2678..7d6c0c5324 100644 --- a/transports/bifrost-http/lib/config.go +++ b/transports/bifrost-http/lib/config.go @@ -4,6 +4,7 @@ package lib import ( "encoding/json" + "fmt" "log" "os" "strings" @@ -31,6 +32,41 @@ type BifrostHTTPConfig struct { MCPConfig *schemas.MCPConfig `json:"mcp"` // MCP configuration (optional) } +// ReadMCPKeys reads environment variables from the environment and updates the MCP configurations. +// It replaces values starting with "env." in the connection_string field with actual values from the environment. +// Returns an error if any required environment variable is missing. +func (config *BifrostHTTPConfig) ReadMCPKeys() error { + if config.MCPConfig == nil { + return nil // No MCP config to process + } + + // Helper function to check and replace env values + replaceEnvValue := func(value string) (string, error) { + if strings.HasPrefix(value, "env.") { + envKey := strings.TrimPrefix(value, "env.") + if envValue := os.Getenv(envKey); envValue != "" { + return envValue, nil + } + return "", fmt.Errorf("environment variable %s not found in the environment", envKey) + } + return value, nil + } + + // Process each client config + for i, clientConfig := range config.MCPConfig.ClientConfigs { + // Process ConnectionString if present + if clientConfig.ConnectionString != nil { + newValue, err := replaceEnvValue(*clientConfig.ConnectionString) + if err != nil { + return fmt.Errorf("MCP client %s: %w", clientConfig.Name, err) + } + config.MCPConfig.ClientConfigs[i].ConnectionString = &newValue + } + } + + return nil +} + // readConfig reads and parses the configuration file. // It handles case conversion for provider names and sets up provider-specific metadata. // Returns a BifrostHTTPConfig containing both provider and MCP configurations. diff --git a/transports/bifrost-http/main.go b/transports/bifrost-http/main.go index 8941203767..a9ec996116 100644 --- a/transports/bifrost-http/main.go +++ b/transports/bifrost-http/main.go @@ -155,6 +155,10 @@ func main() { log.Printf("warning: failed to read environment variables: %v", err) } + if err := config.ReadMCPKeys(); err != nil { + log.Printf("warning: failed to read MCP environment variables: %v", err) + } + loadedPlugins := []schemas.Plugin{} for _, plugin := range pluginsToLoad {