The A-Share MCP Server provides comprehensive access to Chinese A-share market data through various tools for stock information, financial reports, indices, and macroeconomic indicators.
Stock Market Data: Fetch historical K-line data (OHLCV) with various frequencies (daily, weekly, monthly, intraday), basic stock information, dividend data, adjustment factors, and lists of all stocks with trading status.
Financial Reports: Access quarterly financial data including profitability, operations, growth, balance sheets, cash flow, and DuPont analysis, plus performance express and forecast reports.
Indices & Industries: Retrieve constituent stocks for major indices (SZSE 50, CSI 300, CSI 500) and comprehensive industry classification data.
Macroeconomic Data: Query benchmark deposit/loan rates, required reserve ratios, money supply (M0, M1, M2), and SHIBOR data.
Analysis & Utilities: Generate data-driven stock analysis reports (fundamental, technical, comprehensive), manage trading dates, standardize stock codes, and access suitable timeframes for market analysis.
Output Flexibility: All tools support optional
limit
andformat
parameters for controlling data volume and output format (Markdown, JSON, CSV).
Handles data formatting and presentation using Markdown, allowing for structured output of financial data, stock analysis, and market reports.
Provides a Python-based MCP server implementation for accessing A-share market data, offering historical stock data, financial reports, market overview, and economic indicators for Chinese stock markets.
📊 a-share-mcp 📈
本项目是一个基于专注于 A 股市场的 MCP 服务器,它提供股票基本信息、历史 K 线数据、财务指标、宏观经济数据等多种查询功能,理论上来说,可以回答有关 A 股市场的任何问题,无论是针对大盘还是特定股票。
项目结构
功能特点
先决条件
- 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 服务器,请按照以下步骤操作:
使用:在 MCP 客户端中配置服务器
在支持 MCP 的客户端(如 VS Code 插件、CherryStudio 等)中,你需要配置如何启动此服务器。 推荐使用 uv
。
方法一:使用 JSON 配置的 IDE (例如 Cursor、VSCode、Trae 等)
对于需要编辑 JSON 文件来配置 MCP 服务器的客户端,你需要找到对应的能配置 MCP 的地方(各个 IDE 和桌面 MCP Client 可能都不一样),并在 mcpServers
对象中添加一个新的条目。
JSON 配置示例 (请将路径替换为你的实际绝对路径):
注意事项:
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 服务器提供以下工具:
贡献指南
欢迎提交 Issue 或 Pull Request 来帮助改进项目。贡献前请先查看现有 Issue 和文档。
☕️ 请作者喝杯咖啡
如果这个项目对你有帮助,欢迎请我喝杯咖啡 ❤️
许可证
本项目采用 MIT 许可证 - 详情请查看 LICENSE 文件
本次更新概览(2025-09)
本次更新围绕“为代理编写高效工具”的实践进行,重点提升工具可发现性、可组合性与上下文效率。
优化
- 统一输出:新增可选参数 limit(默认 250)与 ormat(markdown|json|csv),默认保持 Markdown 兼容。
- 丰富上下文:在返回中附带 meta(查询参数、as_of、返回/总行数、是否截断、列信息)。
- 新增通用格式化器:ormat_table_output(df, format, max_rows, meta),支持 JSON { data, meta }、CSV 及带 Meta 摘要的 Markdown。
- 工具封装统一化: ools/base.py 的调用助手均支持 limit/format,输出行为一致。
新增工具
- 指数/行业:get_index_constituents、list_industries、get_industry_members
- 市场概览:search_stocks(按代码子串检索)、get_suspensions(停牌列表)
- 日期工具:is_trading_day、previous_trading_day、 ext_trading_day
- 帮助工具: ormalize_stock_code(统一为 sh.600000)、list_tool_constants(枚举合法取值)
已改造工具(新增 limit/format)
- 股票:get_historical_k_data、get_stock_basic_info、get_dividend_data、get_adjust_factor_data
- 财报:所有季度类工具 + get_performance_express_report、get_forecast_report
- 指数:get_stock_industry、get_sz50_stocks、get_hs300_stocks、get_zz500_stocks
- 市场:get_trade_dates、get_all_stock
- 宏观:存款/贷款利率、存款准备金率、货币供应量(月/年)、
兼容性与示例
- 向后兼容:工具名与必填参数未变;新增参数均可选;默认输出仍为 Markdown。
- 示例:
ext get_index_constituents(index='hs300', format='json', limit=100) search_stocks(keyword='600', date='2025-01-10', limit=20) get_historical_k_data(code='sh.600000', start_date='2024-01-01', end_date='2024-06-30', frequency='d', format='csv', limit=200) previous_trading_day('2025-01-04') normalize_stock_code('000001.SZ') # -> 'sz.000001'
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Tools
A Model Context Protocol server focused on China's A-share stock market that provides data on stocks, financials, market indices, and macroeconomic indicators.
Related MCP Servers
- AsecurityFlicenseAqualityA Model Context Protocol server that provides real-time hot trending topics from major Chinese social platforms and news sites.Last updated -1403175
- -securityFlicense-qualityA Model Context Protocol server that enables Claude Desktop to access and analyze Chinese and global financial market data through the AKShare library.Last updated -42
- -securityFlicense-qualityA Multi-Call Protocol server providing comprehensive access to Chinese stock market data through a unified API, leveraging AKShare to fetch real-time and historical data from various Chinese exchanges.Last updated -17
- AsecurityAlicenseAqualityA Model Context Protocol server providing tools for querying A-share stock market data, including historical prices, financial reports, market indices, and macroeconomic indicators.Last updated -27424MIT License