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
This commit is contained in:
2025-10-30 21:22:42 -04:00
parent 8142f38ab9
commit 5ec7977b47
2 changed files with 15 additions and 15 deletions

View File

@@ -27,32 +27,33 @@ class MCPServiceManager:
'price': int(os.getenv('GETPRICE_HTTP_PORT', '8003')) '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 = { self.service_configs = {
'math': { 'math': {
'script': 'tool_math.py', 'script': self.agent_tools_dir / 'tool_math.py',
'name': 'Math', 'name': 'Math',
'port': self.ports['math'] 'port': self.ports['math']
}, },
'search': { 'search': {
'script': 'tool_jina_search.py', 'script': self.agent_tools_dir / 'tool_jina_search.py',
'name': 'Search', 'name': 'Search',
'port': self.ports['search'] 'port': self.ports['search']
}, },
'trade': { 'trade': {
'script': 'tool_trade.py', 'script': self.agent_tools_dir / 'tool_trade.py',
'name': 'TradeTools', 'name': 'TradeTools',
'port': self.ports['trade'] 'port': self.ports['trade']
}, },
'price': { 'price': {
'script': 'tool_get_price_local.py', 'script': self.agent_tools_dir / 'tool_get_price_local.py',
'name': 'LocalPrices', 'name': 'LocalPrices',
'port': self.ports['price'] 'port': self.ports['price']
} }
} }
# Create logs directory # Create logs directory
self.log_dir = Path('../logs') self.log_dir = Path('logs')
self.log_dir.mkdir(exist_ok=True) self.log_dir.mkdir(exist_ok=True)
# Set signal handlers # Set signal handlers
@@ -71,7 +72,7 @@ class MCPServiceManager:
service_name = config['name'] service_name = config['name']
port = config['port'] port = config['port']
if not Path(script_path).exists(): if not script_path.exists():
print(f"❌ Script file not found: {script_path}") print(f"❌ Script file not found: {script_path}")
return False return False
@@ -80,10 +81,10 @@ class MCPServiceManager:
log_file = self.log_dir / f"{service_id}.log" log_file = self.log_dir / f"{service_id}.log"
with open(log_file, 'w') as f: with open(log_file, 'w') as f:
process = subprocess.Popen( process = subprocess.Popen(
[sys.executable, script_path], [sys.executable, str(script_path)],
stdout=f, stdout=f,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
cwd=os.getcwd() cwd=Path.cwd() # Use current working directory (/app)
) )
self.services[service_id] = { self.services[service_id] = {

View File

@@ -47,10 +47,9 @@ cd /app
# Step 2: Start MCP services in background # Step 2: Start MCP services in background
echo "🔧 Starting MCP services..." echo "🔧 Starting MCP services..."
cd /app/agent_tools
python start_mcp_services.py &
MCP_PID=$!
cd /app cd /app
python agent_tools/start_mcp_services.py &
MCP_PID=$!
# Step 3: Wait for services to initialize # Step 3: Wait for services to initialize
echo "⏳ Waiting for MCP services to start..." echo "⏳ Waiting for MCP services to start..."