GainLab MCP Server
Agent's Eyes for Financial Charts 📊
Agents can analyze, but they can't draw charts. GainLab gives agents eyes.
Live Demo • 7 Tools • 4 Markets • Quick Start
______________________________________________________________________
什么是GainLab?
每个AI代理(Claude、ChatGPT、OpenClaw、自定义代理)都需要 展示 GainLab是一个MCP服务器,提供专业的财务图表可视化。
You: "Compare BTC vs Gold performance this year"
↓ MCP Protocol
GainLab: fetches data → normalizes → renders overlay chart → returns interactive HTML工具
| 工具 | 描述 | 状态 |
|---|---|---|
gainlab_kline | 带交易量的烛台图 | ✅ 现场直播 |
gainlab_indicators | 技术指标(MA/EMA/RSI/MACD/BOLL/KDJ/VWAP/ATR) | ✅ 现场直播 |
gainlab_overlay | 多资产比较(2-6个资产,标准化) | ✅ 现场直播 |
gainlab_fundamentals | 财务、DCF估值、分析师估计(17个指标) | ✅ 现场直播 |
gainlab_volume_profile | 按POC、VAH、VAL价格分布的交易量 | ✅ 现场直播 |
gainlab_heatmap | 行业树状图+资产相关性矩阵 | ✅ 现场直播 |
gainlab_wrb_scoring | WRB/带Pro信号检测的隐藏间隙分析 | ✅ 现场直播 |
市场
| 市场 | 数据来源 | Klines | 基本面 |
|---|---|---|---|
| 🪙 加密货币 | 币安(免费) | ✅ | — |
| 🇺🇸 美国股市 | FMP(8美元/月) | ✅ 每日 | ✅ |
| 🇨🇳 A股 | EODHD | ✅ 每日 | ✅ |
| 🥇 贵金属 | EODHD | ✅ 每日 | -- |
快速开始
选项1:使用克劳德桌面
增添 claude_desktop_config.json:
{
"mcpServers": {
"gainlab": {
"command": "npx",
"args": ["tsx", "/path/to/gainlab-mcp/src/index.ts"],
"env": {
"FMP_API_KEY": "your-key",
"EODHD_API_KEY": "your-key"
}
}
}
}然后问克劳德: *“用RSI和MACD绘制BTC每日K线图”*
选项2:直接运行
git clone https://github.com/Ashersun1207/gainlab-mcp.git
cd gainlab-mcp
pnpm install
pnpm dev # starts MCP server on stdioAPI密钥(可选)
加密货币无需任何密钥即可工作。对于其他市场:
export FMP_API_KEY=xxx # US stocks ($8/mo starter plan)
export EODHD_API_KEY=xxx # A-shares + precious metals工具参考
gainlab_kline
{
"symbol": "BTCUSDT",
"market": "crypto",
"timeframe": "1d",
"limit": 100,
"format": "interactive"
}gainlab_indicators
{
"symbol": "AAPL",
"market": "us_stock",
"timeframe": "1d",
"indicators": ["MA", "RSI", "MACD", "VWAP", "ATR"],
"ma_periods": [7, 25, 99],
"limit": 100
}支持的指标: MA, EMA, RSI, MACD, BOLL, KDJ, VWAP, ATR (+锚定VWAP)。
gainlab_overlay
{
"assets": [
{ "symbol": "BTCUSDT", "market": "crypto" },
{ "symbol": "XAUUSD", "market": "commodity" }
],
"timeframe": "1d",
"period": "1Y",
"normalize": true
}gainlab_fundamentals
标准模式 --条形图:
{
"symbols": ["AAPL", "MSFT", "GOOGL"],
"market": "us_stock",
"metrics": ["revenue", "free_cash_flow", "roe"],
"period": "annual",
"years": 5
}支持的指标: revenue, net_income, gross_margin, operating_margin, eps, ebitda, operating_cash_flow, free_cash_flow, capex, pe_ratio, pb_ratio, ev_ebitda, roe, roa, profit_margin, current_ratio, dividend_yield.
DCF模式 --估价标准:
{
"symbols": ["AAPL"],
"market": "us_stock",
"mode": "dcf"
}估算模式 --实际与分析师预测:
{
"symbols": ["AAPL"],
"market": "us_stock",
"mode": "estimates",
"metrics": ["eps"]
}gainlab_volume_profile
{
"symbol": "BTCUSDT",
"market": "crypto",
"timeframe": "1d",
"limit": 100,
"rows": 24,
"value_area_percent": 70,
"format": "interactive"
}显示POC(控制点)、VAH(价值区域高)、VAL(价值区域低)和买卖量分布。
gainlab_heatmap
部门树状图 --Finviz风格的市场概述:
{
"type": "sector_treemap",
"market": "crypto",
"change_period": "1d",
"limit": 100,
"format": "interactive"
}相关矩阵 --成对皮尔逊相关系数:
{
"type": "correlation_matrix",
"assets": [
{ "symbol": "BTCUSDT", "market": "crypto" },
{ "symbol": "ETHUSDT", "market": "crypto" },
{ "symbol": "XAUUSD", "market": "commodity" }
],
"timeframe": "1d",
"period": "90d",
"format": "interactive"
}gainlab_wrb_scoring
{
"symbol": "BTCUSDT",
"market": "crypto",
"timeframe": "1d",
"limit": 200,
"lookback_period": 5,
"sensitivity": 1.5,
"gap_extension": "stopLoss",
"format": "interactive"
}基于HG_PRO系统检测宽范围条(WRB)和隐藏间隙(HG)。标记高质量的“Pro”设置。间隙扩展模式: none (严格间隙), stopLoss (延伸到WRB范围), both (全WRB范围)。
项目结构
src/
├── index.ts # MCP Server entry point (7 tools registered)
├── data/ # Data layer (one file per market)
│ ├── types.ts # Shared interfaces (OHLCV, FundamentalData)
│ ├── index.ts # Router (dispatches by market type)
│ ├── crypto.ts # Binance API
│ ├── us-stock.ts # FMP stable API
│ ├── a-stock.ts # EODHD (Shanghai/Shenzhen auto-detect)
│ ├── commodity.ts # EODHD FOREX (gold, silver)
│ └── screener.ts # EODHD screener + Binance 24hr for heatmap
├── render/ # Rendering layer
│ ├── engine.ts # ECharts → HTML or PNG
│ ├── themes.ts # GainLab dark theme
│ └── charts/ # Chart configs (one per tool)
│ ├── kline.ts
│ ├── indicators.ts # Dynamic multi-panel layout
│ ├── overlay.ts # Date alignment + normalization
│ ├── fundamentals.ts # Grouped bar + peer comparison
│ ├── volume-profile.ts # VP with POC/VAH/VAL markers
│ ├── sector-treemap.ts # Finviz-style treemap
│ ├── correlation-matrix.ts # Heatmap grid
│ ├── wrb-scoring.ts # WRB/HG K-line with gap overlays
│ ├── dcf-gauge.ts # DCF valuation semicircle gauge
│ └── analyst-estimates.ts # Actual vs forecast bars
├── tools/ # MCP tool definitions (one per tool)
│ ├── kline.ts
│ ├── indicators.ts
│ ├── overlay.ts
│ ├── fundamentals.ts # Standard + DCF + estimates modes
│ ├── volume-profile.ts
│ ├── heatmap.ts
│ └── wrb-scoring.ts
└── utils/
├── fetch.ts # Proxy-aware HTTP client
├── ta.ts # Technical indicators (MA/EMA/RSI/MACD/BOLL/KDJ/VWAP/ATR)
├── volume-profile.ts # Volume profile math (POC, Value Area)
├── wrb.ts # WRB/Hidden Gap detection (HG_PRO algorithm)
├── correlation.ts # Pearson correlation + returns
└── crypto-sectors.ts # 120+ token → sector classification设计原则:
- 每个市场=一个数据文件。每个工具=一个工具文件+一个图表文件。
ta.ts是纯粹的数学-没有API调用,没有导入,完全可测试。- 渲染引擎支持交互式HTML和服务器端PNG。
- 当API键丢失时,所有数据源都会正常降级。
建筑
┌─────────────────────────────────────────────────┐
│ AI Agent │
│ (Claude, ChatGPT, OpenClaw, custom) │
└──────────────────────┬──────────────────────────┘
│ MCP Protocol
┌──────────────────────▼──────────────────────────┐
│ @gainlab/mcp-server │
│ │
│ Tools ──→ Data Layer ──→ Render Layer ──→ Output│
│ (7 tools) (4 markets) (ECharts) (HTML/PNG)│
└──────────────────────────────────────────────────┘三层设计(无框架锁定):
- MCP服务器 --直接到Claude/ChatGPT← 当前的
- REST API --任何代理人都可以打电话(计划)
- @gainlab/反应 --可嵌入组件(计划中)
技术栈
| 组件 | 选择 |
|---|---|
| 运行时 | Node.js+TypeScript |
| MCP SDK | @modelcontextprotocol/SDK |
| 图表 | Apache ECharts |
| 服务器端渲染 | 节点画布 |
| 验证 | Zod |
| 包管理器 | pnpm |
测试
pnpm test # 275 tests across 57 suites测试涵盖:所有7个工具、所有4个数据市场、图表生成、技术指标(9种类型)、交易量概况数学、WRB/HG检测、相关性计算、加密行业分类、DCF指标、分析师估计、渲染引擎。
路线图
- \[x\] 第一阶段 --骨架+K线图(币安)
- \[x\] 第2阶段 --4个市场+指标+叠加+基本面
- \[x\] 第2.5a阶段 --体积分布图(POC/VAH/VAL)+VWAP/ATR
- \[x\] 第2.5b阶段 --行业热图+相关矩阵
- \[x\] 第2.5c阶段 --DCF估值+WRB_HG评分+基本面17个指标
- \[ \] 第三期 --npm发布+多市场演示+Smithery市场
许可证
Apache 2.0——请参阅 许可证
______________________________________________________________________
Built by Asher & 智慧卷卷 🦞
