Implementation:HKUDS AI Trader MCPServiceManager Start All Services
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Microservices, LLM_Tooling |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for starting and managing all MCP tool server subprocesses provided by the AI-Trader service orchestrator.
Description
The MCPServiceManager class manages 5 MCP tool servers as subprocesses. The start_all_services() method checks for port conflicts, starts each service via subprocess.Popen, verifies health, and maintains the services with a keep-alive monitoring loop. Services include: math tools (port 8000), news search (8001), stock trade execution (8002), local price lookup (8003), and crypto trade execution (8005).
Usage
Instantiate MCPServiceManager and call start_all_services() before launching any trading agent. The services must remain running throughout the entire backtesting session. Typically invoked by the main.sh shell script or directly from the command line.
Code Reference
Source Location
- Repository: AI-Trader
- File: agent_tools/start_mcp_services.py
- Lines: L160-201
Signature
class MCPServiceManager:
def __init__(self):
"""Initialize service manager with port configs from environment."""
def start_all_services(self):
"""
Start all configured MCP tool servers.
Checks port conflicts, starts each service subprocess,
verifies health, and prints service info.
Returns:
None
"""
Import
from agent_tools.start_mcp_services import MCPServiceManager
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| MATH_HTTP_PORT | str (env) | No | Math tool server port (default 8000) |
| SEARCH_HTTP_PORT | str (env) | No | News search server port (default 8001) |
| TRADE_HTTP_PORT | str (env) | No | Trade execution server port (default 8002) |
| GETPRICE_HTTP_PORT | str (env) | No | Price lookup server port (default 8003) |
| CRYPTO_HTTP_PORT | str (env) | No | Crypto trade server port (default 8005) |
Outputs
| Name | Type | Description |
|---|---|---|
| 5 running subprocesses | Process | MCP HTTP servers on configured ports |
| logs/ | Directory | Service log files in ../logs/ directory |
Usage Examples
Start All Services
from agent_tools.start_mcp_services import MCPServiceManager
manager = MCPServiceManager()
manager.start_all_services()
# Starts 5 MCP servers: math(8000), search(8001), trade(8002), price(8003), crypto(8005)
# Keep alive (blocking)
manager.keep_alive()
From Command Line
# Typically run via the main script:
python agent_tools/start_mcp_services.py &
# Or from the shell orchestrator:
# scripts/main.sh calls this as Step 2
Related Pages
Requires Environment
- Environment:HKUDS_AI_Trader_Python_LangChain_Runtime
- Environment:HKUDS_AI_Trader_API_Credentials
- Environment:HKUDS_AI_Trader_MCP_Services