Skip to content

Commit d08a202

Browse files
author
LittleCoinCoin
committed
fix(vscode): update configuration format from settings.json to mcp.json
- Change file paths from settings.json to mcp.json across all platforms - Update configuration key from 'mcp.servers' to direct 'servers' access - Simplify file structure to use direct servers object instead of nested structure - Update method documentation and comments to reflect new format - Preserve existing atomic write operations and error handling - Maintain non-MCP settings preservation functionality This change separates MCP configuration from VS Code settings, providing cleaner organization and reduced conflicts with VS Code's settings management.
1 parent a688f52 commit d08a202

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

hatch/mcp_host_config/strategies.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -298,35 +298,35 @@ def is_host_available(self) -> bool:
298298

299299
@register_host_strategy(MCPHostType.VSCODE)
300300
class VSCodeHostStrategy(MCPHostStrategy):
301-
"""Configuration strategy for VS Code MCP extension with user-wide settings support."""
301+
"""Configuration strategy for VS Code MCP extension with user-wide mcp support."""
302302

303303
def get_config_path(self) -> Optional[Path]:
304-
"""Get VS Code user settings configuration path (cross-platform)."""
304+
"""Get VS Code user mcp configuration path (cross-platform)."""
305305
try:
306306
system = platform.system()
307307
if system == "Windows":
308-
# Windows: %APPDATA%\Code\User\settings.json
308+
# Windows: %APPDATA%\Code\User\mcp.json
309309
appdata = Path.home() / "AppData" / "Roaming"
310-
return appdata / "Code" / "User" / "settings.json"
310+
return appdata / "Code" / "User" / "mcp.json"
311311
elif system == "Darwin": # macOS
312-
# macOS: $HOME/Library/Application Support/Code/User/settings.json
313-
return Path.home() / "Library" / "Application Support" / "Code" / "User" / "settings.json"
312+
# macOS: $HOME/Library/Application Support/Code/User/mcp.json
313+
return Path.home() / "Library" / "Application Support" / "Code" / "User" / "mcp.json"
314314
elif system == "Linux":
315-
# Linux: $HOME/.config/Code/User/settings.json
316-
return Path.home() / ".config" / "Code" / "User" / "settings.json"
315+
# Linux: $HOME/.config/Code/User/mcp.json
316+
return Path.home() / ".config" / "Code" / "User" / "mcp.json"
317317
else:
318318
logger.warning(f"Unsupported platform for VS Code: {system}")
319319
return None
320320
except Exception as e:
321-
logger.error(f"Failed to determine VS Code user settings path: {e}")
321+
logger.error(f"Failed to determine VS Code user mcp path: {e}")
322322
return None
323323

324324
def get_config_key(self) -> str:
325-
"""VS Code uses nested configuration structure."""
326-
return "mcp.servers" # VS Code specific nested key
325+
"""VS Code uses direct servers configuration structure."""
326+
return "servers" # VS Code specific direct key
327327

328328
def is_host_available(self) -> bool:
329-
"""Check if VS Code is installed by checking for user settings directory."""
329+
"""Check if VS Code is installed by checking for user directory."""
330330
try:
331331
config_path = self.get_config_path()
332332
if not config_path:
@@ -343,18 +343,18 @@ def validate_server_config(self, server_config: MCPServerConfig) -> bool:
343343
return server_config.command is not None or server_config.url is not None
344344

345345
def read_configuration(self) -> HostConfiguration:
346-
"""Read VS Code settings.json configuration."""
346+
"""Read VS Code mcp.json configuration."""
347347
config_path = self.get_config_path()
348348
if not config_path or not config_path.exists():
349349
return HostConfiguration()
350-
350+
351351
try:
352352
with open(config_path, 'r') as f:
353353
config_data = json.load(f)
354-
355-
# Extract MCP servers from nested structure
356-
mcp_servers = config_data.get("mcp", {}).get("servers", {})
357-
354+
355+
# Extract MCP servers from direct structure
356+
mcp_servers = config_data.get(self.get_config_key(), {})
357+
358358
# Convert to MCPServerConfig objects
359359
servers = {}
360360
for name, server_data in mcp_servers.items():
@@ -363,50 +363,48 @@ def read_configuration(self) -> HostConfiguration:
363363
except Exception as e:
364364
logger.warning(f"Invalid server config for {name}: {e}")
365365
continue
366-
366+
367367
return HostConfiguration(servers=servers)
368-
368+
369369
except Exception as e:
370370
logger.error(f"Failed to read VS Code configuration: {e}")
371371
return HostConfiguration()
372372

373373
def write_configuration(self, config: HostConfiguration, no_backup: bool = False) -> bool:
374-
"""Write VS Code settings.json configuration."""
374+
"""Write VS Code mcp.json configuration."""
375375
config_path = self.get_config_path()
376376
if not config_path:
377377
return False
378-
378+
379379
try:
380380
# Ensure parent directory exists
381381
config_path.parent.mkdir(parents=True, exist_ok=True)
382-
383-
# Read existing configuration
382+
383+
# Read existing configuration to preserve non-MCP settings
384384
existing_config = {}
385385
if config_path.exists():
386386
try:
387387
with open(config_path, 'r') as f:
388388
existing_config = json.load(f)
389389
except Exception:
390390
pass
391-
391+
392392
# Convert MCPServerConfig objects to dict
393393
servers_dict = {}
394394
for name, server_config in config.servers.items():
395395
servers_dict[name] = server_config.model_dump(exclude_none=True)
396-
397-
# Update nested configuration structure
398-
if "mcp" not in existing_config:
399-
existing_config["mcp"] = {}
400-
existing_config["mcp"]["servers"] = servers_dict
401-
396+
397+
# Update configuration with new servers (preserves non-MCP settings)
398+
existing_config[self.get_config_key()] = servers_dict
399+
402400
# Write atomically
403401
temp_path = config_path.with_suffix('.tmp')
404402
with open(temp_path, 'w') as f:
405403
json.dump(existing_config, f, indent=2)
406-
404+
407405
temp_path.replace(config_path)
408406
return True
409-
407+
410408
except Exception as e:
411409
logger.error(f"Failed to write VS Code configuration: {e}")
412410
return False

0 commit comments

Comments
 (0)