MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / buildDiscoveryEnv

Function buildDiscoveryEnv

internal/providers/models.go:356–378  ·  view source on GitHub ↗

buildDiscoveryEnv constructs the env slice passed to list_models_cmd. Starts from os.Environ() (via getenv if injected via tests), strips proxy vars when KeepProxyConfig is false, then layers endpoint + api_key on top.

(ep Endpoint, getenv func(string) string)

Source from the content-addressed store, hash-verified

354// proxy vars when KeepProxyConfig is false, then layers endpoint +
355// api_key on top.
356func buildDiscoveryEnv(ep Endpoint, getenv func(string) string) []string {
357 if getenv == nil {
358 getenv = os.Getenv
359 }
360 apiKey := ResolveAPIKey(ep, getenv)
361
362 current := os.Environ()
363 out := make([]string, 0, len(current)+2)
364 for _, kv := range current {
365 name, _, _ := strings.Cut(kv, "=")
366 if !ep.KeepProxyConfig && isProxyVar(name) {
367 continue
368 }
369 // Avoid letting an inherited endpoint/api_key override.
370 if name == "endpoint" || name == "api_key" {
371 continue
372 }
373 out = append(out, kv)
374 }
375 out = append(out, "endpoint="+ep.Endpoint)
376 out = append(out, "api_key="+apiKey)
377 return out
378}
379
380func isProxyVar(name string) bool {
381 for _, p := range proxyVars {

Callers 1

runListModelsCmdFunction · 0.85

Calls 2

ResolveAPIKeyFunction · 0.85
isProxyVarFunction · 0.85

Tested by

no test coverage detected