Tushare MCP

by buuzzy

Not rated
GitHub

About

An intelligent stock data assistant providing financial data using the Tushare API.

Details

Author
buuzzy
Categories
Database, Finance, Other, API

Setup

Install Tushare MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/buuzzy/tushare_MCP

Follow the installation instructions in the repository README, then restart your MCP client.

基于 MCP (Model Context Protocol) 协议构建的 A 股金融数据 AI 助手扩展 (v0.1.0)

Claude Desktop / Cursor 无缝集成 · A 股/港股全量数据 · 财务报表 · 智能 Token 管理

Tushare MCP是一款连接 AI(Claude, Cursor)与 Tushare 金融大数据的桥梁。它实现了 Model Context Protocol (MCP) 标准,让你的 AI 助手能够直接调用 30+ 个专业金融数据接口,实时查询股票行情、财务报表、公司基本面等关键数据。

本项目采用了更为方便、平价的 tinyshare SDK,替代了官方的 tushare 库。使用下述依赖:

如果你完全不知道如何使用,请阅读下方腾讯文档:Tushare MCP 使用说明

如果你想通过添加 mcp server 直接使用,忽略繁琐过程,可以联系我试用: 微信:Buuzzy0603

### stock endpoint https://stock-mcp.pricetrade.top/sse ### fund endpoint https://fund-mcp.pricetrade.top/sse

本次更新重点补齐了公募基金及 ETF 接口。同时,针对大模型(特别是数据对比与分析场景)强烈的“多代码逗号分隔查询”倾向,而底层 Tushare API 又不原生支持的痛点,我们在所有的 Fund 模块底层植入了“本地请求切割与合并处理器”。该机制能够智能拦截逗号列表,在后台循环发起多次原子请求并拼接整合数据帧。

本次迭代实现了从单文件脚本向模块化工程的重构。我们将原来的单体 server.py 拆分为 server.py (仅负责服务编排与路由)、 tools/ (按业务领域拆分的逻辑核心) 以及 utils/ (基础设施) 三层架构。此改动彻底解耦了服务启动与业务逻辑,使得每个 Tushare 接口(如行情、财务)拥有独立的文件空间,显著提升了代码的可维护性与扩展性,为后续接入更多数据源和多人协作奠定了坚实的工程基础。

- Claude Desktop: 标准 Streamable HTTP / Stdio 模式支持,本地直接运行。
- Cursor IDE: 在编辑器中直接询问代码相关的股票数据,辅助金融编程。

- 基础数据: 股票列表、IPO 新股、交易日历、上市公司基本面。
- 行情数据: 日/周/月线行情、每日指标(PE/PB/市值)、涨跌停分析。
- 财务报表: 利润表、资产负债表、现金流量表、业绩预告、主营业务构成。
- 基金与ETF: 场内/场外基金列表、每日行情与份额、基金经理简历、基金持仓、基金分红与净值、专业技术因子。
- 特色数据: 沪深港通十大成交股、融资融券、股权质押。

- 一键配置: 提供setup_tushare_token工具,对话即可完成配置。
- 本地加密: Token 安全存储于本地环境,无需重复输入。
- 批量查询重写: 针对 Tushare 不支持批量ts_code查询的基金接口,在本地自动实现“逗号分割 -> 循环请求 -> 数据拼接”,完美适配 LLM 批量查询习惯。

- Streamable HTTP: 基于 MCP SDK 原生 Streamable HTTP 传输协议,取代旧版 SSE。
- Tinyshare SDK: 深度优化的 Tushare 接口封装,支持重试与异常处理。

graph TD Client(["AI Client (Claude / Cursor)"]) -->|MCP Protocol (Streamable HTTP / Stdio)| MCPServer[Tushare MCP Server] MCPServer -->|Tool Execution| Tools[Tool Implementation] Tools -->|Data Request| SDK[Tinyshare SDK] SDK -->|HTTP API| Tushare[("Tushare Pro API")] Tushare -->|JSON Data| SDK SDK -->|Structured Result| Tools Tools -->|Context| MCPServer MCPServer -->|Answer| Client
# 1. 克隆项目 git clone <repository-url> tushare_mcp cd tushare_mcp # 2. 创建虚拟环境 python3 -m venv venv source venv/bin/activate # macOS/Linux # venv\Scripts\activate # Windows # 3. 安装依赖 pip install -r requirements.txt
# 创建配置文件 touch .env # 写入 Token(推荐使用 MCP 工具 setup_tushare_token 自动配置) echo "TUSHARE_TOKEN=你的token" >> .env

方式 A: HTTP Server (Streamable HTTP 模式) - 推荐

python server.py # 服务将运行在 http://localhost:8000 # MCP 端点: http://localhost:8000/mcp

- 打开 Cursor Settings -> Features -> MCP
- 点击 "+ Add New MCP Server"
- 填写信息:

- Name:tushare
- Type:Streamable HTTP
- URL:http://localhost:8000/mcp

编辑配置文件~/Library/Application Support/Claude/claude_desktop_config.json:

{ "mcpServers": { "tushare": { "command": "/绝对路径/至/你的/venv/bin/python", "args": [ "/绝对路径/至/你的/tushare_mcp/server.py", "--stdio" ] } } }
tushare_MCP/ ├── api_docs/ # 原始 Tushare API 文档参考 ├── mcp_test/ # MCP 工具测试记录 ├── tools/ # MCP 工具实现核心代码 │ ├── finance/ # 财务类工具 (income, balance, cashflow...) │ └── stock/ │ ├── basic/ # 基础数据工具 (stock_basic, trade_cal...) │ └── quote/ # 行情数据工具 (daily, weekly, hsgt...) ├── utils/ # 通用工具函数 (logger, token_manager) ├── server.py # MCP Server 入口 (FastAPI + FastMCP) ├── requirements.txt # 项目依赖 └── README.md # 项目文档

Provides real-time financial market data using the Alpha Vantage API.

A stock market data service for querying A-share market data from Sina and Tencent Finance.

Perform financial analysis using the DART API and Claude.

Funding rounds, acquisitions & exec moves — deduped, enriched, typed. Query over REST, stream over webhooks, or hand to your agent over MCP. 50 free credits.

Access financial datasets from the Federal Reserve Economic Data (FRED) API.

Provides real-time financial data using the Tushare API.

Provides real-time financial data from Yahoo Finance.

Access US Treasury data via the Fiscal Data API to fetch statements, historical data, and generate reports.

Real-time forex macroeconomic API for all major currency pairs sourced from central bank announcements.

Retrieve and process economic data from the International Monetary Fund (IMF) API, including datasets, time series, indicators, and countries.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.