Skip to main content

MCP Server for akshare stock data - A股股票数据MCP服务

Project description

akshare-stock-mcp 📈

基于 MCP (Model Context Protocol) 标准协议的 A 股股票数据服务

让任何 AI Agent 读懂 A 股

Claude Desktop / OpenClaw / Hermes / Cursor / 任何MCP客户端 · 20个专业工具 · 智能缓存 · 标准协议

MCP Python Akshare Transport License


akshare-stock-mcp 是连接 AI 与 akshare 金融数据的桥梁。它实现了 Model Context Protocol (MCP) 标准协议,让任何支持 MCP 的 AI 客户端能够直接调用 20 个专业股票数据接口——实时行情、历史K线、财务报表、北向资金、龙虎榜等。

零 API Key:akshare 是免费开源库,无需注册、无需 Token,装上就能用。


🚀 快速开始(3步,60秒)

第 1 步:安装

git clone <repository-url> akshare-mcp-server
cd akshare-mcp-server

# 创建虚拟环境
python3 -m venv .venv
source .venv/bin/activate

# 安装依赖
pip install -e .

第 2 步:验证

# 测试 Server 能否启动
python -m akshare_stock_mcp.server --help

输出应显示:

usage: server [-h] [--transport {stdio,sse,streamable-http}] [--host HOST] [--port PORT]

第 3 步:连接你的 AI 客户端

选择你使用的客户端,复制对应的配置 ↓


🔌 客户端接入指南

Claude Desktop

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "akshare-stock": {
      "command": "/你的路径/akshare-mcp-server/.venv/bin/python",
      "args": ["-m", "akshare_stock_mcp.server"],
      "cwd": "/你的路径/akshare-mcp-server/src"
    }
  }
}

重启 Claude Desktop,输入 "帮我查一下贵州茅台的实时行情" 测试。


OpenClaw

编辑 ~/.openclaw/openclaw.json

{
  "mcpServers": {
    "akshare-stock": {
      "command": "/你的路径/akshare-mcp-server/.venv/bin/python",
      "args": ["-m", "akshare_stock_mcp.server"],
      "cwd": "/你的路径/akshare-mcp-server/src",
      "transport": "stdio"
    }
  }
}

然后重启网关:

openclaw gateway restart
openclaw mcp list   # 验证:应显示 akshare-stock running 20 tools

Hermes Agent

编辑 ~/.hermes/config.yaml

mcp_servers:
  akshare-stock:
    command: "/你的路径/akshare-mcp-server/.venv/bin/python"
    args: ["-m", "akshare_stock_mcp.server"]
    cwd: "/你的路径/akshare-mcp-server/src"
    timeout: 120

或用 CLI 一键添加:

hermes mcp add --command /你的路径/.venv/bin/python --args "-m,akshare_stock_mcp.server"

Cursor

  1. 打开 Cursor → Settings → Features → MCP
  2. 点击 "+ Add New MCP Server"
  3. 填写:
    • Name: akshare-stock
    • Type: stdio
    • Command: /你的路径/akshare-mcp-server/.venv/bin/python -m akshare_stock_mcp.server

任何支持 MCP 的客户端(通用)

本服务遵循 MCP 1.0 标准协议,理论上兼容所有 MCP 客户端。

Stdio 模式(本地子进程):

/你的路径/.venv/bin/python -m akshare_stock_mcp.server

HTTP 模式(远程/共享):

# 启动 HTTP 服务
source .venv/bin/activate
PYTHONPATH=src python -m akshare_stock_mcp.server --transport streamable-http --port 8765

# 客户端连接地址
# Streamable HTTP: http://localhost:8765/mcp
# SSE:             http://localhost:8765/sse

在客户端中添加 MCP Server,URL 填 http://localhost:8765/mcp 即可。


🧰 工具列表(20个)

📊 实时行情

工具名 说明 参数
get_stock_realtime 单只股票实时行情 symbol: 股票代码
get_market_realtime_top 涨幅/成交额/换手率排行 top_n: 数量, sort_by: 排序字段

📈 历史K线

