a-stock-mcp-server


Namea-stock-mcp-server JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/Llldmiao/a-stock-mcp-server
SummaryA股实时行情MCP服务器 - 基于Model Context Protocol的A股数据查询工具
upload_time2025-09-20 05:45:32
maintainerNone
docs_urlNone
authorFinancial Tools Developer
requires_python>=3.8
licenseNone
keywords mcp stock china a-share real-time financial data investment trading
VCS
bugtrack_url
requirements akshare pandas aiohttp urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # A股实时行情MCP服务器

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![MCP Protocol](https://img.shields.io/badge/MCP-Protocol-green.svg)](https://modelcontextprotocol.io/)
[![PyPI version](https://badge.fury.io/py/a-stock-mcp-server.svg)](https://badge.fury.io/py/a-stock-mcp-server)
[![Downloads](https://pepy.tech/badge/a-stock-mcp-server)](https://pepy.tech/project/a-stock-mcp-server)

这是一个基于Model Context Protocol (MCP) 的A股实时行情查询服务器,支持查询A股实时价格、历史数据、财务信息等。专为AI助手和金融分析工具设计。

## 功能特性

### 🔥 核心功能
- **实时价格查询**: 获取A股实时价格、涨跌幅、成交量等
- **股票基本信息**: 查询股票的基本信息和公司概况
- **市场概况**: 获取上证、深证等主要指数信息
- **历史数据**: 查询股票的历史K线数据
- **财务数据**: 获取利润表、资产负债表、现金流量表

### 🛠️ 支持的工具
1. `get_realtime_price` - 获取实时价格
2. `get_stock_info` - 获取股票基本信息
3. `get_market_summary` - 获取市场概况
4. `get_stock_history` - 获取历史数据
5. `get_financial_data` - 获取财务数据

## 安装和使用

### 🚀 PyPI安装(推荐)

```bash
pip install a-stock-mcp-server
```

### 📦 从源码安装

```bash
# 克隆仓库
git clone https://github.com/Llldmiao/a-stock-mcp-server.git
cd a-stock-mcp-server

# 安装依赖
pip install -r requirements.txt

# 开发模式安装
pip install -e .
```

### 🛠️ 命令行工具使用

安装后可以使用命令行工具:

```bash
# 查询股票价格
a-stock-cli price -s 000001

# 查询股票信息
a-stock-cli info -s 000001

# 查询市场概况
a-stock-cli market
```

### 🧪 本地测试

```bash
# 运行完整测试
python3 local_test.py
```

### 📚 Python代码使用

```python
import asyncio
from local_test import AStockLocalTest

async def main():
    server = AStockLocalTest()
    
    # 查询平安银行实时价格
    result = await server.call_tool("get_realtime_price", {"symbol": "000001"})
    print(result)

asyncio.run(main())
```

## 使用示例

### 查询实时价格
```json
{
  "tool": "get_realtime_price",
  "arguments": {
    "symbol": "000001"
  }
}
```

### 查询历史数据
```json
{
  "tool": "get_stock_history", 
  "arguments": {
    "symbol": "000001",
    "period": "daily",
    "start_date": "20240101",
    "end_date": "20241231"
  }
}
```

### 查询财务数据
```json
{
  "tool": "get_financial_data",
  "arguments": {
    "symbol": "000001",
    "report_type": "income"
  }
}
```

## 数据源

本MCP服务器使用 [AKShare](https://github.com/akfamily/akshare) 作为数据源:
- 免费、开源
- 数据更新及时
- 支持多种金融数据
- 社区活跃

## 扩展建议

### 1. 多数据源支持
- 集成新浪财经API
- 集成腾讯财经API
- 添加数据源故障转移

### 2. 缓存机制
- 添加Redis缓存
- 减少API调用频率
- 提高响应速度

### 3. 数据验证
- 添加数据有效性检查
- 异常数据处理
- 错误重试机制

### 4. 更多功能
- 技术指标计算
- 股票筛选器
- 实时推送
- 历史回测

## 注意事项

1. **数据延迟**: AKShare数据可能有15-20分钟延迟
2. **API限制**: 注意API调用频率限制
3. **数据准确性**: 仅供参考,投资决策请谨慎
4. **网络依赖**: 需要稳定的网络连接

## 故障排除

### 常见问题
1. **导入错误**: 确保安装了所有依赖包
2. **网络超时**: 检查网络连接,可能需要代理
3. **数据为空**: 检查股票代码格式是否正确

### 日志调试
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

## 贡献

欢迎提交Issue和Pull Request来改进这个项目!

## 许可证

MIT License

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Llldmiao/a-stock-mcp-server",
    "name": "a-stock-mcp-server",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "mcp, stock, china, a-share, real-time, financial, data, investment, trading",
    "author": "Financial Tools Developer",
    "author_email": "financial-tools@example.com",
    "download_url": "https://files.pythonhosted.org/packages/d3/15/e7f16844e1d03632bc10c600c03a8ef060027a0cd489da1e2c4aeab4ed6c/a_stock_mcp_server-1.0.0.tar.gz",
    "platform": null,
    "description": "# A\u80a1\u5b9e\u65f6\u884c\u60c5MCP\u670d\u52a1\u5668\n\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![MCP Protocol](https://img.shields.io/badge/MCP-Protocol-green.svg)](https://modelcontextprotocol.io/)\n[![PyPI version](https://badge.fury.io/py/a-stock-mcp-server.svg)](https://badge.fury.io/py/a-stock-mcp-server)\n[![Downloads](https://pepy.tech/badge/a-stock-mcp-server)](https://pepy.tech/project/a-stock-mcp-server)\n\n\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8eModel Context Protocol (MCP) \u7684A\u80a1\u5b9e\u65f6\u884c\u60c5\u67e5\u8be2\u670d\u52a1\u5668\uff0c\u652f\u6301\u67e5\u8be2A\u80a1\u5b9e\u65f6\u4ef7\u683c\u3001\u5386\u53f2\u6570\u636e\u3001\u8d22\u52a1\u4fe1\u606f\u7b49\u3002\u4e13\u4e3aAI\u52a9\u624b\u548c\u91d1\u878d\u5206\u6790\u5de5\u5177\u8bbe\u8ba1\u3002\n\n## \u529f\u80fd\u7279\u6027\n\n### \ud83d\udd25 \u6838\u5fc3\u529f\u80fd\n- **\u5b9e\u65f6\u4ef7\u683c\u67e5\u8be2**: \u83b7\u53d6A\u80a1\u5b9e\u65f6\u4ef7\u683c\u3001\u6da8\u8dcc\u5e45\u3001\u6210\u4ea4\u91cf\u7b49\n- **\u80a1\u7968\u57fa\u672c\u4fe1\u606f**: \u67e5\u8be2\u80a1\u7968\u7684\u57fa\u672c\u4fe1\u606f\u548c\u516c\u53f8\u6982\u51b5\n- **\u5e02\u573a\u6982\u51b5**: \u83b7\u53d6\u4e0a\u8bc1\u3001\u6df1\u8bc1\u7b49\u4e3b\u8981\u6307\u6570\u4fe1\u606f\n- **\u5386\u53f2\u6570\u636e**: \u67e5\u8be2\u80a1\u7968\u7684\u5386\u53f2K\u7ebf\u6570\u636e\n- **\u8d22\u52a1\u6570\u636e**: \u83b7\u53d6\u5229\u6da6\u8868\u3001\u8d44\u4ea7\u8d1f\u503a\u8868\u3001\u73b0\u91d1\u6d41\u91cf\u8868\n\n### \ud83d\udee0\ufe0f \u652f\u6301\u7684\u5de5\u5177\n1. `get_realtime_price` - \u83b7\u53d6\u5b9e\u65f6\u4ef7\u683c\n2. `get_stock_info` - \u83b7\u53d6\u80a1\u7968\u57fa\u672c\u4fe1\u606f\n3. `get_market_summary` - \u83b7\u53d6\u5e02\u573a\u6982\u51b5\n4. `get_stock_history` - \u83b7\u53d6\u5386\u53f2\u6570\u636e\n5. `get_financial_data` - \u83b7\u53d6\u8d22\u52a1\u6570\u636e\n\n## \u5b89\u88c5\u548c\u4f7f\u7528\n\n### \ud83d\ude80 PyPI\u5b89\u88c5\uff08\u63a8\u8350\uff09\n\n```bash\npip install a-stock-mcp-server\n```\n\n### \ud83d\udce6 \u4ece\u6e90\u7801\u5b89\u88c5\n\n```bash\n# \u514b\u9686\u4ed3\u5e93\ngit clone https://github.com/Llldmiao/a-stock-mcp-server.git\ncd a-stock-mcp-server\n\n# \u5b89\u88c5\u4f9d\u8d56\npip install -r requirements.txt\n\n# \u5f00\u53d1\u6a21\u5f0f\u5b89\u88c5\npip install -e .\n```\n\n### \ud83d\udee0\ufe0f \u547d\u4ee4\u884c\u5de5\u5177\u4f7f\u7528\n\n\u5b89\u88c5\u540e\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff1a\n\n```bash\n# \u67e5\u8be2\u80a1\u7968\u4ef7\u683c\na-stock-cli price -s 000001\n\n# \u67e5\u8be2\u80a1\u7968\u4fe1\u606f\na-stock-cli info -s 000001\n\n# \u67e5\u8be2\u5e02\u573a\u6982\u51b5\na-stock-cli market\n```\n\n### \ud83e\uddea \u672c\u5730\u6d4b\u8bd5\n\n```bash\n# \u8fd0\u884c\u5b8c\u6574\u6d4b\u8bd5\npython3 local_test.py\n```\n\n### \ud83d\udcda Python\u4ee3\u7801\u4f7f\u7528\n\n```python\nimport asyncio\nfrom local_test import AStockLocalTest\n\nasync def main():\n    server = AStockLocalTest()\n    \n    # \u67e5\u8be2\u5e73\u5b89\u94f6\u884c\u5b9e\u65f6\u4ef7\u683c\n    result = await server.call_tool(\"get_realtime_price\", {\"symbol\": \"000001\"})\n    print(result)\n\nasyncio.run(main())\n```\n\n## \u4f7f\u7528\u793a\u4f8b\n\n### \u67e5\u8be2\u5b9e\u65f6\u4ef7\u683c\n```json\n{\n  \"tool\": \"get_realtime_price\",\n  \"arguments\": {\n    \"symbol\": \"000001\"\n  }\n}\n```\n\n### \u67e5\u8be2\u5386\u53f2\u6570\u636e\n```json\n{\n  \"tool\": \"get_stock_history\", \n  \"arguments\": {\n    \"symbol\": \"000001\",\n    \"period\": \"daily\",\n    \"start_date\": \"20240101\",\n    \"end_date\": \"20241231\"\n  }\n}\n```\n\n### \u67e5\u8be2\u8d22\u52a1\u6570\u636e\n```json\n{\n  \"tool\": \"get_financial_data\",\n  \"arguments\": {\n    \"symbol\": \"000001\",\n    \"report_type\": \"income\"\n  }\n}\n```\n\n## \u6570\u636e\u6e90\n\n\u672cMCP\u670d\u52a1\u5668\u4f7f\u7528 [AKShare](https://github.com/akfamily/akshare) \u4f5c\u4e3a\u6570\u636e\u6e90\uff1a\n- \u514d\u8d39\u3001\u5f00\u6e90\n- \u6570\u636e\u66f4\u65b0\u53ca\u65f6\n- \u652f\u6301\u591a\u79cd\u91d1\u878d\u6570\u636e\n- \u793e\u533a\u6d3b\u8dc3\n\n## \u6269\u5c55\u5efa\u8bae\n\n### 1. \u591a\u6570\u636e\u6e90\u652f\u6301\n- \u96c6\u6210\u65b0\u6d6a\u8d22\u7ecfAPI\n- \u96c6\u6210\u817e\u8baf\u8d22\u7ecfAPI\n- \u6dfb\u52a0\u6570\u636e\u6e90\u6545\u969c\u8f6c\u79fb\n\n### 2. \u7f13\u5b58\u673a\u5236\n- \u6dfb\u52a0Redis\u7f13\u5b58\n- \u51cf\u5c11API\u8c03\u7528\u9891\u7387\n- \u63d0\u9ad8\u54cd\u5e94\u901f\u5ea6\n\n### 3. \u6570\u636e\u9a8c\u8bc1\n- \u6dfb\u52a0\u6570\u636e\u6709\u6548\u6027\u68c0\u67e5\n- \u5f02\u5e38\u6570\u636e\u5904\u7406\n- \u9519\u8bef\u91cd\u8bd5\u673a\u5236\n\n### 4. \u66f4\u591a\u529f\u80fd\n- \u6280\u672f\u6307\u6807\u8ba1\u7b97\n- \u80a1\u7968\u7b5b\u9009\u5668\n- \u5b9e\u65f6\u63a8\u9001\n- \u5386\u53f2\u56de\u6d4b\n\n## \u6ce8\u610f\u4e8b\u9879\n\n1. **\u6570\u636e\u5ef6\u8fdf**: AKShare\u6570\u636e\u53ef\u80fd\u670915-20\u5206\u949f\u5ef6\u8fdf\n2. **API\u9650\u5236**: \u6ce8\u610fAPI\u8c03\u7528\u9891\u7387\u9650\u5236\n3. **\u6570\u636e\u51c6\u786e\u6027**: \u4ec5\u4f9b\u53c2\u8003\uff0c\u6295\u8d44\u51b3\u7b56\u8bf7\u8c28\u614e\n4. **\u7f51\u7edc\u4f9d\u8d56**: \u9700\u8981\u7a33\u5b9a\u7684\u7f51\u7edc\u8fde\u63a5\n\n## \u6545\u969c\u6392\u9664\n\n### \u5e38\u89c1\u95ee\u9898\n1. **\u5bfc\u5165\u9519\u8bef**: \u786e\u4fdd\u5b89\u88c5\u4e86\u6240\u6709\u4f9d\u8d56\u5305\n2. **\u7f51\u7edc\u8d85\u65f6**: \u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\uff0c\u53ef\u80fd\u9700\u8981\u4ee3\u7406\n3. **\u6570\u636e\u4e3a\u7a7a**: \u68c0\u67e5\u80a1\u7968\u4ee3\u7801\u683c\u5f0f\u662f\u5426\u6b63\u786e\n\n### \u65e5\u5fd7\u8c03\u8bd5\n```python\nimport logging\nlogging.basicConfig(level=logging.DEBUG)\n```\n\n## \u8d21\u732e\n\n\u6b22\u8fce\u63d0\u4ea4Issue\u548cPull Request\u6765\u6539\u8fdb\u8fd9\u4e2a\u9879\u76ee\uff01\n\n## \u8bb8\u53ef\u8bc1\n\nMIT License\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A\u80a1\u5b9e\u65f6\u884c\u60c5MCP\u670d\u52a1\u5668 - \u57fa\u4e8eModel Context Protocol\u7684A\u80a1\u6570\u636e\u67e5\u8be2\u5de5\u5177",
    "version": "1.0.0",
    "project_urls": {
        "Bug Reports": "https://github.com/Llldmiao/a-stock-mcp-server/issues",
        "Changelog": "https://github.com/Llldmiao/a-stock-mcp-server/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/Llldmiao/a-stock-mcp-server#readme",
        "Homepage": "https://github.com/Llldmiao/a-stock-mcp-server",
        "Source": "https://github.com/Llldmiao/a-stock-mcp-server"
    },
    "split_keywords": [
        "mcp",
        " stock",
        " china",
        " a-share",
        " real-time",
        " financial",
        " data",
        " investment",
        " trading"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d03ebbc763a766e72c5003fb178bff3ea18b73a8e4b521083cf3f2ca5cc67dcf",
                "md5": "8ea919e04d434efb77a0171f99d9e1af",
                "sha256": "d387a9b8cc1e4bba3781e31a4dc2bd9033404b385631ebb0031791d371e279b9"
            },
            "downloads": -1,
            "filename": "a_stock_mcp_server-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8ea919e04d434efb77a0171f99d9e1af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4895,
            "upload_time": "2025-09-20T05:45:30",
            "upload_time_iso_8601": "2025-09-20T05:45:30.496605Z",
            "url": "https://files.pythonhosted.org/packages/d0/3e/bbc763a766e72c5003fb178bff3ea18b73a8e4b521083cf3f2ca5cc67dcf/a_stock_mcp_server-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d315e7f16844e1d03632bc10c600c03a8ef060027a0cd489da1e2c4aeab4ed6c",
                "md5": "32d8dfa65d05137d7d1786aae42103df",
                "sha256": "cefde023d805356f0361987b18d898146494367cceea13d8ac3f605b3f948352"
            },
            "downloads": -1,
            "filename": "a_stock_mcp_server-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32d8dfa65d05137d7d1786aae42103df",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15018,
            "upload_time": "2025-09-20T05:45:32",
            "upload_time_iso_8601": "2025-09-20T05:45:32.025501Z",
            "url": "https://files.pythonhosted.org/packages/d3/15/e7f16844e1d03632bc10c600c03a8ef060027a0cd489da1e2c4aeab4ed6c/a_stock_mcp_server-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-20 05:45:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Llldmiao",
    "github_project": "a-stock-mcp-server",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "akshare",
            "specs": [
                [
                    ">=",
                    "1.12.0"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "1.5.0"
                ]
            ]
        },
        {
            "name": "aiohttp",
            "specs": [
                [
                    ">=",
                    "3.8.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "1.26.18"
                ]
            ]
        }
    ],
    "lcname": "a-stock-mcp-server"
}
        
Elapsed time: 1.22143s