Skip to content

Commit a688f52

Browse files
author
LittleCoinCoin
committed
fix(vscode): set mcp configure to user-wide by default
- Replace Path.cwd() workspace assumption with cross-platform user settings paths - Support Windows (%APPDATA%\Code\User\settings.json), macOS (~/Library/Application Support/Code/User/settings.json), Linux (~/.config/Code/User/settings.json) - Fix is_host_available() to check VS Code installation rather than workspace directory - Maintain mcp.servers config key and flexible server validation - No backward compatibility needed as previous implementation was non-functional Resolves critical 'Incorrect Working Directory Assumption' identified in analysis. Enables proper VS Code MCP integration with user-wide configuration scope.
1 parent 2824de7 commit a688f52

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

hatch/mcp_host_config/strategies.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,46 @@ 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."""
302-
301+
"""Configuration strategy for VS Code MCP extension with user-wide settings support."""
302+
303303
def get_config_path(self) -> Optional[Path]:
304-
"""Get VS Code configuration path."""
305-
return Path.cwd() / ".vscode" / "settings.json"
306-
304+
"""Get VS Code user settings configuration path (cross-platform)."""
305+
try:
306+
system = platform.system()
307+
if system == "Windows":
308+
# Windows: %APPDATA%\Code\User\settings.json
309+
appdata = Path.home() / "AppData" / "Roaming"
310+
return appdata / "Code" / "User" / "settings.json"
311+
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"
314+
elif system == "Linux":
315+
# Linux: $HOME/.config/Code/User/settings.json
316+
return Path.home() / ".config" / "Code" / "User" / "settings.json"
317+
else:
318+
logger.warning(f"Unsupported platform for VS Code: {system}")
319+
return None
320+
except Exception as e:
321+
logger.error(f"Failed to determine VS Code user settings path: {e}")
322+
return None
323+
307324
def get_config_key(self) -> str:
308325
"""VS Code uses nested configuration structure."""
309326
return "mcp.servers" # VS Code specific nested key
310-
327+
311328
def is_host_available(self) -> bool:
312-
"""Check if VS Code workspace exists."""
313-
vscode_dir = Path.cwd() / ".vscode"
314-
return vscode_dir.exists()
315-
329+
"""Check if VS Code is installed by checking for user settings directory."""
330+
try:
331+
config_path = self.get_config_path()
332+
if not config_path:
333+
return False
334+
335+
# Check if VS Code user directory exists (indicates VS Code installation)
336+
user_dir = config_path.parent
337+
return user_dir.exists()
338+
except Exception:
339+
return False
340+
316341
def validate_server_config(self, server_config: MCPServerConfig) -> bool:
317342
"""VS Code validation - flexible path handling."""
318343
return server_config.command is not None or server_config.url is not None

0 commit comments

Comments
 (0)