From e9c571402a8715ee3c1cef511ab8eea1ff7592a5 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 30 Oct 2025 21:47:58 -0400 Subject: [PATCH] fix: set PYTHONPATH for MCP services to resolve import errors Root cause: Python adds script directory (not working directory) to sys.path. Services in /app/agent_tools/ couldn't import from /app/tools/ because sys.path[0] was /app/agent_tools. Solution: Set PYTHONPATH=/app when starting services so /app is always in the Python import path. Fixes: ModuleNotFoundError: No module named 'tools' in price.log --- agent_tools/start_mcp_services.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/agent_tools/start_mcp_services.py b/agent_tools/start_mcp_services.py index 2c57c82..ed20048 100755 --- a/agent_tools/start_mcp_services.py +++ b/agent_tools/start_mcp_services.py @@ -79,12 +79,18 @@ class MCPServiceManager: try: # Start service process log_file = self.log_dir / f"{service_id}.log" + + # Set PYTHONPATH to /app so services can import from tools module + env = os.environ.copy() + env['PYTHONPATH'] = str(Path.cwd()) + with open(log_file, 'w') as f: process = subprocess.Popen( [sys.executable, str(script_path)], stdout=f, stderr=subprocess.STDOUT, - cwd=Path.cwd() # Use current working directory (/app) + cwd=Path.cwd(), # Use current working directory (/app) + env=env # Pass environment with PYTHONPATH ) self.services[service_id] = {