Skip to content

Commit ce6ecc6

Browse files
author
LittleCoinCoin
committed
fix(dev): overwrite server config in mcp host rather than merging
Writing to the server config would originally (65e32cd) merge the new server configurations with existing ones. Effectively making it and "append" only writing operation preventing to use this api for removing server configurations (overriding everything). By default, we expect the MCPHostConfig passed to the `write_configuration` to be perfect. - Only in Gemini strategy, because the change was originally operated only there.
1 parent 902fa8a commit ce6ecc6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

hatch/mcp_host_config/strategies.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,29 +444,27 @@ def write_configuration(self, config: HostConfiguration, no_backup: bool = False
444444
config_path = self.get_config_path()
445445
if not config_path:
446446
return False
447-
447+
448448
try:
449449
# Ensure parent directory exists
450450
config_path.parent.mkdir(parents=True, exist_ok=True)
451-
452-
# Read existing configuration to preserve other settings
451+
452+
# Read existing configuration to preserve non-MCP settings
453453
existing_config = {}
454454
if config_path.exists():
455455
try:
456456
with open(config_path, 'r') as f:
457457
existing_config = json.load(f)
458458
except Exception:
459459
pass
460-
461-
# Preserve existing servers and add/update new ones
462-
existing_servers = existing_config.get(self.get_config_key(), {})
463460

464-
# Convert MCPServerConfig objects to dict and merge with existing
461+
# Convert MCPServerConfig objects to dict (REPLACE, don't merge)
462+
servers_dict = {}
465463
for name, server_config in config.servers.items():
466-
existing_servers[name] = server_config.model_dump(exclude_none=True)
464+
servers_dict[name] = server_config.model_dump(exclude_none=True)
467465

468-
# Update configuration with merged servers
469-
existing_config[self.get_config_key()] = existing_servers
466+
# Update configuration with new servers (preserves non-MCP settings)
467+
existing_config[self.get_config_key()] = servers_dict
470468

471469
# Write atomically with enhanced error handling
472470
temp_path = config_path.with_suffix('.tmp')

0 commit comments

Comments
 (0)