使用说明
MCP Chart Generator
MCP (Model Context Protocol) server that exposes the Trading Lab Chart Generator functionality, allowing Claude to generate professional trading charts on demand.
Overview
This MCP server provides programmatic access to the trading-lab chart generation system, enabling:
- On-demand chart generation during Claude conversations
- 28+ technical studies (RSI, MACD, Bollinger Bands, etc.)
- ML predictions from Chronos, TOTO, Prophet, Burg models
- Signal overlays with buy/sell markers
- Multiple themes (Dark Casual, Dark Professional, Light, etc.)
- Flexible timeframes (Daily, Weekly, Monthly, Yearly)
Architecture
Claude Code
↓ (MCP Protocol)
MCP Chart Generator Server
↓ (Python Import)
trading-lab/src/services/chart_generation/
↓
PNG Chart Image
Available Tools
1. render_chart
Generate a trading chart PNG image.
Required Parameters:
symbol_code- Stock symbol (e.g., "AAPL", "SPY")file_name- Output filename without extension
Optional Parameters:
exchange_code- Exchange (default: "US")symbol_type- Type (default: "Common Stock")study- Study name (default: "ChartOnly")theme- Chart theme (default: "Dark Casual")chart_type- Candlestick/Line/HLC (default: "Candlestick")period- Daily/Weekly/Monthly/Yearly (default: "Daily")history_length- Days of history (default: 365)warmup_period- Extra bars for indicators (default: 200)zoom_level- Number of bars to display (default: 250)width- Image width in pixels (default: 1200)height- Image height (default: auto)prediction_mode- off/view_only/full (default: "view_only")bullish_signal- Bullish signal for overlaysbearish_signal- Bearish signal for overlaysmarker_source- actual/predicted (default: "actual")eod_historical_offset- Days back from today (0-30)
Example:
mcp__chart-generator__render_chart(
symbol_code="AAPL",
file_name="aapl_rsi",
study="RSIStudy",
zoom_level=120,
theme="Dark Casual"
)
2. list_studies
List all available chart studies.
Returns: Categorized list of 28+ studies
3. list_signals
List all available trading signals.
Returns: Bullish and bearish signal names
4. list_themes
List all available chart themes.
Returns: Available theme names
5. validate_config
Validate chart configuration before rendering.
Parameters:
symbol_code- Stock symbolstudy- Study name (optional)theme- Theme name (optional)bullish_signal- Bullish signal (optional)bearish_signal- Bearish signal (optional)
Returns: Validation status and errors if any
Installation
Prerequisites
- Python 3.11+
- trading-lab project available at expected path
MARKET_DATABASE_PATHorMARKETDATA_DB_PATHenvironment variable set
Setup
-
Create virtual environment:
cd /Volumes/Work/development/projects/git/mcp-chart-generator python3 -m venv venv -
Install dependencies:
venv/bin/pip install -r requirements.txt -
Configure in
.mcp.json(in trading-lab project):{ "mcpServers": { "chart-generator": { "type": "stdio", "command": "/Volumes/Work/development/projects/git/mcp-chart-generator/venv/bin/python3", "args": [ "/Volumes/Work/development/projects/git/mcp-chart-generator/chart_generator_mcp_server.py" ], "env": { "MARKET_DATABASE_PATH": "/Volumes/Work/marketdata/marketdata.db" } } } } -
Test the server:
cd /path/to/trading-lab claude mcp listYou should see
chart-generatorin the list with ✓ Connected status.
Usage Examples
Example 1: Simple Chart
User: "Generate an AAPL chart"
Claude uses:
mcp__chart-generator__render_chart(
symbol_code="AAPL",
file_name="aapl_chart"
)
Output: /tmp/aapl_chart.png
Example 2: Chart with RSI Study
User: "Show me SPY with RSI indicator, last 90 days"
Claude uses:
mcp__chart-generator__render_chart(
symbol_code="SPY",
file_name="spy_rsi_90d",
study="RSIStudy",
zoom_level=90
)
Output: /tmp/spy_rsi_90d.png
Example 3: Chart with Signal Overlays
User: "MSFT chart with buy/sell signals using ADM momentum"
Claude uses:
mcp__chart-generator__render_chart(
symbol_code="MSFT",
file_name="msft_signals",
bullish_signal="adm_momentum_low",
bearish_signal="adm_momentum_high",
zoom_level=180
)
Output: /tmp/msft_signals.png with buy/sell markers
Example 4: Discover Available Options
User: "What chart studies are available?"
Claude uses:
mcp__chart-generator__list_studies()
Returns: List of all 28+ studies categorized by type
Viewing Generated Charts
Important: Claude Code currently does not support inline image display (iTerm2 image protocol).
After generating a chart, you have two options to view it:
Option 1: Exit and use imgcat (iTerm2)
# Exit Claude Code session (Ctrl+D or /exit)
imgcat /tmp/your_chart.png
Option 2: Open in default viewer
# From within Claude Code or after exiting
open /tmp/your_chart.png
This will open the chart in Preview (macOS default image viewer).
Why this happens
Claude Code intercepts terminal output and doesn't currently pass through iTerm2's inline image escape sequences. This is tracked in GitHub issue #6389.
Workaround: The MCP server generates charts successfully; viewing them just requires opening them outside the Claude Code session.
Technical Details
Dependencies
The MCP server itself only requires:
mcp>=2,<3- MCP protocol implementation
The actual chart generation is handled by importing from the trading-lab project, which has its own dependencies (pandas, playwright, etc.).
Output Location
Generated charts are saved to /tmp/ directory with the filename specified in the file_name parameter.
Performance
- Chart generation takes 1-2 seconds per chart
- The server reuses resources for efficiency
- Can generate hundreds of charts in batch
Integration Points
Market Data:
- Requires
MARKET_DATABASE_PATHenvironment variable - Uses trading-lab's
marketdata.database.Database
Studies:
- Auto-discovers from
trading-lab/src/studies/ - Supports all 28+ studies
Signals:
- Uses
trading-lab/src/signals/bullish_signals/ - Uses
trading-lab/src/signals/bearish_signals/
Troubleshooting
Server won't connect
-
Check virtual environment:
ls -la /Volumes/Work/development/projects/git/mcp-chart-generator/venv/bin/python3 -
Verify dependencies:
/Volumes/Work/development/projects/git/mcp-chart-generator/venv/bin/pip list | grep mcp -
Check trading-lab path: Ensure
/Volumes/Work/development/projects/git/trading-lab/srcexists -
Verify environment variable:
echo $MARKET_DATABASE_PATH
Chart generation fails
-
Check database:
ls -la $MARKET_DATABASE_PATH -
Test trading-lab directly:
cd /Volumes/Work/development/projects/git/trading-lab source venv/bin/activate python tests/test_chart_generation_poc.py -
Validate configuration: Use
validate_configtool beforerender_chart
Development
Running Tests
Test the MCP server independently:
cd /Volumes/Work/development/projects/git/mcp-chart-generator
venv/bin/python3 chart_generator_mcp_server.py
This will start the server in stdio mode (waiting for MCP protocol messages).
Adding New Tools
Edit chart_generator_mcp_server.py:
- Add tool definition in
list_tools() - Add handler in
call_tool() - Implement the async function
Debugging
Enable debug logging in the trading-lab:
import logging
logging.basicConfig(level=logging.DEBUG)
Related Projects
- trading-lab - Main trading analysis platform
- mcp-marketdata-db - Market data MCP server
- mcp-strategy-research-db - Strategy backtest MCP server
- mcp-finance - Yahoo Finance MCP server
License
Same as trading-lab project.
Author
Created as part of the Trading Lab ecosystem for programmatic chart generation via MCP.
