Skip to content

Commit 6119fe2

Browse files
author
LittleCoinCoin
committed
fix: implement environment-specific Python executable path resolution
Root cause: MCP server configurations were using hardcoded 'python' command instead of environment-specific Python executable paths, causing servers to run with wrong Python interpreter. Changes: - Update get_package_mcp_server_config() to use env_manager.get_current_python_executable() - Fallback to 'python' if no environment-specific executable available - Update test to mock get_current_python_executable() method properly - Test now expects environment-specific path instead of generic 'python' Resolves Issue 3: Incorrect Python Executable Path Now generates proper paths like 'C:\Users\eliot\miniforge3\envs\hatch_modeling\python.exe' instead of generic 'python' command. Tested: All MCP CLI tests pass (100% success rate)
1 parent f7af78a commit 6119fe2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

hatch/cli_hatch.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@ def get_package_mcp_server_config(env_manager: HatchEnvironmentManager, env_name
9393
if not hatch_mcp_entry_point:
9494
raise ValueError(f"Package '{package_name}' does not have a HatchMCP entry point")
9595

96+
# Get environment-specific Python executable
97+
python_executable = env_manager.get_current_python_executable()
98+
if not python_executable:
99+
# Fallback to system Python if no environment-specific Python available
100+
python_executable = "python"
101+
96102
# Create server configuration
97103
server_path = str(package_path / hatch_mcp_entry_point)
98104
server_config = MCPServerConfig(
99105
name=package_name,
100-
command="python",
106+
command=python_executable,
101107
args=[server_path],
102108
env={}
103109
)

tests/test_mcp_cli_package_management.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def test_get_package_mcp_server_config_success(self):
259259
'source': {'path': '/path/to/package'}
260260
}
261261
]
262+
# Mock the Python executable method to return a proper string
263+
mock_env_manager.get_current_python_executable.return_value = "/path/to/python"
262264

263265
# Mock file system and metadata
264266
with patch('pathlib.Path.exists', return_value=True):
@@ -272,7 +274,7 @@ def test_get_package_mcp_server_config_success(self):
272274

273275
self.assertIsInstance(config, MCPServerConfig)
274276
self.assertEqual(config.name, "test-package")
275-
self.assertEqual(config.command, "python")
277+
self.assertEqual(config.command, "/path/to/python") # Now uses environment-specific Python
276278
self.assertTrue(config.args[0].endswith("hatch_mcp_server.py"))
277279

278280
@regression_test

0 commit comments

Comments
 (0)