Skip to content

Commit 6f8bd81

Browse files
author
Test
committed
fix(mcpb): fix config loading logic to always read config file
Critical bug fix: The condition 'if config_path is not None or (not use_env)' prevented loading the config file when config_path=None and use_env=True. This broke the hybrid configuration pattern where: - Server URL comes from environment variable (static, doesn't change) - Tokens come from config file (dynamic, can be auto-updated on refresh) Fix: Always attempt to load config file (using DEFAULT_CONFIG_PATH if not specified), making it optional only when use_env=True and file doesn't exist. Environment variables still override file values when use_env=True. This enables Claude Desktop to use: env: CIDX_SERVER_URL=https://... file: bearer_token + refresh_token (auto-updated on token refresh)
1 parent d824881 commit 6f8bd81

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/code_indexer/mcpb/config.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,18 @@ def load_config(
103103
"""
104104
config_data = {}
105105

106-
# Load from file if path provided or using default
107-
if config_path is not None or (not use_env):
108-
path = Path(config_path) if config_path else DEFAULT_CONFIG_PATH
109-
path = path.expanduser().resolve()
110-
111-
if not path.exists():
106+
# Always attempt to load config file (use DEFAULT_CONFIG_PATH if not specified)
107+
# Environment variables will override file values if use_env=True
108+
path = Path(config_path) if config_path else DEFAULT_CONFIG_PATH
109+
path = path.expanduser().resolve()
110+
111+
# Only raise error if config file doesn't exist AND no env vars provided
112+
if not path.exists():
113+
if not use_env:
112114
raise FileNotFoundError(f"Config file not found: {path}")
113-
115+
# If using env vars, config file is optional - continue with empty config_data
116+
else:
117+
# Config file exists - load it
114118
# Check file permissions (Story #517)
115119
file_stat = os.stat(path)
116120
# Get octal permissions (last 3 digits)

0 commit comments

Comments
 (0)