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
This commit is contained in:
2025-10-30 21:47:58 -04:00
parent 79d14444ed
commit e9c571402a

View File

@@ -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] = {