Skip to content

Commit 292bb5f

Browse files
committed
feat: add environment variable fallback with ENT_ prefix support
- Add getEnvWithFallback() to check unprefixed vars first, then ENT_ prefixed - Applies to all env vars: CONTEXT7_API_KEY, BRAVE_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY - Update docs to reflect unprefixed as preferred style with ENT_ as fallback - Bump version to 1.1.0 - Update golangci-lint version to 2.11.3
1 parent 90140c0 commit 292bb5f

5 files changed

Lines changed: 40 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to MCP CLI-Ent will be documented in this file.
44

5+
<!-- RELEASE:START 1.1.0 -->
6+
## [1.1.0] - 2026-03-19
7+
8+
### Added
9+
10+
- **Environment Variable Fallback**: For each `${VAR_NAME}` in config, the CLI now checks the unprefixed variable first (e.g., `CONTEXT7_API_KEY`), then falls back to the `ENT_` prefixed version (e.g., `ENT_CONTEXT7_API_KEY`) if the first is empty. This provides backward compatibility while supporting the preferred unprefixed naming convention.
11+
12+
<!-- RELEASE:END 1.1.0 -->
13+
---
14+
515
<!-- RELEASE:START 1.0.0 -->
616
## [1.0.0] - 2026-01-20
717

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SIGN_IDENTITY?=-
2121

2222
# Lint
2323
GOLANGCI_LINT_BIN ?= golangci-lint
24-
GOLANGCI_LINT_VERSION ?= 2.10.1
24+
GOLANGCI_LINT_VERSION ?= 2.11.3
2525
LINT_TIMEOUT ?= 5m
2626

2727
help: ## Show this help message

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,23 @@ Use `${VAR_NAME}` or `$VAR_NAME` in values:
162162

163163
```json
164164
{
165-
"args": ["--api-key", "${ENT_CONTEXT7_API_KEY}"],
165+
"args": ["--api-key", "${CONTEXT7_API_KEY}"],
166166
"env": { "API_KEY": "$MY_API_KEY" },
167167
"headers": { "Authorization": "Bearer ${TOKEN}" }
168168
}
169169
```
170170

171+
**Fallback Behavior**: For each variable, the CLI checks the unprefixed name first (e.g., `CONTEXT7_API_KEY`), then falls back to the `ENT_` prefixed version (e.g., `ENT_CONTEXT7_API_KEY`) if the first is empty. This prevents conflicts with existing environment variables.
172+
171173
```bash
172-
# Linux/macOS
174+
# Linux/macOS - either format works
175+
export CONTEXT7_API_KEY="your_key"
176+
# or
173177
export ENT_CONTEXT7_API_KEY="your_key"
174-
export ENT_BRAVE_API_KEY="your_key"
175178

176179
# Windows PowerShell
180+
$env:CONTEXT7_API_KEY = "your_key"
181+
# or
177182
$env:ENT_CONTEXT7_API_KEY = "your_key"
178183
```
179184

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.1.0

internal/config/types.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,31 @@ type ServerStatus struct {
4444
Error string `json:"error,omitempty"`
4545
}
4646

47+
// getEnvWithFallback retrieves an environment variable with an ENT_ prefix fallback.
48+
// First checks the unprefixed variable (e.g., CONTEXT7_API_KEY), then falls back
49+
// to the ENT_ prefixed version (e.g., ENT_CONTEXT7_API_KEY) if the first is empty.
50+
func getEnvWithFallback(varName string) string {
51+
// Try the unprefixed version first
52+
if value := os.Getenv(varName); value != "" {
53+
return value
54+
}
55+
// Fall back to ENT_ prefixed version
56+
entVarName := "ENT_" + varName
57+
if value := os.Getenv(entVarName); value != "" {
58+
return value
59+
}
60+
return ""
61+
}
62+
4763
// ResolveEnvironmentVariables substitutes environment variables in string values
48-
// Supports ${VAR_NAME} and $VAR_NAME formats
64+
// Supports ${VAR_NAME} and $VAR_NAME formats.
65+
// For each variable, it checks the unprefixed name first, then falls back to ENT_ prefixed.
4966
func ResolveEnvironmentVariables(input string) string {
5067
// Match ${VAR_NAME} pattern
5168
re := regexp.MustCompile(`\$\{([^}]+)\}`)
5269
result := re.ReplaceAllStringFunc(input, func(match string) string {
5370
varName := strings.Trim(match, "${}")
54-
if value := os.Getenv(varName); value != "" {
71+
if value := getEnvWithFallback(varName); value != "" {
5572
return value
5673
}
5774
return match // Keep original if environment variable not found
@@ -61,7 +78,7 @@ func ResolveEnvironmentVariables(input string) string {
6178
re2 := regexp.MustCompile(`\$([A-Za-z_][A-Za-z0-9_]*)`)
6279
result = re2.ReplaceAllStringFunc(result, func(match string) string {
6380
varName := strings.Trim(match, "$")
64-
if value := os.Getenv(varName); value != "" {
81+
if value := getEnvWithFallback(varName); value != "" {
6582
return value
6683
}
6784
return match // Keep original if environment variable not found

0 commit comments

Comments
 (0)