# Jesse MCP Server - Phase 1 Implementation Plan
## Status: ✅ Phase 1 Foundation Complete
### What's Working
- ✅ MCP server scaffold with stdio communication
- ✅ Tool registration (backtest, strategy_list, strategy_read, strategy_validate)
- ✅ Resource registration (strategies://list, indicators://list)
- ✅ Error handling and JSON communication
- ✅ Test suite validation
### What's Implemented (Phase 1)
#### Core Server (`server.py`)
- **MCP Protocol Handler**: Simple JSON request/response over stdio
- **Tool Registry**: 4 Phase 1 tools registered with schemas
- **Resource Registry**: 2 basic resources registered
- **Error Handling**: Graceful error responses with logging
#### Tools (Phase 1)
1. **`backtest`** - Placeholder with implementation roadmap
2. **`strategy_list`** - Placeholder with next steps
3. **`strategy_read`** - Placeholder with next steps
4. **`strategy_validate`** - Placeholder with next steps
#### Resources (Phase 1)
1. **`strategies://list`** - Basic strategy listing
2. **`indicators://list`** - Basic indicator listing
### Next Steps: Phase 2 - Real Implementation
#### 1. Jesse Integration
```python
# Import Jesse research module
from jesse import research
from jesse.strategies import Strategy
import jesse.helpers as jh
```
#### 2. Backtest Tool Implementation
```python
async def handle_backtest(args: Dict[str, Any]) -> CallToolResult:
"""Real backtest implementation"""
try:
# Import strategy
strategy_class = jh.get_strategy_class(args['strategy'])
# Get candles
candles = research.get_candles(
exchange=args.get('exchange', 'Binance'),
symbol=args['symbol'],
timeframe=args['timeframe'],
start_date_timestamp=jh.arrow_to_timestamp(args['start_date']),
finish_date_timestamp=jh.arrow_to_timestamp(args['end_date'])
)
# Format config
config = {
'starting_balance': args.get('starting_balance', 10000),
'fee': args.get('fee', 0.001),
'type': args.get('exchange_type', 'futures'),
'futures_leverage': args.get('leverage', 1),
'futures_leverage_mode': 'cross',
'exchange': args.get('exchange', 'Binance'),
'warm_up_candles': 240
}
# Format routes
routes = [{
'exchange': args.get('exchange', 'Binance'),
'strategy': args['strategy'],
'symbol': args['symbol'],
'timeframe': args['timeframe']
}]
# Run backtest
result = research.backtest(
config=config,
routes=routes,
data_routes=[],
candles=candles,
generate_equity_curve=args.get('include_equity_curve', False),
generate_trades=args.get('include_trades', False),
generate_logs=args.get('include_logs', False),
hyperparameters=args.get('hyperparameters')
)
return format_success(result)
except Exception as e:
return format_error(f"Backtest failed: {str(e)}")
```
#### 3. Strategy Management
```python
# List strategies from filesystem
def list_strategies():
strategies_dir = '/srv/containers/jesse/strategies'
strategies = []
for item in os.listdir(strategies_dir):
if os.path.isdir(os.path.join(strategies_dir, item)):
strategy_path = os.path.join(strategies_dir, item, '__init__.py')
if os.path.exists(strategy_path):
# Parse strategy metadata
strategies.append(parse_strategy(strategy_path, item))
return strategies
# Read strategy code
def read_strategy(name):
strategy_path = f'/srv/containers/jesse/strategies/{name}/__init__.py'
with open(strategy_path, 'r') as f:
return {
'name': name,
'code': f.read(),
'path': strategy_path
}
```
### Testing Results
```
🚀 Testing jesse-mcp server...
1. Testing tools/list...
✓ Tools listed: 4
2. Testing backtest tool...
✓ Backtest tool responded
Message: "Backtest tool - Phase 1 placeholder"
Next steps: [
"Import Jesse research module",
"Implement backtest() wrapper",
"Add candle data fetching",
"Add metrics formatting"
]
3. Testing resources/list...
✓ Resources listed: 2
🎉 All tests passed!
```
### Architecture Decision
**Simple MCP Protocol**: Instead of using complex MCP library (which has type issues), we implemented a simple JSON-over-stdio protocol:
```
Request: {"method": "tools/call", "params": {"name": "backtest", "arguments": {...}}}
Response: {"content": [{"type": "text", "text": "..."}], "isError": false}
```
This approach:
- ✅ Works with existing Jesse installation
- ✅ No complex type dependencies
- ✅ Easy to debug and extend
- ✅ Compatible with all LLM clients
### Ready for Phase 2
The foundation is solid and ready for real Jesse integration. Next phase will:
1. **Import Jesse modules** and implement real backtest functionality
2. **Add candle data management** (import, availability checking)
3. **Implement strategy CRUD** operations
4. **Add metrics formatting** and analysis tools
5. **Add batch operations** for multiple backtests
### Project Structure
```
/home/bk/jesse-mcp/
├── README.md # Project overview
├── requirements.txt # Dependencies
├── server.py # Main MCP server (Phase 1 complete)
├── test_server.py # Test suite
└── jesse_mcp_server.md # Complete PRD
```
The server is ready for deployment and Phase 2 development!