Skip to main content
Glama
ttjslbz001

AKShare MCP Server

by ttjslbz001

AKShare MCP 服务器

使用 AKShare 库提供财务数据分析功能的模型上下文协议 (MCP) 服务器。

特征

  • 通过AKShare获取中国及全球金融市场数据

  • 通过 MCP 协议与 Claude Desktop 集成

  • 支持各类财务数据查询及分析

Related MCP server: Tushare_MCP

安装

使用 uv(推荐)

# Clone the repository
git clone https://github.com/yourusername/akshare_mcp_server.git
cd akshare_mcp_server

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies with uv
uv pip install -e .

使用 pip

# Clone the repository
git clone https://github.com/yourusername/akshare_mcp_server.git
cd akshare_mcp_server

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -e .

用法

运行服务器

# Activate the virtual environment
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Run the server
python run_server.py

与 Claude Desktop 集成

  1. 将以下配置添加到您的 Claude Desktop 配置中:

"mcpServers": {
    "akshare-mcp": {
        "command": "uv",
        "args": [
            "--directory",
            "/path/to/akshare_mcp_server",
            "run",
            "akshare-mcp"
        ],
        "env": {
            "AKSHARE_API_KEY": "<your_api_key_if_needed>"
        }
    }
}
  1. 重启Claude桌面

  2. 从可用工具中选择 AKShare MCP 服务器

可用工具

AKShare MCP 服务器提供以下工具:

  • 股票数据查询

  • 基金数据查询

  • 债券数据查询

  • 期货数据查询

  • 外汇数据查询

  • 宏观经济数据查询

  • 还有更多...

添加新工具

要向 MCP 服务器添加新工具,请按照以下步骤操作:

  1. 在src/mcp_server_akshare/api.py中添加一个新的 API 函数:

    async def fetch_new_data_function(param1: str, param2: str = "default") -> List[Dict[str, Any]]:
        """
        Fetch new data type.
        
        Args:
            param1: Description of param1
            param2: Description of param2
        """
        try:
            df = ak.akshare_function_name(param1=param1, param2=param2)
            return dataframe_to_dict(df)
        except Exception as e:
            logger.error(f"Error fetching new data: {e}")
            raise
  2. 将新工具添加到src/mcp_server_akshare/server.py中的枚举中:

    class AKShareTools(str, Enum):
        # Existing tools...
        NEW_TOOL_NAME = "new_tool_name"
  3. 在src/mcp_server_akshare/server.py中导入新函数:

    from .api import (
        # Existing imports...
        fetch_new_data_function,
    )
  4. 将工具定义添加到handle_list_tools()函数:

    types.Tool(
        name=AKShareTools.NEW_TOOL_NAME.value,
        description="Description of the new tool",
        inputSchema={
            "type": "object",
            "properties": {
                "param1": {"type": "string", "description": "Description of param1"},
                "param2": {"type": "string", "description": "Description of param2"},
            },
            "required": ["param1"],  # List required parameters
        },
    ),
  5. 在handle_call_tool()函数中添加工具处理程序:

    case AKShareTools.NEW_TOOL_NAME.value:
        param1 = arguments.get("param1")
        if not param1:
            raise ValueError("Missing required argument: param1")
        
        param2 = arguments.get("param2", "default")
        
        result = await fetch_new_data_function(
            param1=param1,
            param2=param2,
        )
  6. 通过运行服务器并向新工具发出请求来测试新工具。

发展

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

Docker

您还可以使用 Docker 运行服务器:

# Build the Docker image
docker build -t akshare-mcp-server .

# Run the Docker container
docker run -p 8000:8000 akshare-mcp-server

执照

麻省理工学院

Related MCP Connectors

Related MCP Servers

  • A
    license
    C
    quality
    F
    maintenance
    A Model Context Protocol server providing tools for querying A-share stock market data, including historical prices, financial reports, market indices, and macroeconomic indicators.
    41
    646
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    A Model Context Protocol server that provides intelligent stock data assistance through Tushare's financial data API, enabling users to query comprehensive stock information, financial data, and market indices through natural language.
    49
    MIT
  • F
    license
    B
    quality
    D
    maintenance
    A financial data server that provides real-time and historical data for A-shares, Hong Kong, and US markets using the AkShare library. It enables users to query market quotes, fundamental information, and technical indicators through the Model Context Protocol.
    14
    4
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that integrates Futu OpenAPI, enabling AI models to query real-time market data and execute trades across Hong Kong, US, and A-share markets.
    38 PyPI
    81
    MIT