trading-mcp
Supports formatting trading data, technical indicators, and fundamental reports into Markdown tables and text for human-readable output.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@trading-mcpShow me the MACD and last 50 candlesticks for symbol 000001"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
trading-mcp
An MCP service for trading data and technical indicators, built with uv + pydantic + akshare + TA-Lib.
Project Content
Provides stock market data queries and basic technical indicator calculations (K-line, RSI, MA, MACD).
Provides medium-to-long-term fundamental data queries (A-share key indicators, US stock three major financial statements, US stock key indicators).
Unified market data access layer, supporting A-shares and US stocks (e.g.,
AAPL.US).MCP tool-based interface, supporting Markdown or JSON output.
Project Architecture
data/: Market data access layer.MarketDataClientinterface +AkshareMarketDataClientimplementation.services/: Business service layer. Converts raw market data into standard structures and drives indicator calculations.indicators/: Indicator engine encapsulation. Unified calls based on TA-Lib.models/: Tool request and response models (Pydantic).utils/: MCP output formatting (Markdown tables, etc.).mcp_app.py/main.py: MCP service entry point and tool registration.
Directory Structure
config/: Configuration definitions (Pydantic Settings).data/: Market data client implementation.indicators/: Indicator calculation engine.models/: Request/response models.services/: Business service layer.tests/: Unit tests.utils/: Output formatting and helper tools.mcp_app.py: MCP tool registration.main.py: Service startup entry point.
Installation and Dependencies
Install dependencies:
uv sync --extra devInstall TA-Lib system library:
macOS:
brew install ta-libDebian/Ubuntu:
sudo apt-get install libta-lib0 libta-lib0-devWindows: Use the pre-compiled wheel for your Python version
Configuration
Configuration is overridden via environment variables with the TRADING_MCP_ prefix:
export TRADING_MCP_ENVIRONMENT=dev
export TRADING_MCP_DATA_DIR=./data
export TRADING_MCP_DEFAULT_SYMBOL=000001
export TRADING_MCP_HOST=0.0.0.0
export TRADING_MCP_PORT=8000
export TRADING_MCP_AKSHARE_PROXY_ENABLED=true
export TRADING_MCP_AKSHARE_PROXY_AUTH_IP=***
export TRADING_MCP_AKSHARE_PROXY_AUTH_TOKEN=*** TRADING_MCP_AKSHARE_PROXY_RETRY=30Field meanings:
TRADING_MCP_ENVIRONMENT: Runtime environment identifier (e.g.,dev/test/prod).TRADING_MCP_DATA_DIR: Local data directory.TRADING_MCP_DEFAULT_SYMBOL: Default market ticker.TRADING_MCP_HOST: MCP service listening address.TRADING_MCP_PORT: MCP service port.TRADING_MCP_AKSHARE_PROXY_ENABLED: Whether to enableakshare-proxy-patch.TRADING_MCP_AKSHARE_PROXY_AUTH_IP:akshare-proxy-patchauthorization gateway IP; patch will not be installed if not configured.TRADING_MCP_AKSHARE_PROXY_AUTH_TOKEN: Optional authorization token.TRADING_MCP_AKSHARE_PROXY_RETRY: Internal retry count for the patch.
East Money Anti-Scraping Proxy Notes:
The project includes
akshare-proxy-patch, which automatically attempts to install when importing data/akshare_client.py.It is only enabled when
TRADING_MCP_AKSHARE_PROXY_AUTH_IPis configured andTRADING_MCP_AKSHARE_PROXY_ENABLED=true.The patch only hooks requests to East Money-related domains and does not affect other non-target sites.
Python Usage
from trading_mcp.config import Settings
from trading_mcp.data import AkshareMarketDataClient
from trading_mcp.indicators import IndicatorEngine
settings = Settings(environment="dev", data_dir="./data", default_symbol="000001")
client = AkshareMarketDataClient()
frame = client.fetch(settings.default_symbol, "2024-01-01", "2024-02-01")
engine = IndicatorEngine()
close_series = frame["close"] if "close" in frame.columns else frame.iloc[:, 0]
result = engine.compute("sma", close_series, timeperiod=5)
print(result.tail())MCP Service Start the MCP service (streamable HTTP):
python main.pyStart the MCP Inspector (adapted for WSL, accessible from the host machine):
./dev.shBy default, the following Inspector configuration is used:
MCP_INSPECTOR_HOST=0.0.0.0MCP_INSPECTOR_CLIENT_PORT=6274MCP_INSPECTOR_SERVER_PORT=6277MCP_INSPECTOR_AUTO_OPEN=false
Access primarily from the Windows host browser:
http://localhost:6274If WSL localhost forwarding is not enabled on your machine, you can run hostname -I inside WSL to find the IP, then access http://<wsl-ip>:6274 from the host.
If you only want to access it from the local Linux environment, you can override it to:
MCP_INSPECTOR_HOST=127.0.0.1 ./dev.shNote: The Inspector proxy has the capability to start local processes. 0.0.0.0 should only be used in trusted network environments.
Available Tools:
trading_kline(symbol, limit=30, offset=0, period_type="1d", start_date=None, end_date=None, response_format="markdown")trading_macd(symbol, limit=30, fast_period=12, slow_period=26, signal_period=9, offset=0, period_type="1d", start_date=None, end_date=None, response_format="markdown")trading_rsi(symbol, limit=30, period=14, offset=0, period_type="1d", start_date=None, end_date=None, response_format="markdown")trading_ma(symbol, limit=30, period=20, ma_type="sma", offset=0, period_type="1d", start_date=None, end_date=None, response_format="markdown")trading_volume(symbol, limit=30, offset=0, period_type="1d", start_date=None, end_date=None, response_format="markdown")trading_fund_flow_individual_em(symbol, limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_fund_flow_individual_rank_em(indicator="5日", limit=30, offset=0, response_format="markdown")trading_fund_flow_sector_rank_em(indicator="今日", sector_type="行业资金流", sort_by="主力净流入", limit=30, offset=0, response_format="markdown")trading_fund_flow_sector_summary_em(symbol, indicator="今日", limit=30, offset=0, response_format="markdown")trading_fundamental_cn_indicators(symbol, indicator="按报告期", limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_fundamental_us_report(stock, symbol="资产负债表", indicator="年报", limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_fundamental_us_indicators(symbol, indicator="年报", limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_industry_summary_ths(limit=30, offset=0, response_format="markdown")trading_industry_index_ths(symbol, limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_industry_name_em(limit=30, offset=0, response_format="markdown")trading_board_change_em(limit=30, offset=0, response_format="markdown")trading_industry_spot_em(symbol, limit=30, offset=0, response_format="markdown")trading_industry_cons_em(symbol, limit=30, offset=0, response_format="markdown")trading_industry_hist_em(symbol, period="日k", adjust="none", limit=30, offset=0, start_date=None, end_date=None, response_format="markdown")trading_industry_hist_min_em(symbol, period="5", limit=30, offset=0, response_format="markdown")trading_info_global_em(limit=30, offset=0, response_format="markdown")
trading_fundamental_cn_indicators Parameter Notes:
indicatorenum:按报告期,按单季度symbolcompatible inputs:000001,000001.SZ,600519.SH(auto-completion or normalized suffix)Fundamental results returned in raw row format:
columns + items
trading_fundamental_us_report Parameter Notes:
symbol(report type) enum:资产负债表,综合损益表,现金流量表indicator(report period) enum:年报,单季报,累计季报stockcompatible inputs:TSLA,AAPL.US,105.AAPL,BRK.B(internally normalized to AkShare-recognizable ticker)
trading_fundamental_us_indicators Parameter Notes:
indicatorenum:年报,单季报,累计季报symbolcompatible inputs:TSLA,AAPL.US,105.AAPL,BRK.BFundamental results returned in raw row format:
columns + items
trading_volume Field Notes:
Returned fields:
timestamp,volume,amount,turnover_rateUnit strategy: Retain original data source units and return units via response fields
A-shares:
volume_unit=lot,amount_unit=CNYUS stocks:
volume_unit=share,amount_unit=USDturnover_rate_unit=percent
When weekly/monthly data is aggregated from daily lines,
turnover_ratemay benull
Fund Flow Tool Notes:
trading_fund_flow_individual_em: East Money individual stock fund flow,symbolsupports000001,600519.SH,830799.BJtrading_fund_flow_individual_rank_em: East Money individual stock fund flow rankingindicatorenum:今日,3日,5日,10日
trading_fund_flow_sector_rank_em: East Money sector fund flow rankingindicatorenum:今日,5日,10日sector_typeenum:行业资金流,概念资金流,地域资金流sort_byenum:涨跌幅,主力净流入; defaults to descending order by主力净流入
When East Money ranking interface is unavailable:
Individual stock ranking falls back to Tonghuashun individual stock fund flow ranking
Industry/Concept sector ranking falls back to corresponding Tonghuashun ranking
Returned columns after fallback may differ from original East Money columns;
地域资金流does not fall back
trading_fund_flow_sector_summary_em: Fund flow for constituent stocks of a specified sectorDefaults to East Money, falls back to Tonghuashun on failure
symbolis the sector name, e.g.,电源设备,风电设备indicatorenum:今日,5日,10日Returned columns after fallback may differ from original East Money columns
Fund flow results are uniformly returned as raw tables:
columns + items
Symbol Notes:
A-share examples:
000001,300308.SZUS stock examples:
AAPL.US,AAPL,105.AAPL,BRK.B
Industry Sector Tool Notes:
trading_industry_summary_ths: Tonghuashun industry overview table, returns original sector summary fieldstrading_industry_index_ths: Tonghuashun industry index,symbolis sector name, supportsstart_date/end_datetrading_industry_name_em: East Money industry sector name listtrading_board_change_em: East Money daily sector movement detailstrading_industry_spot_em: East Money industry sector real-time quotes,symbolis sector nametrading_industry_cons_em: East Money industry sector constituent stocks,symbolis sector nametrading_industry_hist_em: East Money industry sector historical quotesperiodenum:日k,周k,月kadjustenum:none,qfq,hfq; wherenonemeans no adjustment
trading_industry_hist_min_em: East Money industry sector historical intraday quotesperiodenum:1,5,15,30,60
Industry sector results are uniformly returned as raw tables:
columns + items
News Tool Notes:
trading_info_global_em: East Money global financial news flashNews results are uniformly returned as raw tables:
columns + items
Response Structure (structuredContent)
{
"stock": "TSLA",
"symbol": "资产负债表",
"indicator": "年报",
"columns": ["REPORT_DATE", "ITEM_NAME", "AMOUNT"],
"items": [],
"count": 0,
"total": 0,
"limit": 30,
"offset": 0,
"has_more": false,
"next_offset": null,
"start_date": null,
"end_date": null
}MCP Data Interaction Flow (Architecture and Sequence Diagram)
Below is a Mermaid diagram of the current MCP's main data interaction architecture and sequence, helping to understand the flow of requests within the system.
Architecture (Flowchart)
flowchart LR
Client[Client / User] -->|HTTP/Stream 请求| MCP[MCP Server]
MCP -->|调用工具接口| API[Tool Dispatcher / Handlers]
API --> Market[MarketDataClient (Akshare / Providers)]
Market -->|行情数据| Storage[Local Cache / Data Dir]
API --> Indicator[IndicatorEngine (TA-Lib)]
Indicator -->|指标结果| Formatter[Response Formatter (Markdown / JSON)]
Formatter -->|返回| Client
Market -.->|必要时| Proxy[akshare-proxy-patch]
MCP -->|注册 & 管理| Inspector[MCP Inspector]Notes:
MCP Server: Receives external requests (HTTP/stream), responsible for parsing requests and calling internal tools.
Tool Dispatcher: Routes requests to specific tools (e.g., trading_kline, trading_macd).
MarketDataClient: Unified market data access layer, currently implemented mainly via Akshare, supports proxy patch.
IndicatorEngine: Calls TA-Lib or built-in algorithms to calculate technical indicators.
Response Formatter: Converts structured data into Markdown or JSON MCP response formats.
Local Cache/Storage: Used for short-term caching and historical data storage to reduce API calls.
Sequence Diagram
sequenceDiagram
participant U as Client/User
participant M as MCP Server
participant D as Tool Dispatcher
participant MD as MarketDataClient
participant I as IndicatorEngine
participant F as Formatter
U->>M: 发起 trading_macd 请求 (symbol, start, end, params)
M->>D: 解析并转发请求
D->>MD: 请求历史 K 线 (symbol, start, end)
MD-->>D: 返回原始行情数据 (OHLCV)
D->>I: 传入行情数据与参数, 调用指标计算
I-->>D: 返回指标结果 (MACD lines, histogram)
D->>F: 格式化为 Markdown / JSON 的 MCP 响应
F-->>M: 返回格式化结果
M-->>U: 通过 HTTP Stream 返回响应 (chunked / 完整)
alt 缓存命中
D->>Storage: 读取缓存
Storage-->>D: 返回缓存数据
end
alt 第三方被阻断/需要代理
MD->>Proxy: 走 akshare-proxy-patch
Proxy-->>MD: 返回代理后的数据
endThe two diagrams above are abstract views of the current system; if you would like to refine the diagrams with more components (e.g., authentication, rate limiting, queues, asynchronous tasks, monitoring metrics), let me know which parts you need to add, and I can expand and update the Mermaid diagrams in the README.
If you confirm that this update is acceptable, I will commit the changes to a new branch and push it, then create a Pull Request for your review.
This server cannot be deployed
Maintenance
Related MCP Connectors
China A-share market data for research, backtesting and AI agents via MCP.
China A-share market data over MCP: 22 tools for quotes, K-line, financials, money flow, top-trader boards, sectors, macro, convertible bonds and factor screening. Five tools need no API key, so you can connect and try it immediately.
MCP server giving AI agents one-connection access to China A-share market intelligence: financials,
Market Data App MCP — wraps the Market Data App API (marketdata.app)
Related MCP Servers
- AlicenseCqualityDmaintenanceProvides technical analysis indicators like SMA, EMA, RSI, MACD, Bollinger Bands, and Stochastic through MCP, enabling AI assistants to perform financial market analysis and calculations on price data.187MIT
- FlicenseNot gradedqualityDmaintenanceProvides stock market data and computes technical indicators like EMA, MACD, and RSI across multiple timeframes using the LongPort API and TA-Lib. It enables users to perform detailed financial analysis and multi-timeframe market reviews through standard MCP tools.-
- FlicenseNot gradedqualityFmaintenanceProvides AI clients access to TdxQuant/通达信 financial data and trading capabilities through MCP. Enables retrieval of market data, financial reports, sector information, and trading operations via stdio or HTTP/SSE connections.29-
- AlicenseBqualityCmaintenanceMCP server that wraps AKShare's 1000+ financial data functions, enabling LLMs to query Chinese stock, macro, futures, fund, bond, option, forex, and alternative data through standardized tools.143Apache 2.0