MCP Server - TradingView Chart Image Scraper
🚀 Now with Browser Pooling Optimization for 70-80% Better Concurrent Performance!
This MCP server provides tools to fetch TradingView chart images based on ticker and interval with advanced browser pooling for maximum concurrent performance.
🔥 Performance Optimizations
Browser Pooling Technology
- Production Version: Uses
main_optimized.py
with browser pooling for maximum concurrent performance - Performance Improvement: 70-80% faster for concurrent requests
- Concurrent Handling: Supports up to 4 simultaneous requests with pre-initialized browser instances
- Expected Performance:
- 1 request: ~6-8s (baseline)
- 2 concurrent: ~3-4s each (60-70% faster)
- 3 concurrent: ~2.5-3.5s each (70-80% faster)
Version Comparison
main_optimized.py
(Production): Browser pooling, concurrent optimization, performance trackingmain.py
(Legacy): Simple single-browser approach, kept for debugging/fallback
Features
- 🚀 Optimized Chart Image Tool: Fetches direct chart images with browser pooling for maximum concurrent performance
- 📊 Performance Statistics: Built-in performance monitoring and statistics
- 🔄 Browser Pool Management: Pre-initialized browser instances for zero-overhead concurrent requests
- 🎯 Natural Language Prompts: Easy chart requests with interval mapping
- ⚙️ Environment Configuration: Fully configurable via environment variables
- 🔐 TradingView Authentication: Secure session-based authentication
- 💾 Clipboard Capture: Direct base64 image capture for faster performance
Tools
get_tradingview_chart_image
Description: Fetches the direct image URL for a TradingView chart snapshot with optimized concurrent performance.
Performance: This optimized version achieves 70-80% better performance for concurrent requests using browser pooling technology.
Arguments:
ticker
(str): The TradingView ticker symbol (e.g., "BYBIT.P", "NASDAQ"). Required.interval
(str): The chart time interval (e.g., '1', '5', '15', '60', '240', 'D', 'W'). Required.
Returns:
- (str): The direct TradingView snapshot image URL (e.g.,
data:image/png;base64,...
orhttps://s3.tradingview.com/snapshots/...
).
Raises:
Error
(MCP type): If the scraper encounters an error. Error codes:400
: Input error (invalid ticker/interval format)503
: Scraper error (failure during the scraping process)500
: Unexpected internal server error
get_performance_stats
Description: Get performance statistics for the optimized TradingView MCP server.
Returns:
- Detailed metrics about request performance, improvement over baseline, and browser pool status
Example Output:
Prompts
Get the {interval} chart for {ticker}
- Maps common timeframe names (e.g., "1 minute", "5 minute", "1 hour", "daily") to TradingView codes
Show me the daily TradingView chart for {ticker}
- Specifically requests the daily ('D') chart
Fetch TradingView chart image for {ticker} on the {interval} timeframe
- Comprehensive prompt with timeframe mapping
Setup
- Create Virtual Environment:
- Activate Virtual Environment:
- macOS/Linux:
- Windows (Git Bash/WSL):
- Windows (Command Prompt):
- Windows (PowerShell):(Note: You might need to adjust PowerShell execution policy:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
)
Your terminal prompt should now indicate you are in the
(.venv)
. - macOS/Linux:
- Install Dependencies (inside venv):
- Configure Environment (for Local Testing):
- Copy
.env.example
to.env
. - Fill in your
TRADINGVIEW_SESSION_ID
andTRADINGVIEW_SESSION_ID_SIGN
in the.env
file. You can obtain these from your browser's cookies after logging into TradingView. - This
.env
file is used when running the server directly (e.g.,python main.py
) for local testing. - Adjust optional scraper settings (
MCP_SCRAPER_HEADLESS
, etc.) in.env
if needed for local runs.
- Copy
- Ensure ChromeDriver: Make sure
chromedriver
is installed and accessible in your system's PATH, or configure thetview-scraper.py
accordingly if it allows specifying a path.
Running the Server
Production (Optimized)
Legacy (Simple)
Command Line Options
🧪 Performance Testing
Agent-Style Testing
Test the server using the same approach as the production agent:
Expected Results
- Sequential: ~6-8s per request (baseline)
- Concurrent (3x): ~2.5-3.5s per request (70-80% improvement)
- Success Rate: 100% reliability under load
- Throughput: Up to 4 concurrent requests efficiently handled
🔧 Technical Details
Browser Pooling Architecture
- Pre-initialized Browsers: 4 browser instances ready for immediate use
- Thread-Safe Pool: Concurrent access with proper locking
- Async Semaphore: Optimal request limiting
- Performance Tracking: Real-time statistics and monitoring
- Graceful Cleanup: Proper browser lifecycle management
Save Shortcut Feature
The MCP_SCRAPER_USE_SAVE_SHORTCUT
feature allows you to capture chart images directly to the clipboard as base64 data URLs:
Benefits:
- Faster Performance: No HTTP requests needed
- More Reliable: No dependency on TradingView's CDN
- Offline Capability: Works once chart is loaded
- Direct Integration: Base64 data URLs for immediate use
Configuration:
Usage Examples
Available Tools:
get_tradingview_chart_image(ticker: str, interval: str)
: Optimized chart fetching with browser pooling
Example Prompts:
- "Get the 15 minute chart for NASDAQ"
- "Show me the daily chart for BYBIT.P"
- "Fetch TradingView chart image for COINBASE:ETHUSD on the 60 timeframe"
Deactivating the Virtual Environment
When finished:
🔄 Fallback Options
If you encounter issues with the optimized version:
- Disable Browser Pooling:
- Use Legacy Version:
- Debug Mode:
📊 Performance Monitoring
The optimized server includes built-in performance monitoring:
- Request success rates
- Average response times
- Performance improvement metrics
- Browser pool utilization
- Concurrent request handling statistics
Access these metrics via the get_performance_stats
tool or through the server logs.
🔌 Using with MCP Clients (Claude Desktop / Cursor)
This server supports two ways of providing configuration:
- Via
.env
file (for local testing): When runningpython main.py
directly, the server will load credentials and settings from a.env
file in the project directory. - Via Client Environment Variables (Recommended for Integration): When run by an MCP client (like Claude/Cursor), you should configure the client to inject the required environment variables directly. These will override any values found in a
.env
file.
Claude Desktop
- Open your Claude Desktop configuration file:
- Windows:
%APPDATA%\\Claude\\claude_desktop_config.json
- macOS:
~/Library/Application\ Support/Claude/claude_desktop_config.json
- Windows:
- Add or merge the following within the
mcpServers
object. Provide your credentials in theenv
block: - Replace the placeholder paths (
command
,args
) with your actual absolute paths. - Replace
YOUR_SESSION_ID_HERE
andYOUR_SESSION_ID_SIGN_HERE
with your actual TradingView credentials. - Restart Claude Desktop.
Cursor
- Go to:
Settings -> Cursor Settings -> MCP -> Edit User MCP Config (~/.cursor/mcp.json)
. - Add or merge the following within the
mcpServers
object. Provide your credentials in theenv
block: - Replace the placeholder paths (
command
,args
) with your actual absolute paths. - Replace
YOUR_SESSION_ID_HERE
andYOUR_SESSION_ID_SIGN_HERE
with your actual TradingView credentials. - Restart Cursor.
Installing via Smithery
To install TradingView Chart Image Scraper for Claude Desktop automatically via Smithery:
Configuration
Environment Variables
The following environment variables can be set to configure the scraper:
TRADINGVIEW_SESSION_ID
: Your TradingView session ID (required)TRADINGVIEW_SESSION_ID_SIGN
: Your TradingView session ID signature (required)MCP_SCRAPER_HEADLESS
: Run browser in headless mode (default:True
)MCP_SCRAPER_WINDOW_WIDTH
: Browser window width (default:1920
)MCP_SCRAPER_WINDOW_HEIGHT
: Browser window height (default:1080
)MCP_SCRAPER_USE_SAVE_SHORTCUT
: Use clipboard image capture instead of screenshot links (default:True
)MCP_SCRAPER_CHART_PAGE_ID
: Custom chart page ID (optional)
Save Shortcut Feature
The MCP_SCRAPER_USE_SAVE_SHORTCUT
feature allows you to capture chart images directly to the clipboard as base64 data URLs instead of getting screenshot links. This eliminates the need to download images from URLs.
Benefits:
- Faster chart capture (no HTTP requests needed)
- More reliable (no dependency on TradingView's CDN)
- Works offline once the chart is loaded
- Direct base64 data URLs for immediate use
How it works:
- When enabled (
True
): UsesShift+Ctrl+S
(orShift+Cmd+S
on Mac) to capture chart image directly to clipboard - When disabled (
False
): Uses traditionalAlt+S
to get screenshot links, then converts to image URLs
Configuration:
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Gráfico MCP de Tradingview
Related MCP Servers
- PythonMIT License
- PythonMIT License
- -securityAlicense-qualityTwitter Marketing MCPLast updated 3 months agoPythonMIT License
- TypeScriptMIT License