A-Share Financial Data (Baostock) MCP server

Provides financial data tools for Chinese stock market analysis through the Baostock API, enabling retrieval of historical prices, financial reports, industry classifications, index constituents, and macroeconomic indicators.
Back to servers
Setup instructions
Provider
24mlight
Release date
Apr 30, 2025
Language
Python
Stats
424 stars

This MCP server provides a comprehensive interface for accessing A-share (Chinese stock market) data through the Model Context Protocol. It offers various data querying capabilities including stock information, historical price data, financial indicators, and macroeconomic data.

Installation

To set up the A-share MCP server, follow these steps:

# 1. Create a virtual environment
uv venv

# 2. Activate the virtual environment
# On Windows
.venv\Scripts\activate
# On macOS/Linux
# source .venv/bin/activate

# 3. Install all dependencies
uv sync

Configuring MCP Server in Your Client

You'll need to configure this server in an MCP-compatible client (like VS Code, CherryStudio, etc.).

Method 1: Using JSON Configuration (Cursor, VSCode, Trae)

Add the following configuration to your MCP client's JSON settings:

{
  "mcpServers": {
    "a-share-mcp": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\Users\\YourName\\Projects\\a_share_mcp",
        "run",
        "python",
        "mcp_server.py"
      ],
      "transport": "stdio"
    }
  }
}

Important Notes:

  • Replace the directory path with your actual project path
  • Ensure the uv command is accessible or provide the absolute path to uv.exe
  • On Windows, use double backslashes \\ in the path

Method 2: Using CherryStudio

In CherryStudio's MCP server configuration interface:

  • Name: a-share-mcp (or custom name)
  • Description: Local A-share MCP Server (or custom description)
  • Type: Select Standard Input/Output (stdio)
  • Command: uv (or absolute path to uv.exe)
  • Parameters: Add each of these on separate lines:
    1. --directory
    2. C:\\Users\\YourName\\Projects\\a_share_mcp
    3. run
    4. python
    5. mcp_server.py

Tip: If the server doesn't start immediately, try navigating away from the MCP settings page and then back again.

Available Tools

The server provides a variety of tools organized in several categories:

Stock Market Data

  • get_historical_k_data: Retrieve historical K-line data
  • get_stock_basic_info: Get basic stock information
  • get_dividend_data: Obtain dividend history
  • get_adjust_factor_data: Get price adjustment factors

Financial Statement Data

  • get_profit_data: Retrieve profit statement data
  • get_operation_data: Get operational metrics
  • get_growth_data: Access growth indicators
  • get_balance_data: Get balance sheet data
  • get_cash_flow_data: Retrieve cash flow information
  • get_dupont_data: Access DuPont analysis data

Market Overview

  • get_trade_dates: Get trading dates
  • get_all_stock: List all stocks
  • search_stocks: Search for stocks by keyword
  • get_suspensions: Get list of suspended stocks

Index Data

  • get_stock_industry: Get stock industry classification
  • get_sz50_stocks: Get SSE 50 Index constituents
  • get_hs300_stocks: Get CSI 300 Index constituents
  • get_zz500_stocks: Get CSI 500 Index constituents
  • get_index_constituents: Get any index constituents
  • list_industries: List all industries
  • get_industry_members: Get stocks in a specific industry

Macroeconomic Data

  • get_deposit_rate_data: Get deposit interest rates
  • get_loan_rate_data: Get loan interest rates
  • get_required_reserve_ratio_data: Get required reserve ratios
  • get_money_supply_data_month: Get monthly money supply data
  • get_money_supply_data_year: Get yearly money supply data

Date Tools & Analysis

  • get_latest_trading_date: Get the latest trading date
  • is_trading_day: Check if a date is a trading day
  • previous_trading_day: Get the previous trading day
  • next_trading_day: Get the next trading day
  • normalize_stock_code: Normalize stock code format
  • get_stock_analysis: Get stock analysis report

Usage Examples

Most tools support optional limit and format parameters for customizing output:

# Get CSI 300 index constituents in JSON format
get_index_constituents(index='hs300', format='json', limit=100)

# Search for stocks with code containing "600"
search_stocks(keyword='600', date='2025-01-10', limit=20)

# Get historical data for a stock in CSV format
get_historical_k_data(code='sh.600000', start_date='2024-01-01', end_date='2024-06-30', frequency='d', format='csv', limit=200)

# Get the previous trading day
previous_trading_day('2025-01-04')

# Normalize a stock code
normalize_stock_code('000001.SZ')  # -> 'sz.000001'

Data Update Schedule

Baostock data updates follow this schedule:

Daily Updates:

  • 17:30 on trading days: Daily K-line data
  • 18:00 on trading days: Adjustment factor data
  • 11:00 next day: Minute K-line data
  • 01:30 next day: Other financial report data
  • 17:30 Saturday: Weekly line data

Weekly Updates:

  • Monday afternoon: Index constituent updates (SSE 50, CSI 300, CSI 500)

Note that on trading days, data for the current day won't be available until after 17:30.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "a-share-mcp" '{"command":"uv","args":["--directory","C:\\Users\\YourName\\Projects\\a_share_mcp","run","python","mcp_server.py"],"transport":"stdio"}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "a-share-mcp": {
            "command": "uv",
            "args": [
                "--directory",
                "C:\\Users\\YourName\\Projects\\a_share_mcp",
                "run",
                "python",
                "mcp_server.py"
            ],
            "transport": "stdio"
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "a-share-mcp": {
            "command": "uv",
            "args": [
                "--directory",
                "C:\\Users\\YourName\\Projects\\a_share_mcp",
                "run",
                "python",
                "mcp_server.py"
            ],
            "transport": "stdio"
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later