MCPcopy Create free account
hub / github.com/github/gh-aw / getShellEnvironmentPolicyVars

Method getShellEnvironmentPolicyVars

pkg/workflow/codex_engine.go:572–634  ·  view source on GitHub ↗
(tools map[string]any, mcpTools []string)

Source from the content-addressed store, hash-verified

570}
571
572func (e *CodexEngine) getShellEnvironmentPolicyVars(tools map[string]any, mcpTools []string) []string {
573 // Collect all environment variables needed by MCP servers
574 envVars := make(map[string]struct{})
575
576 // Always include core environment variables
577 envVars["PATH"] = struct{}{}
578 envVars["HOME"] = struct{}{}
579
580 // Add CODEX_API_KEY for authentication
581 envVars["CODEX_API_KEY"] = struct{}{}
582 envVars["OPENAI_API_KEY"] = struct{}{} // Fallback for CODEX_API_KEY
583
584 // Check each MCP tool for required environment variables
585 for _, toolName := range mcpTools {
586 switch toolName {
587 case "github":
588 // GitHub MCP server needs GITHUB_PERSONAL_ACCESS_TOKEN
589 envVars["GITHUB_PERSONAL_ACCESS_TOKEN"] = struct {
590 }{}
591 case "agentic-workflows":
592 // Agentic workflows MCP server needs GITHUB_TOKEN
593 envVars["GITHUB_TOKEN"] = struct {
594 }{}
595 case "safe-outputs":
596 // Safe outputs MCP server needs several environment variables
597 envVars["GH_AW_SAFE_OUTPUTS"] = struct {
598 }{}
599 envVars["GH_AW_ASSETS_BRANCH"] = struct {
600 }{}
601 envVars["GH_AW_ASSETS_MAX_SIZE_KB"] = struct {
602 }{}
603 envVars["GH_AW_ASSETS_ALLOWED_EXTS"] = struct {
604 }{}
605 envVars["GITHUB_REPOSITORY"] = struct {
606 }{}
607 envVars["GITHUB_SERVER_URL"] = struct {
608 }{}
609 default:
610 // For custom MCP tools, check if they have env configuration
611 if toolValue, ok := tools[toolName]; ok {
612 if toolConfig, ok := toolValue.(map[string]any); ok {
613 // Extract environment variable names from env configuration
614 if env, hasEnv := toolConfig["env"].(map[string]any); hasEnv {
615 for envKey := range env {
616 envVars[envKey] = struct {
617 }{}
618 }
619 }
620 }
621 }
622 }
623 }
624
625 sortedEnvVars := sliceutil.SortedKeys(envVars)
626
627 // Codex expects regex patterns for shell_environment_policy.include_only, not literal names.
628 // Anchor each variable name to avoid accidental substring matches (for example "PATH" matching "PATH_SUFFIX").
629 var includeOnlyPatterns []string

Calls 1

SortedKeysFunction · 0.92

Tested by

no test coverage detected