工具名 说明 参数
get_stock_history 日/周/月线(支持复权) symbol, period, start_date, end_date, adjust
get_stock_history_min 1/5/15/30/60分钟线 symbol, period, start_date, end_date

🏢 个股信息

工具名 说明 参数
get_stock_info 上市日期、行业、股本等 symbol
search_stock 按名称/代码模糊搜索 keyword

💰 财务数据

工具名 说明 参数
get_stock_financial_abstract 营收、净利润、ROE等核心指标 symbol
get_stock_financial_report 利润表/资产负债表/现金流量表 symbol, report_type
get_stock_shareholders 十大股东 symbol
get_stock_dividend 历史分红送转记录 symbol

📉 市场统计

工具名 说明 参数
get_market_pe_pb A股整体PE/PB估值水平
get_sector_performance 行业板块涨跌排行
get_sector_stocks 指定行业成分股 sector_name
get_limit_up_down 涨跌停统计 date(可选)

🌊 北向资金

工具名 说明 参数
get_northbound_flow 沪深港通净流入
get_northbound_top_stocks 外资重仓股排行 market

🐉 龙虎榜 & 融资融券

工具名 说明 参数
get_dragon_tiger 机构/游资买卖明细 date(可选)
get_margin_data 市场杠杆水平

🛠 管理

工具名 说明
clear_cache 清空所有缓存
get_cache_status 查看缓存状态

💡 使用示例

连接成功后,你可以直接用自然语言问 AI:

"帮我查一下贵州茅台最近一个月的K线数据"
"A股今天涨幅前10的股票有哪些?"
"北向资金最近流入了哪些股票?"
"平安银行的财务摘要,营收和净利润趋势如何?"
"半导体行业板块有哪些龙头股?"
"今天的龙虎榜数据"

🏗 架构

┌─────────────────────────────────────────────────┐
│  AI Client (Claude / OpenClaw / Hermes / Cursor) │
│                        │                         │
│              MCP Protocol (JSON-RPC 2.0)         │
│              stdio / SSE / Streamable HTTP        │
│                        ↓                         │
│           ┌─────────────────────────┐            │
│           │  akshare-stock-mcp      │            │
│           │  ┌───────────────────┐  │            │
│           │  │   智能缓存层       │  │            │
│           │  │  (30s~24h 分级)    │  │            │
│           │  └───────┬───────────┘  │            │
│           │          ↓              │            │
│           │  ┌───────────────────┐  │            │
│           │  │   20个工具        │  │            │
│           │  │  行情/K线/财务...  │  │            │
│           │  └───────┬───────────┘  │            │
│           └──────────┼──────────────┘            │
│                      ↓                           │
│              ┌───────────────┐                   │
│              │  akshare 库   │                   │
│              └───────┬───────┘                   │
│                      ↓                           │
│         东方财富 / 新浪 / 腾讯 等数据源            │
└─────────────────────────────────────────────────┘

⚡ 与同类项目的区别

特性 本项目 其他 akshare MCP
工具数量 20个精选 1000+ 自动生成(选择困难)
缓存 智能分级缓存 无缓存(易被限流)
输出格式 统一JSON schema 原始DataFrame字符串
错误处理 友好错误信息 原始异常堆栈
传输协议 stdio + SSE + HTTP 仅stdio
股票代码 兼容多种格式 仅纯数字

📄 许可证

MIT License


🙏 致谢

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akshare_stock_mcp-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akshare_stock_mcp-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file akshare_stock_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: akshare_stock_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for akshare_stock_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1222faf5be478e0b18c4fa1a9227215aa6e2a606e11092ce8356434dbdc0c02
MD5 322a8451df0ff290b9e6b45c86118c57
BLAKE2b-256 f9c2ca1bcdac1a7ea179bc4470572839af5a567f02f12652e61023ff082c9b4a

See more details on using hashes here.

File details

Details for the file akshare_stock_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for akshare_stock_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20fb96ce4a495b5ba3da9798a01f9aed17e4077102a00222ded28e10067e1219
MD5 7e62c141e12ee8a6f764cf64265c2281
BLAKE2b-256 8889b813380461d158ff5215b4824fe2168121e4e7e43802a96094331f856fc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page