A Share MCP
This server provides comprehensive data and analysis capabilities for the Chinese A-share market, including:
Historical Market Data: Fetch daily, weekly, monthly, or minute-level K-line data with various adjustment options
Basic Stock Information: Access fundamental details, listing dates, industry classifications
Dividend & Adjustment Data: Retrieve historical dividends and price adjustment factors
Financial Reports: Query detailed quarterly metrics for profitability, operations, growth, balance sheets, cash flow, and DuPont analysis
Performance Data: Access performance express and forecast reports
Index Information: Get constituent stocks for SZSE 50, CSI 300, and CSI 500 indices
Macroeconomic Indicators: Retrieve deposit/loan rates, reserve ratios, money supply data, and SHIBOR rates
Trading Dates & Utilities: Check trading calendars, current/latest trading dates, and market analysis timeframes
Stock Analysis Tools: Generate data-driven fundamental and technical analysis reports
Provides stock market data analysis tools for A-share markets through data accessed via Baostock, offering historical K-line data, financial reports, market indices, and macroeconomic indicators.
📊 a-share-mcp 📈
本项目是一个基于专注于 A 股市场的 MCP 服务器,它提供股票基本信息、历史 K 线数据、财务指标、宏观经济数据等多种查询功能,理论上来说,可以回答有关 A 股市场的任何问题,无论是针对大盘还是特定股票。
项目结构
a_share_mcp/
│
├── mcp_server.py # 主服务器入口文件
├── pyproject.toml # 项目依赖配置
├── README.md # 项目说明文档
│
├── src/ # 源代码目录
│ ├── __init__.py
│ ├── baostock_data_source.py # Baostock数据源实现
│ ├── data_source_interface.py # 数据源接口定义
│ ├── utils.py # 通用工具函数
│ │
│ ├── formatting/ # 数据格式化模块
│ │ ├── __init__.py
│ │ └── markdown_formatter.py # Markdown格式化工具
│ │
│ └── tools/ # MCP工具模块
│ ├── __init__.py
│ ├── base.py # 基础工具函数
│ ├── stock_market.py # 股票市场数据工具
│ ├── financial_reports.py # 财务报表工具
│ ├── indices.py # 指数相关工具
│ ├── market_overview.py # 市场概览工具
│ ├── macroeconomic.py # 宏观经济数据工具
│ ├── date_utils.py # 日期工具
│ └── analysis.py # 分析工具
│
└── resource/ # 资源文件
└── img/ # 图片资源
├── img_1.png # CherryStudio配置示例
└── img_2.png # CherryStudio配置示例Related MCP server: Tushare MCP Server
功能特点
先决条件
Python 环境: Python 3.10+
依赖管理: 使用
uv包管理器安装依赖数据来源: 基于 Baostock 数据源,无需付费账号。在此感谢 Baostock。
提醒:本项目于 Windows 环境下开发。
数据更新时间
以下是 Baostock 官方数据更新时间,请注意查询最新数据时的时间点 Baostock 官网
每日数据更新时间:
当前交易日 17:30,完成日 K 线数据入库
当前交易日 18:00,完成复权因子数据入库
第二自然日 11:00,完成分钟 K 线数据入库
第二自然日 1:30,完成前交易日"其它财务报告数据"入库
周六 17:30,完成周线数据入库
每周数据更新时间:
每周一下午,完成上证 50 成份股、沪深 300 成份股、中证 500 成份股信息数据入库
所以说,在交易日的当天,如果是在 17:30 之前询问当天的数据,是无法获取到的。
安装环境
在项目根目录下执行:
要启动 A 股 MCP 服务器,请按照以下步骤操作:
# 1. 创建虚拟环境(仅创建,不会安装任何包)
uv venv
# 2. 激活虚拟环境
# Windows
.venv\Scripts\activate
# macOS/Linux
# source .venv/bin/activate
# 3. 安装所有依赖(必须在激活的虚拟环境中执行)
uv sync使用:在 MCP 客户端中配置服务器
在支持 MCP 的客户端(如 VS Code 插件、CherryStudio 等)中,你需要配置如何启动此服务器。 推荐使用 uv。
方法一:使用 JSON 配置的 IDE (例如 Cursor、VSCode、Trae 等)
对于需要编辑 JSON 文件来配置 MCP 服务器的客户端,你需要找到对应的能配置 MCP 的地方(各个 IDE 和桌面 MCP Client 可能都不一样),并在 mcpServers 对象中添加一个新的条目。
JSON 配置示例 (请将路径替换为你的实际绝对路径):
{
"mcpServers": {
"a-share-mcp": {
"command": "uv", // 或者 uv.exe 的绝对路径, 例如: "C:\\path\\to\\uv.exe"
"args": [
"--directory",
"C:\\Users\\YourName\\Projects\\a_share_mcp", // 替换为你的项目根目录绝对路径,不一定是C盘,按实际的填写
"run",
"python",
"mcp_server.py"
],
"transport": "stdio"
// "workingDirectory": "C:\\Users\\YourName\\Projects\\a_share_mcp", // 使用 uv --directory 后,此项可能不再必需,但建议保留作为备用
}
// ... other servers ...
}
}注意事项:
command: 确保填写的uv命令或uv.exe的绝对路径是客户端可以访问和执行的。args: 确保参数列表完整且顺序正确。路径转义: 路径需要写成双反斜杠
\\。这是 Windows 系统特有的情况。如果是在 macOS 或 Linux 系统中,路径使用正斜杠/作为目录分隔符,就不需要这种转义处理。
workingDirectory: 虽然uv --directory应该能解决工作目录问题,但如果客户端仍然报错ModuleNotFoundError,可以尝试在客户端配置中明确设置此项为项目根目录的绝对路径。
方法二:使用 CherryStudio
在 CherryStudio 的 MCP 服务器配置界面中,按如下方式填写:
名称:
a-share-mcp(或自定义)描述:
本地 A 股 MCP 服务器(或自定义)类型: 选择 标准输入/输出 (stdio)
命令:
uv(或者填系统中绝对路径下 uv.exe)包管理源: 默认
参数:
第一个参数填:
--directory第二个参数填:
C:\\Users\\YourName\\Projects\\a_share_mcp第三个参数填:
run第四个参数填:
python第五个参数填:
mcp_server.py
确保所有参数按下回车转行隔开的,否则报错(是不是手把手教学了?)
环境变量: (通常留空)
Tricks(必看): 有时候在 Cherrystudio 填写好参数后,点击右上方的开关按钮,会发现没任何反应,此时只要随便点击左侧目录任一按钮,跳出 mcp 设置界面,然后再回到 mcp 设置界面,就会发现 mcp 已经闪绿灯配置成功了。
CherryStudio 使用示例: 理论上来说,你可以问有关 A 股的任何问题 :)


