ictedge-mcp¶
Window focus utility and TradingView Desktop launcher. Provides the focus-window tool and platform-specific scripts that start TradingView with Chrome DevTools Protocol enabled.
Why It Exists¶
tradingview-mcp connects to TradingView Desktop via CDP on localhost:9222. This requires TradingView to be launched with the --remote-debugging-port=9222 flag. ictedge-mcp handles this prerequisite: it launches TradingView correctly and ensures the window is focused and ready for CDP connections.
graph LR
ICT["ictedge-mcp"] -- "launch with CDP flag" --> TV["TradingView Desktop<br/>--remote-debugging-port=9222"]
TV -- "CDP WebSocket<br/>localhost:9222" --> MCP["tradingview-mcp"]
CDP Connection Manager (src/connection.js)¶
ictedge-mcp has its own independent CDP connection manager, separate from tradingview-mcp's connection.js. It manages its own connection lifecycle and does not share state with the main MCP server.
Three exported functions:
| Function | Purpose |
|---|---|
listChartTargets() |
Fetches http://localhost:9222/json/list, filters to page targets whose URL contains tradingview.com/chart/ |
connectToTarget(target) |
Opens a CDP WebSocket connection to a specific target by ID or target object. Enables Runtime domain. Caller must close the returned client. |
evalOnTarget(targetId, expression) |
Opens a connection, evaluates a JS expression via Runtime.evaluate, returns the result value, and closes the connection. Self-contained. |
This separation allows ictedge-mcp to enumerate and interact with TradingView windows without depending on tradingview-mcp being connected.
MCP Tools¶
tv_list_windows¶
Lists all TradingView chart windows currently open in the Desktop app.
Parameters: None.
Returns: An array of window objects, each containing:
| Field | Description |
|---|---|
targetId |
CDP target ID for this page |
symbol |
Ticker symbol (exchange prefix stripped, e.g., "SI1!" not "COMEX:SI1!") |
chartId |
Chart layout ID extracted from the URL path |
url |
Full TradingView chart URL |
The tool connects to each target and calls TradingViewApi._activeChartWidgetWV.value().symbol() to resolve the symbol, then strips the exchange prefix (splits on : and takes the last part).
tv_focus_window¶
Brings a TradingView window to the OS foreground by symbol or CDP target ID.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
string |
Symbol to focus (e.g., "ES1!"). Matches against the window title. Exchange prefixes are stripped automatically. |
target_id |
string |
CDP target ID (alternative to symbol). The symbol is resolved via CDP before focusing. |
Provide either symbol or target_id (not both required).
Implementation: Uses VBScript AppActivate via cscript.exe //nologo win-focus.vbs <title>. The VBScript approach was chosen over PowerShell for simplicity -- AppActivate performs a partial title match against all open windows.
Why focus matters: Pine Script indicator graphics only render on the visible/active chart window. After focusing a window, Pine graphics become readable by tradingview-mcp.
Window Focus Scripts¶
win-focus.vbs (Active)¶
The primary focus mechanism. Called programmatically by tv_focus_window. Uses WScript.Shell.AppActivate for partial window title matching.
win-focus.ps1 (Reference/Legacy)¶
PowerShell alternative that uses user32.dll P/Invoke (FindWindow, SetForegroundWindow, ShowWindow). This approach compiles a C# class at runtime for Win32 API access. Not actively used by the MCP tool -- retained as a reference implementation.
Launch Scripts¶
ictedge-mcp includes platform-specific scripts that start TradingView Desktop with the CDP debugging flag.
Windows¶
launch_tv_debug.bat -- Batch script for direct execution:
launch_tv_debug.vbs -- VBScript wrapper for silent launch (no console window):
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\TradingView\TradingView.exe"" --remote-debugging-port=9222", 1, False
The .vbs variant is preferred for automated workflows where a lingering console window is undesirable.
Linux / macOS¶
launch_tv_debug.sh -- Shell script:
The & backgrounds the process so the script returns immediately.
How CDP Gets Enabled¶
The key flag is --remote-debugging-port=9222. When TradingView Desktop (an Electron app) starts with this flag:
- Electron opens a WebSocket debug server on
localhost:9222 - The
/jsonendpoint lists available debug targets (pages/tabs) chrome-remote-interface(inside tradingview-mcp) connects to the WebSocket- CDP commands (
Runtime.evaluate,DOM.querySelector,Page.captureScreenshot) become available
Without this flag, port 9222 is not open and tradingview-mcp cannot connect.
sequenceDiagram
participant L as Launch Script
participant TV as TradingView Desktop
participant P as localhost:9222
participant MCP as tradingview-mcp
L->>TV: Start with --remote-debugging-port=9222
TV->>P: Open WebSocket debug server
MCP->>P: GET /json (discover targets)
P-->>MCP: Page target list
MCP->>P: WebSocket connect to page
P-->>MCP: CDP session established
MCP->>TV: Runtime.evaluate() / DOM queries
Integration with the Platform¶
ictedge-mcp sits at the very beginning of the platform chain:
| Step | Component | Action |
|---|---|---|
| 1 | ictedge-mcp | Launch TradingView with CDP flag |
| 2 | ictedge-mcp | Focus the TradingView window |
| 3 | tradingview-mcp | Connect via CDP on port 9222 |
| 4 | tradingview-strategy | Read indicators, produce signals |
| 5 | Dashboard | Display results |
In a typical workflow:
- Run the launch script once to start TradingView with debugging enabled
- Open the chart with the four ICT indicators loaded
- Start the strategy pipeline -- tradingview-mcp connects automatically
- Use
focus-windowas needed if TradingView loses focus
The launch only needs to happen once per session. As long as TradingView remains running with CDP enabled, the rest of the platform can connect and reconnect freely.