tradingview-mcp
tradingview-mcp
tradingview-mcp/ v0.1 ──────────────────────────────────────────────────一个专注且类型安全的 MCP 服务器,让 Claude Code(或任何兼容 MCP 的客户端)能够驱动本地运行的 TradingView 桌面版应用程序 —— 读取图表状态、更改交易品种和时间周期、获取 OHLCV 数据、截取屏幕截图。
[!IMPORTANT] 本项目与 TradingView Inc. 无关,未得到其认可或关联。 这是一个个人使用的桥接工具,通过 Chrome DevTools 协议与您本地运行的 TradingView 桌面版应用程序进行交互 —— 这与 Slack、VS Code、Discord 以及其他所有 Electron 应用内置的调试接口标准相同。
[!IMPORTANT] 需要有效的 TradingView 订阅。 本工具不会绕过、抓取或规避任何 TradingView 的付费墙或访问控制。所有操作均在您的机器上进行,针对的是您已经登录并付费的 TradingView 桌面版实例。
[!NOTE] 所有处理均在本地进行。 本工具不会传输、存储或重新分发任何 TradingView 数据。您的图表、您的数据、您的机器。
[!CAUTION] TradingView 的内部页面 API 未经文档记录。它可能会在桌面版发布版本之间发生变化。如果您需要稳定性,请锁定一个可用的 TradingView 桌面版版本,并在升级前查看 版本兼容性 说明。
功能概述
将 TradingView 桌面版图表封装在一组定义明确的 MCP 工具中。工具通过 Zod 模式进行端到端类型定义,在边界处进行验证,并在出错时提供有用的错误信息。
┌───────────────┐
│ Claude Code │
│ (or any MCP │
│ client) │
└───────┬───────┘
│ stdio (MCP)
▼
┌───────────────┐
│tradingview-mcp│
└───────┬───────┘
│ Chrome DevTools Protocol
▼
┌───────────────┐
│ TradingView │
│ Desktop │
│ (--remote- │
│ debugging- │
│ port=9222) │
└───────────────┘Related MCP server: TradingView MCP Jackson
为什么需要另一个 TradingView 集成?
现有的 TradingView 自动化项目已经存在。本项目特意缩小了范围:
12 个工具,而不是 78 个。 每个工具都经过文档记录、类型定义和测试。
严格的 TypeScript。 没有
any,没有隐式返回,开启了noUncheckedIndexedAccess。每个文件单一职责。 连接、页面、工具和服务器是独立的层级 —— 版本漂移只需修复一个地方。
类型化错误。
ConnectionError、ToolExecutionError、ChartStateError等,并带有可操作的消息。tradingview-mcp doctor。 一个诊断命令,可以准确告诉您设置中存在的问题。
如果您想要一个可以在一下午读完的小型、可预测的接口,请使用此工具。如果您想要封装所有 TradingView 功能的“大而全”替代方案,请使用其他工具。
安装
需要 Node.js 20+。
npm install -g tradingview-mcp
# or, in a project:
npm install tradingview-mcp用于开发:
git clone https://github.com/harshil1502/tradingview-mcp.git
cd tradingview-mcp
npm install
npm run build设置 —— 三个步骤
1. 退出所有正在运行的 TradingView 桌面版
否则无法启用调试端口。
2. 启动带有调试端口的 TradingView 桌面版
macOS:
open -a "TradingView" --args --remote-debugging-port=9222Windows:
& "C:\Users\<you>\AppData\Local\Programs\TradingView\TradingView.exe" --remote-debugging-port=9222Linux:
tradingview --remote-debugging-port=9222[!NOTE]
--remote-debugging-port标志是一个标准的 Chromium 调试标志。它是可选的,默认禁用。除非您明确传递它,否则不会发生任何事情。
3. 验证连接
tradingview-mcp doctor如果一切连接正常,您将看到类似以下内容:
tradingview-mcp · doctor
─────────────────────────────────────────────
[ok] CDP endpoint reachable on localhost:9222
[ok] TradingView page found (NASDAQ:AAPL · 1h)
[ok] tvWidget detected — chart state readable
─────────────────────────────────────────────
ready.与 Claude Code 一起使用
将其添加到您的 Claude Code MCP 配置中(~/.claude/mcp.json 或项目 .mcp.json):
{
"mcpServers": {
"tradingview": {
"command": "tradingview-mcp",
"env": {
"TV_MCP_PORT": "9222"
}
}
}
}重启 Claude Code。下面的工具将变为可用状态。
工具
工具 | 描述 |
| 读取当前交易品种、时间周期、可见指标、最新价格 |
| 更改活动交易品种(例如 |
| 更改分辨率( |
| 从活动图表中获取最多 5,000 条最新的 OHLCV 数据 |
更多工具即将推出 —— 请参阅 docs/roadmap.md。
示例会话
You: What's the chart showing?
Claude: [calls chart_get_state]
Showing NASDAQ:AAPL on 1h timeframe with EMA20, EMA50.
Last price 187.42.
You: Switch to BTCUSDT 4h and pull the last 200 bars.
Claude: [calls chart_set_symbol, chart_set_timeframe, chart_get_ohlcv]
Done. Range: 187 days. Open at start: 62,440.
Close at end: 67,830. +8.6%.配置
环境变量 | 默认值 | 描述 |
|
| CDP 主机 |
|
| CDP 调试端口 |
| (自动检测) | 显式 CDP 目标 ID —— 仅在打开多个 TradingView 窗口时需要 |
开发
npm install
npm run build # tsc to dist/
npm run dev # tsc --watch
npm test # vitest run
npm run test:coverage # with v8 coverage report
npm run typecheck # tsc --noEmit代码库分为四个层级:
src/
├── index.ts entry — reads env, starts stdio server
├── server.ts MCP server, tool registration, request handlers
├── errors.ts typed error classes
├── types.ts shared types + Zod schemas
├── connection/
│ ├── cdp.ts CDP client wrapper (chrome-remote-interface)
│ └── tradingview.ts TradingView-page interactions (all evaluated JS lives here)
└── tools/
├── index.ts tool registry
└── chart.ts chart_* tools添加工具:
在
src/tools/下创建一个新文件(或扩展现有文件)。导出
<name>Input和<name>OutputZod 模式以及处理函数。将条目添加到
src/tools/index.ts中的TOOLS。在
tests/下添加测试。
就是这样 —— 自动注册、自动验证、自动内省。
版本兼容性
TradingView 桌面版 | tradingview-mcp | 状态 |
2026.x.x | 0.1.x | 已测试 |
如果 TradingView 更新导致工具开始失效,请首先检查 connection/tradingview.ts —— 这是唯一了解 TradingView 内部 API 的文件。
免责声明
本软件按“原样”提供,不附带任何形式的保证。运行本软件即表示您承认:
您正在使用自己的付费 TradingView 桌面版实例,针对自己的数据进行操作。
您自行启用了 Chrome DevTools 调试端口。
TradingView 的内部 API 未经文档记录,可能会发生中断。
本软件中的任何内容都不能保证 AI 代理在其之上做出的交易决策的正确性。在让其触及真实资金之前,请先在模拟账户上使用。
许可证
MIT © 2026 Harshil Patel
致谢
这是一个全新的实现 —— 从零开始构建,目标是小巧、类型良好且易于阅读。如果您曾在此领域从事过类似工具的开发,感谢您铺平道路。
Available Tools
11 toolschart_get_ohlcvB
Fetch recent OHLCV bars from the active chart.
Inputs: count.
chart_get_stateA
Read the current chart state: symbol, timeframe, visible studies, and last price.
Inputs: no named parameters.
chart_set_symbolB
Change the active chart symbol (e.g. "NASDAQ:AAPL").
Inputs: symbol (required).
chart_set_timeframeB
Change the active chart timeframe / resolution.
Inputs: timeframe (required).
pine_compileB
Trigger a Pine compile and return diagnostics (errors, warnings).
Inputs: no named parameters.
pine_get_sourceA
Read the current Pine Editor source code. Pine Editor must be open.
Inputs: no named parameters.
pine_saveA
Save the current Pine script (commits + reloads the indicator on the chart).
Inputs: no named parameters.
pine_set_sourceB
Replace the Pine Editor source code with new content.
Inputs: code (required).
quote_getA
Get a real-time quote snapshot for the active symbol (last price, day OHLC, volume).
Inputs: no named parameters.
screenshot_chartA
Capture the chart pane as a base64-encoded PNG.
Inputs: no named parameters.
screenshot_fullA
Capture the full TradingView viewport as a base64-encoded PNG.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Each tool has a clearly distinct purpose. The chart_* tools handle different aspects of chart interaction, pine_* tools manage Pine script editing and compilation, screenshot_* tools capture images, and quote_get fetches real-time quotes. No overlapping functionality.
Tool names follow a consistent pattern: <domain>_<verb>_<noun> (e.g., chart_get_ohlcv, pine_set_source, screenshot_chart). All use lowercase with underscores, and the verb-noun structure is uniform across domains.
With 11 tools, the server is well-scoped for a TradingView MCP. It covers chart manipulation, Pine scripting, quotes, and screenshots without being bloated or too sparse.
The tool set covers core workflows like symbol/timeframe changes, data retrieval, Pine script management, and screenshots. A minor gap is the lack of tools to add or remove studies (only visible studies are read), but this does not severely hinder typical use cases.
Maintenance
Related MCP Connectors
Trading MCP server for AI agents, with live market data, account reads and controlled execution.
MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents
> TradingMCP puts a market analyst inside your AI assistant. Paste one URL into Claude, ChatGPT, Cursor, VS Code or any MCP client and ask in plain language: screen for breakouts, run a multi-timeframe analysis, backtest a strategy with walk-forward validation, scan for smart-money and volume signals, or get a one-prompt morning market brief. In clients that support MCP Apps, price charts and the Markets panel are drawn right in the chat. > 40+ tools covering crypto (real-time), stocks, ETFs, FX, futures and commodities across major global exchanges. > Hosted, nothing to install: Pro $9/month (2,500 tool calls) or Pro+ $29/month (10,000). Paid upfront with a 14-day money-back guarantee; your API key arrives right after checkout. > Built on the open-source tradingview-mcp core (MIT, ~5k GitHub stars): self-host it free, or use the hosted version with zero ops. > For research and education, not financial advice. Not affiliated with TradingView
Official Intrinio MCP server. US stock prices, options and fundamentals for AI agents.
Related MCP Servers
- AlicenseBqualityAmaintenanceMCP server that lets AI agents directly control and interact with the TradingView desktop app via 88 chart-control tools, enabling automated chart reading, Pine Script compilation, strategy optimization, and replay control.11344 npm61MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that connects to TradingView Desktop via Chrome DevTools Protocol, enabling chart control, Pine Script development, and a morning brief workflow with AI-driven analysis.-
- AlicenseAqualityDmaintenanceA Codex-first MCP server that bridges TradingView Desktop via Chrome DevTools Protocol, enabling launch, symbol/timeframe control, and health checks from Codex CLI.54MIT
- AlicenseNot gradedqualityAmaintenanceA local MCP server that connects TradingView Desktop to AI assistants via Chrome DevTools Protocol, enabling Pine Script development, multi-timeframe analysis, and Wyckoff scanning with a rules engine.44 npm1MIT