使用说明
风力MCP
一个模型上下文协议服务器,使AI助手可以直接访问Wind金融终端数据。
Wind MCP通过 模型上下文协议。它暴露了 23个工具+1个资源 涵盖市场数据、基本面、宏观经济学、筛选、估计、投资组合管理和数据工具——所有这些都可以通过自然语言访问。
平台: 仅限Windows(WindPy是一个基于Windows COM的库)。
配套项目 彭博MCP同样的建筑,同样的哲学——但对于万得来说。
You: "拉一下贵州茅台过去20天的量价数据"
Claude: runs wind_historical with codes=600519.SH, fields=close,volume
→ Returns structured price/volume time series
You: "Find me A-share stocks with PE < 15 and ROE > 20%"
Claude: runs wind_dynamic_screen with universe=A-shares, filters, rank
→ Returns filtered and ranked stock list
建筑
graph TB
subgraph Clients
CC[Claude Code]
WC[Web Client]
CA[Custom App]
end
subgraph "Wind MCP Server"
direction TB
MCP["FastMCP Server<br/><i>23 tools + 1 resource</i>"]
subgraph Handlers["Handler Layer"]
direction LR
SNAP[Snapshot & Historical]
INTRA[Minute Bars & Ticks]
MACRO[Macro & Sector]
SCREEN[Screening]
EST[Estimates & Holders]
CAL[Calendar & Dates]
end
subgraph Core["Core Layer"]
direction LR
SESSION["WindSession<br/><i>Singleton + atexit</i>"]
CACHE["WindCache<br/><i>TTL-based</i>"]
PARSER["Parser<br/><i>12 parsers</i>"]
CONV["Converter<br/><i>BBG → Wind</i>"]
end
end
WIND["Wind Terminal<br/><i>WindPy (w.start)</i>"]
CC -- stdio --> MCP
WC -- HTTP/SSE --> MCP
CA -- HTTP/SSE --> MCP
MCP --> Handlers
Handlers --> Core
SESSION <--> WIND
style MCP fill:#1a73e8,stroke:#1557b0,color:#fff
style WIND fill:#e65100,stroke:#bf360c,color:#fff
style SESSION fill:#2e7d32,stroke:#1b5e20,color:#fff
style CACHE fill:#2e7d32,stroke:#1b5e20,color:#fff
工具概述(23个工具+1个资源)
graph LR
subgraph "Market Data (5)"
T1["wind_snapshot<br/><i>WSS current data</i>"]
T2["wind_historical<br/><i>WSD time series</i>"]
T3["wind_minute_bars<br/><i>WSI candles</i>"]
T4["wind_ticks<br/><i>WST raw ticks</i>"]
T5["wind_realtime<br/><i>WSQ live quotes</i>"]
end
subgraph "Fundamentals & Screening (5)"
T6["wind_dataset<br/><i>WSET tables</i>"]
T7["wind_screen<br/><i>WEQS screens</i>"]
T8["wind_dynamic_screen<br/><i>Custom filter + rank</i>"]
T9["wind_estimates<br/><i>Consensus</i>"]
T10["wind_holders<br/><i>Shareholding</i>"]
end
subgraph "Macro & Sector (3)"
T11["wind_macro<br/><i>EDB series</i>"]
T12["wind_sector_series<br/><i>WSES time series</i>"]
T13["wind_sector_snapshot<br/><i>WSEE snapshot</i>"]
end
subgraph "Connect & Calendar (2)"
T14["wind_stock_connect<br/><i>Northbound flows</i>"]
T15["wind_event_calendar<br/><i>IPO, earnings...</i>"]
end
subgraph "Composite & Portfolio (4)"
T16["wind_company_profile<br/><i>One-stop overview</i>"]
T17["wind_portfolio_report<br/><i>WPF reports</i>"]
T18["wind_portfolio_snapshot<br/><i>WPS holdings</i>"]
T19["wind_portfolio_series<br/><i>WPD time series</i>"]
end
subgraph "Date Utilities (3)"
T20["wind_trading_days<br/><i>TDAYS</i>"]
T21["wind_date_offset<br/><i>TDAYSOFFSET</i>"]
T22["wind_days_count<br/><i>TDAYSCOUNT</i>"]
end
subgraph "Observability (1 tool + 1 resource)"
T23["wind_metrics<br/><i>Server stats</i>"]
R1["wind://health<br/><i>Health check</i>"]
end
style T6 fill:#1a73e8,stroke:#1557b0,color:#fff
style T7 fill:#1a73e8,stroke:#1557b0,color:#fff
style T8 fill:#1a73e8,stroke:#1557b0,color:#fff
style T11 fill:#7b1fa2,stroke:#6a1b9a,color:#fff
style T12 fill:#7b1fa2,stroke:#6a1b9a,color:#fff
style T13 fill:#7b1fa2,stroke:#6a1b9a,color:#fff
style T16 fill:#00695c,stroke:#004d40,color:#fff
style T17 fill:#00695c,stroke:#004d40,color:#fff
style T18 fill:#00695c,stroke:#004d40,color:#fff
style T19 fill:#00695c,stroke:#004d40,color:#fff
style R1 fill:#546e7a,stroke:#37474f,color:#fff
主要特点
- 彭博→ Wind票务转换器 --接受彭博社样式标识符(
AAPL US Equity,700 HK Equity,601012 CH Equity)并自动转换为Wind代码(AAPL.O,00700.HK,601012.SH).涵盖美国、香港、日本、LN、CH股票、指数、大宗商品和货币。 - 模块化架构 --server.py是一个精简的入口点。处理程序、模型、格式化程序、解析器和转换器完全分离。
- 16个FieldSet快捷键 --扩展到风场助记符的预定义字段集合(价格、估值、盈利能力等)。
- 缓存层 --基于TTL的内存缓存,具有数据类型感知过期功能(实时30秒,静态24小时)。
- 12个WindPy解析器 --使用NaN处理WSS、WSD、WSI、WST、WSQ、WSET、EDB、WSES、WSEE、TDAYS、TDAYSOFFSET、TDAYSCOUNT→无清理和列到行转置。
- 动态筛选 --使用运算符(gt、lt、between、in、eq)+排名+切片进行自定义过滤,而不知道Wind助记符。
数据流
sequenceDiagram
participant Client as AI Assistant
participant MCP as MCP Server
participant Conv as Ticker Converter
participant Expand as Field Expander
participant Cache as Cache Layer
participant Session as WindSession
participant Wind as Wind Terminal
Client->>MCP: Tool call (JSON)
MCP->>Conv: Convert BBG → Wind codes
Conv-->>MCP: Wind codes
alt FieldSet shortcuts used
MCP->>Expand: Expand FieldSet shortcuts
Expand-->>MCP: Resolved field list
end
MCP->>Cache: Check cache
alt Cache hit
Cache-->>MCP: Cached result
else Cache miss
MCP->>Session: Call WindPy API
Session->>Wind: w.wsd() / w.wss() / ...
Wind-->>Session: WindData response
Session-->>MCP: Parsed dicts
MCP->>Cache: Store with TTL
end
alt Markdown format
MCP-->>Client: Formatted table
else JSON format
MCP-->>Client: Structured JSON
end
工具参考
市场数据
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_snapshot |
WSS | 任何安全的当前字段值 | codes, fields, trade_date |
wind_historical |
WSD | 具有可配置周期的时间序列 | codes, fields, begin_date, end_date |
wind_minute_bars |
WSI | OHLCV日内蜡烛(1/3/5/15/30/60分钟) | codes, fields, begin_time, end_time, bar_size |
wind_ticks |
WST | 原始分时交易数据 | codes, fields, begin_time, end_time |
wind_realtime |
WSQ | 直播报价 | codes, fields |
基础与筛选
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_dataset |
WSET | 结构化数据集(指数成员、IPO等) | table_name, options |
wind_screen |
WEQS | 执行已保存的Wind股票屏幕 | screen_name, options |
wind_dynamic_screen |
WSS | 自定义过滤器+排名+切片 | universe, fields, filters, rank_by, top_n |
wind_estimates |
WSS | 共识估计和目标价格 | codes, metrics, year |
wind_holders |
WSS/WSET | 顶级持有人、机构、基金持有量 | codes, holder_type, date |
宏观与行业
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_macro |
EDB | 宏观经济指标时间序列 | codes, begin_date, end_date |
wind_sector_series |
WSES | 部门级时间序列 | codes, fields, begin_date, end_date |
wind_sector_snapshot |
WSEE | 扇区级当前快照 | codes, fields, trade_date |
沪港通和日历
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_stock_connect |
WSET/WSS | 北向/南向流量数据 | codes, direction, date |
wind_event_calendar |
WSET | IPO、收益、股息日历 | event_type, begin_date, end_date |
综合与投资组合
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_company_profile |
WSS+WSD | 一站式公司概述(快照+估计+价格历史) | codes |
wind_portfolio_report |
WPF | 投资组合绩效/归因/风险报告 | product_name, table_name, options |
wind_portfolio_snapshot |
WPS | 投资组合资产净值、持有量、权重、PnL | portfolio_name, fields, options |
wind_portfolio_series |
WPD | 投资组合业绩时间序列 | portfolio_name, fields, begin_date |
可观测性
| 工具 | 类型 | 描述 |
|---|---|---|
wind_metrics |
工具 | 服务器指标:工具调用计数、延迟、缓存命中率、正常运行时间 |
wind://health |
资源 | 风连接和缓存运行状况 |
日期实用程序
| 工具 | WindPy API | 描述 | 关键参数 |
|---|---|---|---|
wind_trading_days |
TDAYS | 列出一定范围内的交易日 | begin_date, end_date, calendar |
wind_date_offset |
TDAYSOFFSET | 将日期偏移N个交易日 | date, offset, calendar |
wind_days_count |
TDAYSCOUNT | 计算两个日期之间的交易日 | begin_date, end_date, calendar |
所有工具支持 response_format: "markdown" (默认)或 "json".
字段集快捷方式
不要记住风场助记符,而是使用扩展到多个场的简写名称。
| 字段集 | 字段 | 关键风助记符 |
|---|---|---|
PRICE |
5 | 关闭、打开、高、低、pct_chg |
MOMENTUM |
4 | pct_chg、pct_chg_5d、pct_ch4g_1m、pct_ching-ytd |
VOLUME_PROFILE |
4 | 音量、amt、转弯、自由转弯 |
VALUATION |
5 | pe_ttm、pb_lf、ps_ttm、pcf_ocf_ttm、ev2_to_ebitda |
VALUATION_EXTENDED |
9 | +pe_est,除数_收益率,总计_mkt_cap,ev |
PROFITABILITY |
6 | roe_tm、roa_tm、毛利润率、净利润率、营业利润率、投资回报率 |
GROWTH |
4 | yoyprofit,yoyrevidence,yoyocf,qfa_yoygr |
BALANCE_SHEET |
6 | 债务与资产、流动比率、快速比率、现金流与债务、长期债务与债务、权益比率 |
CASH_FLOW |
5 | ocfps、fcf、cf_from_ops、资本支出、股息 |
TECHNICAL |
5 | rsi,macd,vol_20d,beta_100w,atr_14d |
ANALYST |
4 | rating_avg、est_target_price、est_eps_y1、est_net_profit_fy1 |
ESTIMATE_REVISIONS .4.est_eps_chg_4w、est_eps-chg_13w、est_num_up、est_nom_down。 |
||
SECTOR |
2 | 工业_sw,工业_sw_lv2 |
NORTHBOUND |
4 | sh_hk_share_pct、sh_hk_share_chg、sh_hk/share_amt、sh_hk-share_rank |
MARGIN |
3 | 买入保证金、卖出保证金、净保证金 |
RISK |
5 | beta_100w,波动性_20d,波动性_60d,锐化_20d |
SCREENING_FULL |
50+ | 以上所有加起来 |
彭博→ 风票转换
Wind MCP会自动将彭博风格标识符转换为Wind代码:
| 彭博格式 | 风代码 | 市场 |
|---|---|---|
AAPL US Equity |
AAPL.O |
美国(纳斯达克) |
JPM US Equity |
JPM.N |
美国(纽约证券交易所) |
700 HK Equity |
00700.HK |
香港 |
7203 JP Equity |
7203.T |
日本 |
VOD LN Equity |
VOD.L |
伦敦 |
601012 CH Equity |
601012.SH |
A股(上海) |
000001 CH Equity |
000001.SZ |
A股(深圳) |
300750 CH Equity |
300750.SZ |
A股(创业板) |
SPX Index |
SPX.GI |
索引 |
HSI Index |
HSI.HI |
索引 |
CL1 Comdty |
CL.NYM |
商品 |
EURUSD Curncy |
EURUSD.FX |
货币 |
600519.SH |
600519.SH |
穿越(已经是风) |
动态筛选
使用预先验证的字段集、过滤器和排名构建自定义屏幕——不需要知道Wind字段助记符。
flowchart LR
A["Universe<br/><i>index, sector,<br/>or ticker list</i>"] --> B["Field Expansion<br/><i>FieldSet shortcuts<br/>→ Wind fields</i>"]
B --> C["Wind API<br/><i>WSS request</i>"]
C --> D["Filter<br/><i>gt, lt, between,<br/>in, eq, ...</i>"]
D --> E["Rank & Slice<br/><i>rank_by + top_n</i>"]
E --> F["Response<br/><i>Markdown table<br/>or JSON</i>"]
style A fill:#e8f5e9,stroke:#2e7d32
style C fill:#fff3e0,stroke:#ff6f00
style F fill:#e3f2fd,stroke:#1a73e8
过滤器操作员
| 操作员 | 描述 | 示例 |
|---|---|---|
gt / gte |
大于(或等于) | {"field": "roe_ttm", "op": "gt", "value": 20} |
lt / lte |
小于(或等于) | {"field": "pe_ttm", "op": "lt", "value": 15} |
eq / neq |
等于/不等于 | {"field": "industry_sw", "op": "eq", "value": "电子"} |
between |
范围(含) | {"field": "pe_ttm", "op": "between", "value": [10, 25]} |
in |
列表中的值 | {"field": "industry_sw", "op": "in", "value": ["电子", "计算机"]} |
示例:查找被低估的高净资产收益率A股
{
"universe": "sector:全部A股",
"fields": ["PRICE", "VALUATION", "PROFITABILITY"],
"filters": [
{"field": "pe_ttm", "op": "lt", "value": 15},
{"field": "roe_ttm", "op": "gt", "value": 20}
],
"rank_by": "roe_ttm",
"rank_descending": true,
"top_n": 20
}
缓存层
内置缓存通过数据类型感知的TTL减少了Wind API的负载:
| 数据类型 | 默认TTL | 基本原理 |
|---|---|---|
| 实时报价(WSQ) | 30秒 | 近乎实时 |
| 快照(WSS) | 5分钟 | 中等刷新 |
| 分钟条(WSI) | 5分钟 | 日内刷新 |
| 滴答声(WST) | 1分钟 | 高频 |
| 作品集(WPF/WPS/WPD) | 5分钟 | 适度刷新 |
| 放映(WEQS) | 10分钟 | 适度刷新 |
| 估计 | 4小时 | 共识更新不频繁 |
| 历史(WSD) | 12小时 | 日终数据稳定 |
| 宏观数据(EDB) | 24小时 | 定期更新 |
| 数据集(WSET) | 24小时 | 参考数据 |
| 部门(WSES/WSEE) | 24小时 | 很少变化 |
| 持有人/日期 | 24小时 | 很少更改 |
所有TTL均可通过以下方式配置 wind_mcp.toml 或环境变量。看 配置.
配置
服务器行为可以通过以下方式定制 wind_mcp.toml 在项目根中。所有值也可以通过带有前缀的环境变量进行覆盖 WIND_MCP_ (例如。, WIND_MCP_CACHE_MAXSIZE=5000).
[session]
connect_timeout = 30 # Seconds to wait for Wind connection
reconnect_retries = 3 # Auto-reconnect attempts
reconnect_backoff = 1.0 # Backoff multiplier between retries
[cache]
maxsize = 2000 # Max cached entries (LRU eviction)
ttl_realtime = 30 # WSQ — near real-time
ttl_snapshot = 300 # WSS — 5 min
ttl_historical = 43200 # WSD — 12 hours
ttl_dataset = 86400 # WSET — 24 hours
ttl_macro = 86400 # EDB — 24 hours
ttl_portfolio = 300 # WPF/WPS/WPD — 5 min
[api]
timeout = 30.0 # Per-call timeout (seconds)
retries = 2 # Retry count on transient errors
backoff = 1.0 # Backoff multiplier
[log]
format = "text" # "json" or "text"
level = "INFO"
项目结构
wind-mcp/
├── pyproject.toml
├── README.md
├── LICENSE
├── wind_mcp.toml # Server configuration (cache TTL, timeouts, retries)
├── run_server.bat / run_server.ps1
├── src/wind_mcp/
│ ├── __init__.py
│ ├── __main__.py
│ ├── server.py # FastMCP entry point, 23 tools + 1 resource
│ ├── formatters.py # Markdown table & JSON output
│ ├── core/
│ │ ├── session.py # WindSession singleton + reconnect
│ │ ├── cache.py # TTL cache with LRU eviction
│ │ ├── parser.py # 12 WindData parsers
│ │ ├── converter.py # Bloomberg → Wind ticker converter
│ │ ├── executor.py # Single-thread executor for Wind API calls
│ │ ├── validators.py # Input validation (codes, dates, fields)
│ │ ├── resilience.py # Timeout, retry, stale-cache fallback
│ │ ├── config.py # Centralized config (env > toml > defaults)
│ │ ├── metrics.py # Counters + histograms for observability
│ │ ├── universe.py # Universe resolution (index/sector → security list)
│ │ └── filters.py # In-memory data filtering (gt/lt/between/in/...)
│ ├── models/
│ │ ├── enums.py # ResponseFormat, Periodicity, etc.
│ │ └── inputs.py # Pydantic input models
│ ├── tools/
│ │ ├── fieldsets.py # 16 FieldSet definitions
│ │ └── field_expander.py # FieldSet → field list resolver
│ ├── handlers/ # 16 handler modules
│ │ ├── snapshot.py # WSS
│ │ ├── historical.py # WSD
│ │ ├── minute_bars.py # WSI
│ │ ├── ticks.py # WST
│ │ ├── realtime.py # WSQ
│ │ ├── dataset.py # WSET
│ │ ├── macro.py # EDB
│ │ ├── sector.py # WSES / WSEE
│ │ ├── screening.py # WEQS + dynamic screen
│ │ ├── estimates.py # Consensus estimates
│ │ ├── holders.py # Holder analysis
│ │ ├── stock_connect.py # Northbound/Southbound
│ │ ├── calendar.py # Event calendar
│ │ ├── dates.py # TDAYS / TDAYSOFFSET / TDAYSCOUNT
│ │ ├── composite.py # Company profile (multi-source)
│ │ └── portfolio.py # WPF / WPS / WPD portfolio tools
│ └── data/ # Static mapping files
│ ├── us_exchange_map.json # ~200 US tickers → exchange
│ ├── index_map.json # BBG → Wind index mapping
│ ├── commodity_map.json # BBG → Wind commodity mapping
│ └── currency_map.json # BBG → Wind currency mapping
├── tests/ # 101 unit tests (no Wind needed)
│ ├── test_parser.py
│ ├── test_fieldsets.py
│ ├── test_cache.py
│ ├── test_config.py
│ ├── test_converter.py
│ ├── test_filters.py
│ ├── test_formatters.py
│ ├── test_inputs.py
│ ├── test_metrics.py
│ ├── test_resilience.py
│ └── test_validators.py
└── examples/
├── basic_usage.py
└── screening_example.py
安装
先决条件
- 视窗 (WindPy是一个基于Windows COM的库)
- Python 3.10+(必须与Wind Terminal位匹配,通常为64位)
- 万得Wind金融终端正在运行并已登录 (iWind或WFT)
- WindPy --通过风力发电站安装,而不是通过管道安装。开放式风力发电站→ 单击“修复”或从“工具”菜单安装WindPy插件。
验证WindPy
在安装Wind MCP之前,请验证WindPy是否在Python环境中工作:
python -c "from WindPy import w; w.start(); print(w.isconnected())"
# Should print: True
如果返回 False 或错误,请先修复您的WindPy安装。常见问题:
- 风力终端未运行/未登录
- Python位不匹配(例如,32位Python与64位Wind)
- 未安装WindPy(通过风力发电站进行维修)
安装
# From source
git clone https://github.com/QmQsun/Wind-MCP.git
cd Wind-MCP
pip install . # standard install
# or: pip install -e . # editable mode (for development)
# Or from PyPI
pip install wind-mcp
配置Claude代码
添加一个 .mcp.json 文件以注册MCP服务器。两种选择:
全球 (所有项目都可以使用Wind MCP)--地点 ~/.mcp.json (即。, C:\Users\<you>\.mcp.json):
{
"mcpServers": {
"wind-mcp": {
"command": "wind-mcp",
"args": []
}
}
}
项目级别 (只有一个项目)--地点 .mcp.json 在项目根目录中。
这个
wind-mcpcommand是pip安装的控制台入口点。或者,使用"command": "python", "args": ["-m", "wind_mcp.server"].
快速开始
作为MCP服务器
# stdio (default — for Claude Code)
python -m wind_mcp.server
# HTTP transport (for web clients)
python -m wind_mcp.server --http --port=8080
# SSE transport (for streaming clients)
python -m wind_mcp.server --sse --port=8080
视窗
# Command Prompt
run_server.bat
# PowerShell
.\run_server.ps1
风API覆盖范围
graph LR
subgraph "Wind Terminal (WindPy)"
WSS["WSS<br/><i>Snapshot</i>"]
WSD["WSD<br/><i>Historical</i>"]
WSI["WSI<br/><i>Minute bars</i>"]
WST["WST<br/><i>Tick data</i>"]
WSQ["WSQ<br/><i>Realtime</i>"]
WSET["WSET<br/><i>Datasets</i>"]
EDB["EDB<br/><i>Macro</i>"]
WSES["WSES<br/><i>Sector series</i>"]
WSEE["WSEE<br/><i>Sector snapshot</i>"]
WEQS["WEQS<br/><i>Stock screener</i>"]
TDAYS["TDAYS<br/><i>Trading days</i>"]
end
WSS --- T1[Snapshot + Estimates + Holders + Screen]
WSD --- T2[Historical Time Series]
WSI --- T3[Intraday Bars]
WST --- T4[Tick Data]
WSQ --- T5[Realtime Quotes]
WSET --- T6[Datasets + Connect + Calendar]
EDB --- T7[Macro Indicators]
WSES --- T8[Sector Time Series]
WSEE --- T9[Sector Snapshot]
WEQS --- T10[Saved Screens]
TDAYS --- T11[Date Utilities]
style WSS fill:#1a73e8,stroke:#1557b0,color:#fff
style WSD fill:#1a73e8,stroke:#1557b0,color:#fff
style EDB fill:#7b1fa2,stroke:#6a1b9a,color:#fff
style WEQS fill:#e65100,stroke:#bf360c,color:#fff
贡献
欢迎投稿!请打开问题或提交拉取请求。
pip install -e ".[dev]"
pytest # Unit tests (no Wind Terminal needed)
black src/ tests/
ruff check src/ tests/
相关项目
- 彭博MCP --彭博终端的架构相同
许可证
麻省理工学院——见 许可证 了解详情。