
A-Share MCP Server
A Model Context Protocol server providing tools for querying A-share stock market data, including historical prices, financial reports, market indices, and macroeconomic indicators.
Tools
get_historical_k_data
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). 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.
get_stock_basic_info
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: A Markdown formatted string containing the basic stock information table, or an error message.
get_dividend_data
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: A Markdown formatted string containing the dividend data table, or an error message.
get_adjust_factor_data
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: A Markdown formatted string containing the adjustment factor data table, or an error message.
get_profit_data
Fetches quarterly profitability data (e.g., ROE, net profit margin) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with profitability data or an error message.
get_operation_data
Fetches quarterly operation capability data (e.g., turnover ratios) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with operation capability data or an error message.
get_growth_data
Fetches quarterly growth capability data (e.g., YOY growth rates) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with growth capability data or an error message.
get_balance_data
Fetches quarterly balance sheet / solvency data (e.g., current ratio, debt ratio) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with balance sheet data or an error message.
get_cash_flow_data
Fetches quarterly cash flow data (e.g., CFO/Operating Revenue ratio) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with cash flow data or an error message.
get_dupont_data
Fetches quarterly DuPont analysis data (ROE decomposition) for a stock. Args: code: The stock code (e.g., 'sh.600000'). year: The 4-digit year (e.g., '2023'). quarter: The quarter (1, 2, 3, or 4). Returns: Markdown table with DuPont analysis data or an error message.
get_performance_express_report
Fetches performance express reports (业绩快报) for a stock within a date range. Note: Companies are not required to publish these except in specific cases. Args: code: The stock code (e.g., 'sh.600000'). start_date: Start date (for report publication/update) in 'YYYY-MM-DD' format. end_date: End date (for report publication/update) in 'YYYY-MM-DD' format. Returns: Markdown table with performance express report data or an error message.
get_forecast_report
Fetches performance forecast reports (业绩预告) for a stock within a date range. Note: Companies are not required to publish these except in specific cases. Args: code: The stock code (e.g., 'sh.600000'). start_date: Start date (for report publication/update) in 'YYYY-MM-DD' format. end_date: End date (for report publication/update) in 'YYYY-MM-DD' format. Returns: Markdown table with performance forecast report data or an error message.
get_stock_industry
Fetches industry classification for a specific stock or all stocks on a given date. Args: code: Optional. The stock code (e.g., 'sh.600000'). If None, fetches for all stocks. date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the latest available date. Returns: Markdown table with industry classification data or an error message.
get_sz50_stocks
Fetches the constituent stocks of the SZSE 50 Index for a given date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the latest available date. Returns: Markdown table with SZSE 50 constituent stocks or an error message.
get_hs300_stocks
Fetches the constituent stocks of the CSI 300 Index for a given date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the latest available date. Returns: Markdown table with CSI 300 constituent stocks or an error message.
get_zz500_stocks
Fetches the constituent stocks of the CSI 500 Index for a given date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the latest available date. Returns: Markdown table with CSI 500 constituent stocks or an error message.
get_trade_dates
Fetches trading dates information 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 indicating whether each date in the range was a trading day (1) or not (0).
get_all_stock
Fetches a list of all stocks (A-shares and indices) and their trading status for a given date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date. Returns: Markdown table listing stock codes, names, and their trading status (1=trading, 0=suspended).
get_deposit_rate_data
Fetches benchmark deposit rates (活期, 定期) within a date range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. end_date: Optional. End date in 'YYYY-MM-DD' format. Returns: Markdown table with deposit rate data or an error message.
get_loan_rate_data
Fetches benchmark loan rates (贷款利率) within a date range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. end_date: Optional. End date in 'YYYY-MM-DD' format. Returns: Markdown table with loan rate data or an error message.
get_required_reserve_ratio_data
Fetches required reserve ratio data (存款准备金率) within a date range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. end_date: Optional. End date in 'YYYY-MM-DD' format. year_type: Optional. Year type for date filtering. '0' for announcement date (公告日期, default), '1' for effective date (生效日期). Returns: Markdown table with required reserve ratio data or an error message.
get_money_supply_data_month
Fetches monthly money supply data (M0, M1, M2) within a date range. Args: start_date: Optional. Start date in 'YYYY-MM' format. end_date: Optional. End date in 'YYYY-MM' format. Returns: Markdown table with monthly money supply data or an error message.
get_money_supply_data_year
Fetches yearly money supply data (M0, M1, M2 - year end balance) within a date range. Args: start_date: Optional. Start year in 'YYYY' format. end_date: Optional. End year in 'YYYY' format. Returns: Markdown table with yearly money supply data or an error message.
get_shibor_data
Fetches SHIBOR (Shanghai Interbank Offered Rate) data within a date range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. end_date: Optional. End date in 'YYYY-MM-DD' format. Returns: Markdown table with SHIBOR data or an error message.
get_current_date
获取当前日期,可用于查询最新数据。 Returns: 当前日期,格式为'YYYY-MM-DD'。
get_latest_trading_date
获取最近的交易日期。如果当天是交易日,则返回当天日期;否则返回最近的交易日。 Returns: 最近的交易日期,格式为'YYYY-MM-DD'。
get_market_analysis_timeframe
获取适合市场分析的时间范围,基于当前真实日期而不是训练数据。 这个工具应该在进行市场分析或大盘分析时首先调用,以确保使用最新的实际数据。 Args: period: 时间范围类型,可选值: "recent": 最近1-2个月(默认) "quarter": 最近一个季度 "half_year": 最近半年 "year": 最近一年 Returns: 包含分析时间范围的详细描述字符串,格式为"YYYY年M月-YYYY年M月"。
get_stock_analysis
提供基于数据的股票分析报告,而非投资建议。 Args: code: 股票代码,如'sh.600000' analysis_type: 分析类型,可选'fundamental'(基本面)、'technical'(技术面)或'comprehensive'(综合) Returns: 数据驱动的分析报告,包含关键财务指标、历史表现和同行业比较
README
<div align="center">
📊 a-share-mcp 📈
<img src="https://img.shields.io/badge/A股数据-MCP%20工具-E6162D?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPg0KPHBhdGggZmlsbD0iI2ZmZiIgZD0iTTggMTAuOGMwIDAgMC44LTEuNSAyLjQtMS41IDEuNyAwIDIuOCAxLjUgNC44IDEuNSAxLjcgMCAyLjgtMC42IDIuOC0wLjZ2LTIuMmMwIDAtMS4xIDEuMS0yLjggMS4xLTIgMC0zLjEtMS41LTQuOC0xLjUtMS42IDAtMi40IDAuOS0yLjQgMC45djIuM3pNOCAxNC44YzAgMCAwLjgtMS41IDIuNC0xLjUgMS43IDAgMi44IDEuNSA0LjggMS41IDEuNyAwIDIuOC0wLjYgMi44LTAuNnYtMi4yYzAgMC0xLjEgMS4xLTIuOCAxLjEtMiAwLTMuMS0xLjUtNC44LTEuNS0xLjYgMC0yLjQgMC45LTIuNCAwLjl2Mi4zeiI+PC9wYXRoPg0KPC9zdmc+">
<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=12,15,20,24&height=200§ion=header&text=A%20股%20MCP&fontSize=80&fontAlignY=35&desc=基于%20Model%20Context%20Protocol%20(MCP)&descAlignY=60&animation=fadeIn" />
</div>
本项目是一个基于专注于 A 股市场的 MCP 服务器,它提供股票基本信息、历史 K 线数据、财务指标、宏观经济数据等多种查询功能,理论上来说,可以回答有关 A 股市场的任何问题,无论是针对大盘还是特定股票。
<div align="center"> <img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%"> </div>
项目结构
a_share_mcp/
│
├── mcp_server.py # 主服务器入口文件
├── pyproject.toml # 项目依赖配置
├── README.md # 项目说明文档
│
├── docs/ # 项目文档
│ ├── baostock_com.md # Baostock API文档
│ ├── mcp_server_docs.md # 服务器文档
│ └── dev_docs/ # 开发文档
│ ├── AppFlow.md
│ ├── ImplementationPlan.md
│ └── PRD.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配置示例
<div align="center"> <img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%"> </div>
功能特点
<div align="center"> <table> <tr> <td align="center"><img src="https://img.icons8.com/fluency/48/null/stocks-growth.png" width="30px"/><br><b>股票基础数据</b></td> <td align="center"><img src="https://img.icons8.com/fluency/48/null/line-chart.png" width="30px"/><br><b>历史行情数据</b></td> <td align="center"><img src="https://img.icons8.com/fluency/48/null/bonds.png" width="30px"/><br><b>财务报表数据</b></td> </tr> <tr> <td align="center"><img src="https://img.icons8.com/fluency/48/null/economic-improvement.png" width="30px"/><br><b>宏观经济数据</b></td> <td align="center"><img src="https://img.icons8.com/fluency/48/null/statistics.png" width="30px"/><br><b>指数成分股</b></td> <td align="center"><img src="https://img.icons8.com/fluency/48/null/fine-print.png" width="30px"/><br><b>数据分析报告</b></td> </tr> </table> </div>
先决条件
- 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 服务器提供以下工具:
<div align="center"> <details> <summary><b>🔍 展开查看全部工具</b></summary> <br> <table> <tr> <th>🏛️ 股票市场数据</th> <th>📊 财务报表数据</th> <th>🔎 市场概览数据</th> </tr> <tr valign="top"> <td> <ul> <li><code>get_historical_k_data</code></li> <li><code>get_stock_basic_info</code></li> <li><code>get_dividend_data</code></li> <li><code>get_adjust_factor_data</code></li> </ul> </td> <td> <ul> <li><code>get_profit_data</code></li> <li><code>get_operation_data</code></li> <li><code>get_growth_data</code></li> <li><code>get_balance_data</code></li> <li><code>get_cash_flow_data</code></li> <li><code>get_dupont_data</code></li> </ul> </td> <td> <ul> <li><code>get_trade_dates</code></li> <li><code>get_all_stock</code></li> </ul> </td> </tr> <tr> <th>📈 指数相关数据</th> <th>🌐 宏观经济数据</th> <th>⏰ 日期工具 & 分析</th> </tr> <tr valign="top"> <td> <ul> <li><code>get_stock_industry</code></li> <li><code>get_sz50_stocks</code></li> <li><code>get_hs300_stocks</code></li> <li><code>get_zz500_stocks</code></li> </ul> </td> <td> <ul> <li><code>get_deposit_rate_data</code></li> <li><code>get_loan_rate_data</code></li> <li><code>get_required_reserve_ratio_data</code></li> <li><code>get_money_supply_data_month</code></li> <li><code>get_money_supply_data_year</code></li> <li><code>get_shibor_data</code></li> </ul> </td> <td> <ul> <!-- <li><code>get_current_date</code></li> --> <li><code>get_latest_trading_date</code></li> <li><code>get_stock_analysis</code></li> </ul> </td> </tr> </table> </details> </div>
贡献指南
欢迎提交 Issue 或 Pull Request 来帮助改进项目。贡献前请先查看现有 Issue 和文档。
☕️ 请作者喝杯咖啡
如果这个项目对你有帮助,欢迎请我喝杯咖啡 ❤️
<img src="resource/img/ali.png" alt="支付宝收款码" width="300"/>
🌟 加入我们的社区
=======
同时也欢迎关注我们的公众号【空指针指向量化 Agent】,获取更多量化投资和 AI 智能交易相关的干货内容! 🚀
<div style="display: flex; justify-content: space-between;"> <div style="text-align: center; margin-right: 20px;"> <p>关注公众号【空指针指向了量化 Agent】,获取更多量化投资和 AI 智能交易相关的干货内容! <img src="resource/img/gzh_code.jpg" alt="公众号二维码" width="300"/> </div> </div>
另外,诚挚邀请各位加入我的知识星球(一顿饭钱:99¥)
(微信号: PareidoliaX,加微信后,我拉你进星球。该微信只做邀请用途,不做任何私人回复。非加星球请勿扰哈。),
星球中还有更多我个人分享的资料和对该项目的解析。 另外,星球会提前更新代码,抢先体验不容错过。
许可证
本项目采用 MIT 许可证 - 详情请查看 LICENSE 文件
<div align="center"> <img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=12,15,20,24§ion=footer&height=100&animation=fadeIn" /> </div>
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.