How tejas-040303/tradingview-mcp works
Purpose and process topology
This repository exposes two independent local MCP servers for AI-assisted trading workflows: a TradingView Desktop controller/reader over Chrome DevTools Protocol (CDP), and a read-only MetaTrader 5 data service backed by Python. They can run separately, communicate only through localhost, and are also usable through a tv CLI.
• src/server.js
• src/mt5-server.js
• src/cli/index.js
TradingView MCP boundary
The TradingView server is a Node.js stdio MCP process. Tool registration/adaptation lives in src/tools/, while operational implementations live in src/core/. A shared CDP connection layer targets the user-launched TradingView Electron instance on port 9222; TradingView itself remains the stateful chart/UI authority.
• src/connection.js
• src/core/index.js
• src/tools/chart.js
TradingView workflow domains
Core modules organize chart state/data extraction, chart and pane navigation, Pine editor automation, drawings/alerts, replay, screenshots, UI automation, watchlists, tabs, and polling streams. Typical control flow is MCP tool/CLI command → tool adapter → core operation → CDP evaluation/UI interaction → compact structured response.
• src/core/chart.js
• src/core/pine.js
• src/core/stream.js
CLI and command routing
The tv CLI is a parallel front door rather than a separate implementation: command modules parse user input and route into the same capabilities, preserving pipe-friendly JSON behavior. The router/index are the primary CLI composition points.
• src/cli/index.js
• src/cli/router.js
• src/cli/commands/pine.js
MT5 read-only bridge
Because MT5’s official binding is Python and Windows-specific, the Node MT5 MCP server proxies to a separate local HTTP bridge. The bridge owns terminal calls, normalization, analytics, calendar ingestion, and strict read-only route behavior; no order-operation path exists. MT5 times are normalized to explicitly labeled broker-server and UTC values, with null/refusal rather than guessed offsets.
• src/mt5-server.js
• mt5-bridge/bridge.py
• mt5-bridge/mt5_client.py
Broker analytics and strategy simulation
The Python subsystem converts raw deals into paired trades, derives excursion/analytics insights, and provides deterministic strategy setup detection, backtests, parameter sweeps, reconciliation against actual trades, and reconstructed paper state. Simulation output is intentionally shaped like real trades so downstream analytics/dashboard use a common path.
• mt5-bridge/normalize.py
• mt5-bridge/analytics.py
• mt5-bridge/strategy.py
Dashboard and runtime orchestration
The bridge serves a same-origin dashboard and API. A React/Vite analytics UI consumes precomputed API statistics rather than calculating metrics client-side; plain HTML/JS dashboard fallbacks coexist under the bridge. The Node launcher probes services, starts only missing local processes, and conditionally builds dashboard assets.
• dashboard-app/src/App.jsx
• dashboard-app/src/lib/api.js
• scripts/start.js
External dependencies and infrastructure
Material runtimes are Node.js for MCP, CLI, CDP control, and launcher; Python 3.9+ plus MetaTrader5 for the broker bridge; and a build-time React/Vite/Tailwind dashboard. External application boundaries are TradingView Desktop via local CDP :9222, MT5 terminal through the Python package, and an MQL5 calendar exporter that writes JSON for the bridge to consume.
• mt5-bridge/calendar_export.mq5
• mt5-bridge/calendar_export.mq5
• dashboard-app/vite.config.js
Components 22
TradingView control
- TradingView MCP server
src/server.js - Tool adapters
src/tools/chart.js - TradingView core · Chart, Pine, UI, drawing, replay, and watchlist operations.
src/core/index.js - Chart operations
src/core/chart.js - Pine automation
src/core/pine.js - Polling streams
src/core/stream.js - CDP connection
src/connection.js - TradingView Desktop · Stateful chart and UI authority exposed on localhost :9222.
- tv CLI
src/cli/index.js - CLI router
src/cli/router.js - Pine command
src/cli/commands/pine.js
MT5 read-only analytics
- MT5 MCP server
src/mt5-server.js - MT5 HTTP bridge · Enforces read-only routes and serves normalized data, analytics, and dashboard APIs.
mt5-bridge/bridge.py - MT5 terminal client · Obtains terminal data with explicit broker-server and UTC time handling.
mt5-bridge/mt5_client.py - MetaTrader 5 terminal
- Trade normalization · Pairs raw deals into common trade-shaped records.
mt5-bridge/normalize.py - Analytics and simulation · Derives trade insights and deterministic backtests, sweeps, reconciliation, and paper state.
mt5-bridge/analytics.py - Strategy engine
mt5-bridge/strategy.py - MQL5 calendar exporter · Writes calendar JSON for bridge ingestion.
mt5-bridge/calendar_export.mq5
Dashboard and orchestration
- React analytics dashboard · Renders precomputed API statistics rather than calculating metrics client-side.
dashboard-app/src/App.jsx - Dashboard API client
dashboard-app/src/lib/api.js - Local launcher · Probes services, starts missing processes, and conditionally builds dashboard assets.
scripts/start.js
Connections 23
- TradingView MCP server → Tool adapters: registers tools
- Tool adapters → TradingView core: adapts requests
- TradingView core → Chart operations: chart workflow
- TradingView core → Pine automation: Pine workflow
- TradingView core → Polling streams: stream workflow
- TradingView core → CDP connection: CDP evaluation/UI
- CDP connection → TradingView Desktop: localhost :9222
- tv CLI → CLI router: routes commands
- CLI router → Pine command: selects command
- Pine command → Pine automation: shared capability
- MT5 MCP server → MT5 HTTP bridge: local HTTP proxy
- MT5 HTTP bridge → MT5 terminal client: read-only terminal calls
- MT5 terminal client → MetaTrader 5 terminal: MetaTrader5 binding
- MT5 HTTP bridge → Trade normalization: normalizes deals
- Trade normalization → Analytics and simulation: common trades
- Analytics and simulation → Strategy engine: runs simulations
- MQL5 calendar exporter → MT5 HTTP bridge: calendar JSON
- React analytics dashboard → Dashboard API client: requests statistics
- Dashboard API client → MT5 HTTP bridge: same-origin API
- Local launcher → MT5 HTTP bridge: starts if absent
- Local launcher → React analytics dashboard: builds/starts locally
- Local launcher → TradingView MCP server: starts if absent
- Local launcher → MT5 MCP server: starts if absent