From 5ec7977b478ce6fbebec65ba637153adc0f7ea49 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 30 Oct 2025 21:22:42 -0400 Subject: [PATCH] fix: resolve module import error for MCP services Run MCP service manager from /app instead of /app/agent_tools to ensure services can import from tools module. Changes: - entrypoint.sh: Run start_mcp_services.py from /app directory - start_mcp_services.py: Use absolute paths for service scripts - start_mcp_services.py: Set working directory to /app for services Fixes ModuleNotFoundError: No module named 'tools' in price.log --- agent_tools/start_mcp_services.py | 25 +++++++++++++------------ entrypoint.sh | 5 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/agent_tools/start_mcp_services.py b/agent_tools/start_mcp_services.py index 111f936..2c57c82 100755 --- a/agent_tools/start_mcp_services.py +++ b/agent_tools/start_mcp_services.py @@ -27,32 +27,33 @@ class MCPServiceManager: 'price': int(os.getenv('GETPRICE_HTTP_PORT', '8003')) } - # Service configurations + # Service configurations (paths relative to /app) + self.agent_tools_dir = Path(__file__).parent.resolve() self.service_configs = { 'math': { - 'script': 'tool_math.py', + 'script': self.agent_tools_dir / 'tool_math.py', 'name': 'Math', 'port': self.ports['math'] }, 'search': { - 'script': 'tool_jina_search.py', + 'script': self.agent_tools_dir / 'tool_jina_search.py', 'name': 'Search', 'port': self.ports['search'] }, 'trade': { - 'script': 'tool_trade.py', + 'script': self.agent_tools_dir / 'tool_trade.py', 'name': 'TradeTools', 'port': self.ports['trade'] }, 'price': { - 'script': 'tool_get_price_local.py', + 'script': self.agent_tools_dir / 'tool_get_price_local.py', 'name': 'LocalPrices', 'port': self.ports['price'] } } - + # Create logs directory - self.log_dir = Path('../logs') + self.log_dir = Path('logs') self.log_dir.mkdir(exist_ok=True) # Set signal handlers @@ -70,20 +71,20 @@ class MCPServiceManager: script_path = config['script'] service_name = config['name'] port = config['port'] - - if not Path(script_path).exists(): + + if not script_path.exists(): print(f"❌ Script file not found: {script_path}") return False - + try: # Start service process log_file = self.log_dir / f"{service_id}.log" with open(log_file, 'w') as f: process = subprocess.Popen( - [sys.executable, script_path], + [sys.executable, str(script_path)], stdout=f, stderr=subprocess.STDOUT, - cwd=os.getcwd() + cwd=Path.cwd() # Use current working directory (/app) ) self.services[service_id] = { diff --git a/entrypoint.sh b/entrypoint.sh index 604492a..f283cd7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,10 +47,9 @@ cd /app # Step 2: Start MCP services in background echo "🔧 Starting MCP services..." -cd /app/agent_tools -python start_mcp_services.py & -MCP_PID=$! cd /app +python agent_tools/start_mcp_services.py & +MCP_PID=$! # Step 3: Wait for services to initialize echo "⏳ Waiting for MCP services to start..."