Skip to content

tradingview-mcp

A 78-tool MCP server connecting to TradingView Desktop via Chrome DevTools Protocol. Two runtime dependencies. Zero framework bloat.


Architecture

graph LR
    TV["TradingView Desktop<br/>localhost:9222"] -- "CDP WebSocket" --> CRI["chrome-remote-interface"]
    CRI --> CORE["Core Modules (15)"]
    CORE --> TOOLS["Tools (78)<br/>Zod schemas"]
    CORE --> CLI["CLI Interface"]
    TOOLS --> SDK["@modelcontextprotocol/sdk<br/>MCP protocol"]

tradingview-mcp follows a three-layer separation:

  • Core modules (15) -- CDP connection, DOM traversal, data extraction. Framework-agnostic, directly importable.
  • Tools (78) -- Wrap core functions with Zod input/output schemas, exposed through MCP protocol.
  • CLI -- Same capabilities via command line for scripting and debugging.

Runtime Dependencies

Dependency Role
chrome-remote-interface CDP client -- WebSocket connection to TradingView
@modelcontextprotocol/sdk MCP protocol implementation

Two dependencies total. No Puppeteer, no Playwright, no Electron helpers.


78 Tools in 12 Categories

Category Count Description
Health 4 Connection status, browser info, page readiness, heartbeat
Chart Control 10 Symbol changes, timeframe switching, scrolling, zooming, range selection
Data Access 13 OHLCV data, quotes, DOM reads, watchlist, screener
Pine Script 12 Pine labels, lines, boxes, tables, indicator list, study management
Drawing 5 Trendlines, horizontal lines, rectangles, text, drawing removal
Alerts 3 Alert creation, listing, deletion
Replay 6 Replay mode control, stepping, speed, date selection
Capture 1 Chart screenshot to file
Batch 1 Execute multiple tools in a single call
UI Automation 13 Dialog interaction, menu navigation, element clicks, keyboard input
Panes 4 Pane management, indicator pane targeting
Tabs 4 Tab switching, listing, creation, closure

CDP Connection

TradingView Desktop is an Electron app. When launched with --remote-debugging-port=9222, it exposes a Chrome DevTools Protocol endpoint. tradingview-mcp connects via WebSocket and evaluates JavaScript directly in TradingView's browser context to read DOM state, extract Pine graphics, and trigger UI actions.

TradingView Desktop (Electron)
    |
    | --remote-debugging-port=9222
    v
WebSocket: ws://localhost:9222/devtools/page/{id}
    |
    v
chrome-remote-interface (CDP client)
    |
    v
Runtime.evaluate() / DOM.querySelector() / Page.captureScreenshot()

6 Critical Strategy Tools

The strategy layer uses a focused subset. These are the tools that matter:

Pine Graphics Readers

Tool Returns Used By
data_get_pine_labels Labels: text, coordinates, color, style, tooltip Bias, Session, OB, SMT readers
data_get_pine_lines Lines: start/end coordinates, color, width, style Session, SMT readers
data_get_pine_boxes Boxes: coordinates, colors, borders, text OB reader
data_get_pine_tables Tables: cell values, colors, positions Bias reader

Chart State and Health

Tool Returns Used By
tv_health_check Connection status, page readiness Pipeline startup
chart_get_state Current symbol, timeframe, visible range Engine context

The study_filter Parameter

All Pine graphics tools accept an optional study_filter string. When provided, results are limited to graphics from indicators whose name matches the filter.

// All labels from every indicator
await data.getPineLabels();

// Only Bias AI labels
await data.getPineLabels({ study_filter: "Bias AI" });

// Only OB AI boxes
await data.getPineBoxes({ study_filter: "OB AI" });

This is critical for the strategy layer. Each reader targets its specific indicator by name, preventing cross-contamination between indicator outputs. If an indicator is renamed on the chart, the corresponding reader's filter must be updated.


Direct Import API

The strategy layer imports core modules directly, bypassing MCP protocol overhead:

import { data, chart } from 'tradingview-mcp/core';

const labels = await data.getPineLabels({ study_filter: "Bias AI" });
const state  = await chart.getState();
const ohlcv  = await data.getOhlcv();

Same Zod validation. Lower latency. Simpler error handling.


Strengths

Strength Detail
2-dependency footprint Entire server runs on two packages. Minimal attack surface.
Input sanitization 28 tests ensure every tool rejects malformed input before touching the browser.
Three-layer separation Core is importable without MCP. Tools add schemas. CLI adds terminal access. Each independently testable.
Dual MCP + CLI npx tradingview-mcp chart_get_state works from any terminal.
study_filter targeting Per-indicator data extraction without noise from other studies.

Limitations

Limitation Impact
Single browser connection One CDP session at a time. No multi-instance sharing.
Visible range only Pine graphics tools return data for the visible chart range. Historical data beyond the viewport requires scrolling.
Indicator name coupling study_filter uses string matching. Renamed indicators break readers.
No plot data access Pine plots (line plots, histograms) are rendered pixels, not queryable objects. Strategy uses labels/lines/boxes/tables exclusively.
Electron dependency Requires TradingView Desktop specifically. Web browser version does not expose CDP.