重要提示:
确保命令字段中的
uv或其绝对路径有效且可执行。确保参数字段按顺序正确填写了五个参数。
工具列表
该 MCP 服务器目前提供 41 个工具,覆盖股票、财报、宏观、日期分析等全方位数据。以下是完整列表:
贡献指南
欢迎提交 Issue 或 Pull Request 来帮助改进项目。贡献前请先查看现有 Issue 和文档。
☕️ 请作者喝杯咖啡
如果这个项目对你有帮助,欢迎请我喝杯咖啡 ❤️
许可证
本项目采用 MIT 许可证 - 详情请查看 LICENSE 文件
本次更新概览(2025-12-25)
本次更新新增 财务指标汇总工具,将 6 大类财务数据聚合为一个便捷查询接口。
🆕 新增工具
财务指标汇总:
get_fina_indicator一键获取 6 大类财务指标(盈利能力、营运能力、成长能力、偿债能力、现金流量、杜邦分析),按季度返回合并数据。
Available Tools
41 toolsget_adjust_factor_dataA
Fetches adjustment factor data for a given stock code and date range.
Uses Baostock's "涨跌幅复权算法" factors. Useful for calculating adjusted prices.
Args:
code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
start_date: Start date in 'YYYY-MM-DD' format.
end_date: End date in 'YYYY-MM-DD' format.
Returns:
Adjustment factors table.
Inputs: code (required), start_date (required), end_date (required), limit, +1 more.
get_all_stockC
Fetch a list of all stocks (A-shares and indices) and their trading status for a date.
Args:
date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date.
Returns:
Markdown table listing stock codes and trading status (1=trading, 0=suspended).
Inputs: date, limit, format.
get_balance_dataC
Quarterly balance sheet data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_cash_flow_dataD
Quarterly cash flow data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_deposit_rate_dataD
Benchmark deposit rates.
Inputs: start_date, end_date, limit, format.
get_dividend_dataC
Fetches dividend information for a given stock code and year.
Args:
code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
year: The year to query (e.g., '2023').
year_type: Type of year. Valid options (from Baostock):
'report': Announcement year (预案公告年份)
'operate': Ex-dividend year (除权除息年份)
Defaults to 'report'.
Returns:
Dividend records table.
Inputs: code (required), year (required), year_type, limit, +1 more.
get_dupont_dataC
Quarterly Dupont analysis data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_fina_indicatorA
Aggregated financial indicators from 6 Baostock APIs into one convenient query.
**Data is returned by QUARTER** (Q1, Q2, Q3, Q4) based on financial report dates.
Input date range determines which quarters to fetch.
Combines data from:
- 盈利能力 (Profitability): roeAvg, npMargin, gpMargin, epsTTM
- 营运能力 (Operation): NRTurnRatio, INVTurnRatio, CATurnRatio
- 成长能力 (Growth): YOYNI, YOYEquity, YOYAsset
- 偿债能力 (Solvency): currentRatio, quickRatio, liabilityToAsset
- 现金流量 (Cash Flow): CFOToOR, CFOToNP, CAToAsset
- 杜邦分析 (DuPont): dupontROE, dupontAssetTurn, dupontPnitoni
Output columns include prefixes: profit_*, operation_*, growth_*,
balance_*, cashflow_*, dupont_* to distinguish data sources.
Inputs: code (required), start_date (required), end_date (required), limit, +1 more.
get_forecast_reportC
Earnings forecast report within date range.
Inputs: code (required), start_date (required), end_date (required), limit, +1 more.
get_growth_dataD
Quarterly growth capability data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_historical_k_dataA
Fetches historical K-line (OHLCV) data for a Chinese A-share stock.
Args:
code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
start_date: Start date in 'YYYY-MM-DD' format.
end_date: End date in 'YYYY-MM-DD' format.
frequency: Data frequency. Valid options (from Baostock):
'd': daily
'w': weekly
'm': monthly
'5': 5 minutes
'15': 15 minutes
'30': 30 minutes
'60': 60 minutes
Defaults to 'd'.
adjust_flag: Adjustment flag for price/volume. Valid options (from Baostock):
'1': Forward adjusted (后复权)
'2': Backward adjusted (前复权)
'3': Non-adjusted (不复权)
Defaults to '3'.
fields: Optional list of specific data fields to retrieve (must be valid Baostock fields).
If None or empty, default fields will be used (e.g., date, code, open, high, low, close, volume, amount, pctChg).
limit: Max rows to return. Defaults to 250.
format: Output format: 'markdown' | 'json' | 'csv'. Defaults to 'markdown'.
Returns:
A Markdown formatted string containing the K-line data table, or an error message.
The table might be truncated if the result set is too large.
Inputs: code (required), start_date (required), end_date (required), frequency, +4 more.
get_hs300_stocksD
CSI 300 constituents.
Inputs: date, limit, format.
get_index_constituentsC
Generic index constituent fetch (hs300/sz50/zz500).
Inputs: index (required), date, limit, format.
get_industry_membersC
Get all stocks in a given industry on a date.
Inputs: industry (required), date, limit, format.
get_last_n_trading_daysC
Return the last N trading dates.
Inputs: days.
get_latest_trading_dateB
Get the latest trading date up to today.
Inputs: no named parameters.
get_loan_rate_dataD
Benchmark loan rates.
Inputs: start_date, end_date, limit, format.
get_market_analysis_timeframeC
Return a human-friendly timeframe label.
Inputs: period.
get_money_supply_data_monthC
Monthly money supply data.
Inputs: start_date, end_date, limit, format.
get_money_supply_data_yearC
Yearly money supply data.
Inputs: start_date, end_date, limit, format.
get_month_end_trading_datesC
Return month-end trading dates for a given year.
Inputs: year (required).
get_operation_dataD
Quarterly operation capability data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_performance_express_reportD
Performance express report within date range.
Inputs: code (required), start_date (required), end_date (required), limit, +1 more.
get_profit_dataC
Quarterly profitability data.
Inputs: code (required), year (required), quarter (required), limit, +1 more.
get_recent_trading_rangeC
Return a date range string covering the recent N trading days.
Inputs: days.
get_required_reserve_ratio_dataD
Required reserve ratio data.
Inputs: start_date, end_date, year_type, limit, +1 more.
get_stock_analysisB
提供基于数据的股票分析报告,而非投资建议。
Args:
code: 股票代码,如'sh.600000'
analysis_type: 'fundamental'|'technical'|'comprehensive'
Inputs: code (required), analysis_type.
get_stock_basic_infoA
Fetches basic information for a given Chinese A-share stock.
Args:
code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
fields: Optional list to select specific columns from the available basic info
(e.g., ['code', 'code_name', 'industry', 'listingDate']).
If None or empty, returns all available basic info columns from Baostock.
Returns:
Basic stock information in the requested format.
Inputs: code (required), fields, format.
get_stock_industryC
Get industry classification for a specific stock or all stocks on a date.
Inputs: code, date, limit, format.
get_suspensionsA
List suspended stocks for a date.
Args:
date: Optional 'YYYY-MM-DD'. If None, uses current date.
limit: Max rows to return. Defaults to 250.
format: Output format: 'markdown' | 'json' | 'csv'. Defaults to 'markdown'.
Returns:
Table of stocks where tradeStatus==0.
Inputs: date, limit, format.
get_sz50_stocksC
SZSE 50 constituents.
Inputs: date, limit, format.
get_trade_datesB
Fetch trading dates within a specified range.
Args:
start_date: Optional. Start date in 'YYYY-MM-DD' format. Defaults to 2015-01-01 if None.
end_date: Optional. End date in 'YYYY-MM-DD' format. Defaults to the current date if None.
Returns:
Markdown table with 'is_trading_day' (1=trading, 0=non-trading).
Inputs: start_date, end_date, limit, format.
get_zz500_stocksD
CSI 500 constituents.
Inputs: date, limit, format.
is_trading_dayC
Check if a specific date is a trading day.
Inputs: date (required).
list_industriesC
List distinct industries for a given date.
Inputs: date, format.
list_tool_constantsB
List valid constants for tool parameters.
Args:
kind: Optional filter: 'frequency' | 'adjust_flag' | 'year_type' | 'index'. If None, show all.
Inputs: kind.
next_trading_dayC
Get the next trading day after the given date.
Inputs: date (required).
normalize_index_codeC
Normalize common index codes to Baostock format.
Inputs: code (required).
normalize_stock_codeC
Normalize a stock code to Baostock format.
Inputs: code (required).
previous_trading_dayC
Get the previous trading day before the given date.
Inputs: date (required).
search_stocksA
Search stocks by code substring on a date.
Args:
keyword: Substring to match in the stock code (e.g., '600', '000001').
date: Optional 'YYYY-MM-DD'. If None, uses current date.
limit: Max rows to return. Defaults to 50.
format: Output format: 'markdown' | 'json' | 'csv'. Defaults to 'markdown'.
Returns:
Matching stock codes with their trading status.
Inputs: keyword (required), date, limit, format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 41 tools
Most tools have distinct purposes targeting specific financial data types (e.g., balance sheets, dividends, K-line data), but there is significant overlap in data retrieval patterns. Tools like get_balance_data, get_cash_flow_data, get_profit_data, and get_operation_data all follow the same quarterly data fetch pattern for different metrics, which could cause confusion about which specific financial indicator is needed. However, the clear naming and descriptions help mitigate this overlap.
Tool names follow a highly consistent 'verb_noun' pattern throughout, primarily using 'get_' or 'list_' prefixes (e.g., get_adjust_factor_data, list_industries, search_stocks). Minor deviations like is_trading_day and normalize_stock_code still fit the pattern semantically. This consistency makes the tool set predictable and easy to navigate.
With 41 tools, the count is excessive for a stock data server, leading to bloat and potential overwhelm. Many tools are highly specialized (e.g., get_month_end_trading_dates, get_market_analysis_timeframe) that could be consolidated into broader functions. A more focused set of 15-20 tools would better serve the domain without sacrificing functionality.
The tool set provides comprehensive coverage for Chinese stock market data, including historical prices, financial statements, indices, dividends, trading calendars, and industry classifications. It supports full CRUD-like data retrieval across multiple dimensions (time, frequency, adjustment) and includes utility functions for code normalization and constant listing, leaving no obvious gaps for the stated purpose.
Maintenance
Related MCP Connectors
China A-share & equity research MCP server (回声投研) for market quotes, filings, financials, fund flows, concepts & sentiment.
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.
China A-share data for AI agents: 57 read-only tools plus 6 tools for your own watchlist.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables Claude Desktop to access and analyze Chinese and global financial market data through the AKShare library.53MIT
- AlicenseNot gradedqualityDmaintenanceA server based on Model Context Protocol that enables AI assistants to query and search for stock information using the Tushare API.47MIT
- AlicenseNot gradedqualityBmaintenanceA Model Context Protocol server that provides intelligent stock data assistance through Tushare's financial data API, enabling users to query comprehensive stock information, financial data, and market indices through natural language.51MIT
- AlicenseBqualityDmaintenanceA financial data server that provides real-time and historical data for A-shares, Hong Kong, and US markets using the AkShare library. It enables users to query market quotes, fundamental information, and technical indicators through the Model Context Protocol.144MIT