Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions transports/bifrost-http/lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package lib

import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
Expand Down Expand Up @@ -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
}
Comment thread
Pratham-Mishra04 marked this conversation as resolved.

// 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.
Expand Down
4 changes: 4 additions & 0 deletions transports/bifrost-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down