Skip to content

Commit 0206352

Browse files
authored
feat: add tradingview-cli for composable CLI usage (#44)
* chore: add .worktrees/ to .gitignore * feat: add tradingview-cli binary for composable CLI usage Add a standalone CLI interface alongside the existing MCP server, inspired by the argument that CLI tools are simpler, more composable, and more token-efficient than MCP servers. - New binary: `tradingview-cli` (same npm package, dual mode) - Commands: screen stocks/forex/crypto/etf, lookup, fields, preset(s) - Output formats: JSON (default), CSV, table - Preset support: --preset flag with automatic symbol-based detection - Zero new runtime dependencies (uses Node 18+ util.parseArgs) - 47 new tests covering arg parsing, formatters, and integration - MCP server remains 100% unchanged * autoresearch: expand CLI tests with edge cases (+8 tests) Add coverage for: columns override, sort-order override, malformed JSON filters, all result shapes (pairs/crypto/etfs/symbols) in CSV/table, preset with columns+filters merge, empty filters array. * autoresearch: add 15 end-to-end CLI tests, gitignore .autoresearch E2E tests verify full CLI dispatch via child process: help, version, presets, fields, screen help, and error handling for unknown commands, invalid asset types, missing symbols/preset names. * docs: add CLI usage docs, update README and CLAUDE.md for dual mode - Add CLI Usage section to README with commands, options, output formats - Update project description to mention CLI alongside MCP - Add CLI architecture docs to CLAUDE.md (dual entry points, cli/ helpers) - Update package.json description and add 'cli' keyword
1 parent bab92b8 commit 0206352

9 files changed

Lines changed: 1304 additions & 7 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ Thumbs.db
3535

3636
# Local documentation and specs
3737
docs/local/
38+
39+
# Worktrees
40+
.worktrees/
41+
42+
# Autoresearch
43+
.autoresearch/

CLAUDE.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
TradingView MCP Server is an unofficial Model Context Protocol server that provides access to TradingView's market screener API. It enables AI-powered stock, forex, crypto, and ETF screening through Claude Desktop or Claude Code.
7+
TradingView MCP Server is an unofficial Model Context Protocol server **and CLI tool** that provides access to TradingView's market screener API. It enables AI-powered stock, forex, crypto, and ETF screening through Claude Desktop, Claude Code, or the standalone `tradingview-cli` command.
88

99
## Build and Development Commands
1010

@@ -13,7 +13,8 @@ npm install # Install dependencies
1313
npm run build # Compile TypeScript to dist/
1414
npm test # Run all tests
1515
npm run test:watch # Run tests in watch mode
16-
npm run dev # Run directly with tsx (no build step)
16+
npm run dev # Run MCP server directly with tsx (no build step)
17+
npm run dev:cli # Run CLI directly with tsx (no build step)
1718
```
1819

1920
### Running a single test file
@@ -28,13 +29,24 @@ For local development, use `npm run dev` which runs TypeScript directly via tsx
2829

2930
## Architecture
3031

31-
### Entry Point and MCP Server Setup
32-
`src/index.ts` - Creates the MCP server, registers tools and resources, handles tool calls. Initializes core components:
32+
### Dual Entry Points
33+
The package has two entry points sharing all core logic:
34+
35+
**MCP Server**`src/index.ts`
36+
Creates the MCP server, registers tools and resources, handles tool calls via stdio. Initializes core components:
3337
- `TradingViewClient` - API client
3438
- `Cache` - Response caching (configurable TTL)
3539
- `RateLimiter` - Request throttling (configurable RPM)
3640
- `ScreenTool`, `FieldsTool`, `PresetsTool` - Tool implementations
3741

42+
**CLI**`src/cli.ts`
43+
Standalone CLI using Node's built-in `util.parseArgs`. Reuses the same tool classes. Output formats: JSON (default), CSV, table. No `cache.startCleanup()` (CLI is short-lived).
44+
45+
**CLI Helpers** (`src/cli/`)
46+
- `parseArgs.ts` - Option configs, input builders, preset merging
47+
- `formatters.ts` - JSON/CSV/table output formatters
48+
- `help.ts` - Help text for all commands
49+
3850
### Core Components
3951

4052
**API Layer** (`src/api/`)

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
[![License](https://img.shields.io/github/license/fiale-plus/tradingview-mcp-server?style=flat-square)](LICENSE)
1111
[![MCP](https://img.shields.io/badge/MCP-Compatible-blue?style=flat-square)](https://modelcontextprotocol.io)
1212

13-
**Unofficial** Model Context Protocol (MCP) server for TradingView's market screener API — stocks, forex, crypto & ETFs.
13+
**Unofficial** MCP server **and CLI** for TradingView's market screener API — stocks, forex, crypto & ETFs.
1414

1515
### AI-powered investment research for patient, systematic investors.
1616

17+
**Two modes, one package:** Use as an MCP server with Claude, or as a standalone CLI tool that pipes to `jq`, `csvtool`, or any Unix workflow.
18+
1719
</div>
1820

1921
---
@@ -22,6 +24,7 @@
2224

2325
- [Features](#features)
2426
- [Installation](#installation)
27+
- [CLI Usage](#cli-usage)
2528
- [Configuration](#configuration)
2629
- [MCP Tools](#mcp-tools)
2730
- [Screening Fields](#screening-fields)
@@ -35,6 +38,7 @@
3538

3639
## Features
3740

41+
- **Dual mode: MCP + CLI** — use as an MCP server with Claude or as a standalone `tradingview-cli` command
3842
- **100+ screener fields** including Piotroski F-Score, Altman Z-Score, Graham Number, analyst consensus, and dividend growth streaks
3943
- **18 filter operators** including `crosses_above` / `crosses_below` for golden cross detection
4044
- **14 pre-built strategies** covering value, growth, quality, GARP, deep value, breakouts, compounders, and macro monitoring
@@ -68,6 +72,68 @@ local-setup.bat # Windows
6872

6973
---
7074

75+
## CLI Usage
76+
77+
After installing the package, the `tradingview-cli` command is available globally:
78+
79+
```bash
80+
# List all pre-built screening strategies
81+
tradingview-cli presets
82+
83+
# Screen stocks using a preset
84+
tradingview-cli screen stocks --preset quality_stocks --limit 10
85+
86+
# Screen with custom filters
87+
tradingview-cli screen stocks --filters '[{"field":"price_earnings_ttm","operator":"less","value":15}]'
88+
89+
# Look up specific symbols (indexes, stocks)
90+
tradingview-cli lookup NASDAQ:AAPL TVC:SPX NYSE:MSFT
91+
92+
# Discover available screening fields
93+
tradingview-cli fields --asset-type stock --category fundamental
94+
```
95+
96+
### Output Formats
97+
98+
```bash
99+
# JSON (default) — pipe to jq
100+
tradingview-cli screen stocks --preset value_stocks | jq '.stocks[].name'
101+
102+
# CSV — pipe to file or csvtool
103+
tradingview-cli screen stocks --preset value_stocks -f csv > results.csv
104+
105+
# Table — human-readable terminal output
106+
tradingview-cli screen stocks --preset value_stocks -f table
107+
```
108+
109+
### CLI Commands
110+
111+
| Command | Description |
112+
|---|---|
113+
| `screen stocks [opts]` | Screen stocks by fundamental/technical criteria |
114+
| `screen forex [opts]` | Screen forex pairs |
115+
| `screen crypto [opts]` | Screen cryptocurrencies |
116+
| `screen etf [opts]` | Screen ETFs |
117+
| `lookup <symbols...>` | Look up specific symbols by ticker |
118+
| `fields [opts]` | List available screening fields |
119+
| `preset <name>` | Get a preset strategy's details |
120+
| `presets` | List all available presets |
121+
122+
### Screen Options
123+
124+
| Flag | Description |
125+
|---|---|
126+
| `--filters <json>` | Filter array as JSON string |
127+
| `--preset <name>` | Load a preset (merges with `--filters`) |
128+
| `--markets <market>` | Market to screen (repeatable, stocks/etf only) |
129+
| `--sort-by <field>` | Sort by field |
130+
| `--sort-order <asc\|desc>` | Sort direction |
131+
| `--limit <n>` | Max results (1-200, default 20) |
132+
| `--columns <col>` | Columns to include (repeatable) |
133+
| `-f, --format <fmt>` | Output: `json`, `csv`, or `table` |
134+
135+
---
136+
71137
## Configuration
72138

73139
### Claude Desktop

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "tradingview-mcp-server",
33
"version": "0.0.0-dev",
4-
"description": "Unofficial MCP server for TradingView stock screener API",
4+
"description": "Unofficial MCP server and CLI for TradingView stock screener API",
55
"type": "module",
66
"main": "dist/index.js",
77
"bin": {
8-
"tradingview-mcp-server": "dist/index.js"
8+
"tradingview-mcp-server": "dist/index.js",
9+
"tradingview-cli": "dist/cli.js"
910
},
1011
"files": [
1112
"dist/",
@@ -15,6 +16,7 @@
1516
"scripts": {
1617
"build": "tsc",
1718
"dev": "tsx src/index.ts",
19+
"dev:cli": "tsx src/cli.ts",
1820
"start": "node dist/index.js",
1921
"test": "tsx --test src/tests/*.test.ts",
2022
"test:watch": "tsx --test --watch src/tests/*.test.ts",
@@ -24,6 +26,7 @@
2426
"keywords": [
2527
"mcp",
2628
"tradingview",
29+
"cli",
2730
"stock-screener",
2831
"model-context-protocol",
2932
"claude",

0 commit comments

Comments
 (0)