Skip to main content
Glama
xueqiu

xueqiu

by CNQQC

Xueqiu MCP Server

Bring Xueqiu market quotes, financials, capital flow, and community forum data into any MCP-compatible client (Claude Code, Claude Desktop, Cherry Studio, etc.).

Covers A-shares / Hong Kong stocks / US stocks, plus indices, ETFs, and convertible bonds. 22 tools in total.

Features

  • LLM-oriented output: Xueqiu's raw API returns fields and values like ncf_from_oa, 1.7205417189091E11. This project translates 600+ financial fields into Chinese, converts amounts into "hundred million yuan / ten thousand yuan", and transposes multi-period financial reports into "metric × reporting period" Markdown tables that models can read directly, with far lower token consumption than the raw JSON.

  • Hong Kong stock fields validated: Xueqiu's HK stock financial reports use highly abbreviated codes like tto, plobtx, ploashh. The Chinese mappings in this project were reverse-confirmed using Tencent Holdings' actual financial figures and accounting identities (e.g., tto - slgcost == gp, ta - tlia == teqy, nocf + ninvcf + nfcgcf == icdccceq), not guessed.

  • Forum works: The community API is blocked by risk control on the xueqiu.com main domain. This project uses api.xueqiu.com (used by the Xueqiu app) and can read stock discussions, announcements/news, hot posts, and comments without login. Post body HTML is cleaned into plain text.

  • Zero configuration: Anonymous tokens are fetched and renewed automatically. Ready to use after installation — no Cookie, no registration needed.

  • Screener metrics synced in real time: The screener's metric list is read directly from Xueqiu's official metadata API, so this project won't go stale when Xueqiu adjusts its metrics.

  • Handles concurrency on small machines: Tiered TTL cache + concurrent request coalescing + HTTP/2 multiplexing. In real-world testing, repeated queries are 15.8x faster, requests to Xueqiu drop by 90%, and resident memory is about 75MB. See Performance & Concurrency.

Related MCP server: mcp-stock-quote

Installation

uv venv --python 3.12 && uv pip install -e .

If you want 2~3x faster parsing of large JSON (e.g., 500 K-line bars), you can install with orjson:

uv pip install -e ".[fast]"

Connecting to Claude Code

Run this in the project directory:

claude mcp add xueqiu -- "$(pwd)/.venv/bin/xueqiu-mcp"

Connecting to Claude Desktop / Other Clients

On macOS you can run the install script directly. It automatically waits for Claude to fully quit (a running Claude will overwrite the file with its in-memory config), backs up the original config, and only adds or modifies the xueqiu entry without touching your other existing MCP servers:

./install-claude-desktop.sh

To configure manually, edit the config file (Claude Desktop uses ~/Library/Application Support/Claude/claude_desktop_config.json), and replace command with the absolute path of .venv/bin/xueqiu-mcp:

{
  "mcpServers": {
    "xueqiu": {
      "command": "/绝对路径/.venv/bin/xueqiu-mcp"
    }
  }
}

If the project path contains spaces or Chinese characters, be sure to use the full absolute path string — don't split it into args.

Tool Overview

Search & Quotes

Tool

Description

search_stock

Search instruments by name / pinyin / code

get_quote

Real-time quotes, supports multiple instruments and cross-market queries in one call

get_kline

Historical K-line, optionally with PE/PB/PS/market cap per bar

get_minute

Current-day or last-5-day minute chart (auto-sampled to ~40 points)

Financials

Tool

Description

get_financial_statement

Income statement / balance sheet / cash flow statement / key metrics, works for A-shares, HK, and US stocks

get_business_breakdown

Revenue breakdown: revenue, cost, and gross margin by product and region

Company Profile

Tool

Description

get_company_profile

Company intro, actual controller, headcount, industry and concept sectors

get_shareholders

Shareholder count trend, top 10 circulating shareholders, institutional holdings

get_dividends

Historical dividends, bonus issues, and ex-dividend/ex-rights dates

Capital Flow

Tool

Description

get_capital_flow

Daily net inflow of main capital + intraday large/medium/small order breakdown

get_margin_trading

Margin trading balance and net buying

get_block_trades

Block trade details (including buy/sell brokerages)

Market & Screening

Tool

Description

screen_stocks

Stock screener — filter and sort by valuation / financial / quote metrics

list_screener_metrics

List all metrics supported by the screener (official metadata)

list_industries

Shenwan industry classification

get_hot_stocks

Xueqiu popularity ranking

Community Forum

Tool

Description

get_stock_discussions

Stock discussion board, sortable by popularity or time

get_stock_news

Stock news / company announcement feed

get_hot_posts

Xueqiu homepage hot discussions

search_posts

Site-wide post search

get_post

Full post text + hot comments

get_user_posts

A user's posting activity

Code Formats

Market

Format

Example

A-shares

SH/SZ/BJ + 6 digits, or just 6 digits

SH600519, 600519, 000001

HK stocks

5 digits, zero-padded

00700, 9988

US stocks

Letter codes

AAPL, BRK.B

You can also pass Chinese names directly (e.g., "贵州茅台"); the tool will search first, then fetch data.

Usage Examples

Just tell the model:

  • "What are Moutai's recent financial metrics?"

  • "Screen A-shares with P/E below 20x, dividend yield above 3%, and market cap above 100 billion"

  • "See what people on Xueqiu are saying about CATL"

  • "Compare Kweichow Moutai and Wuliangye's gross margin and ROE over the past three years"

  • "Any announcements from Tencent today?"

Screener filter syntax:

filters="pettm:0~20,dy_l:3~,mc:100000000000~"

That means P/E 0~20x, dividend yield above 3%, market cap above 100 billion. Boundaries can be left blank for no limit. Metric names can be looked up with list_screener_metrics; the _l suffix means the latest reporting period.

Most features work anonymously. A few endpoints that require a logged-in session (e.g., user profile details) can be configured via environment variables:

export XUEQIU_COOKIE="从浏览器开发者工具复制的完整 Cookie"

In the MCP config, write it as:

{
  "mcpServers": {
    "xueqiu": {
      "command": "/绝对路径/.venv/bin/xueqiu-mcp",
      "env": { "XUEQIU_COOKIE": "..." }
    }
  }
}

Deploying to a Server

By default it starts over stdio, with one process serving one client. To serve many users and clients from a single machine, switch to streamable-http:

XUEQIU_TRANSPORT=streamable-http XUEQIU_HOST=0.0.0.0 XUEQIU_PORT=8000 \
  .venv/bin/xueqiu-mcp

Clients connect to http://<address>:8000/mcp. This mode is stateless by default — the server keeps no session per client, memory doesn't grow with connection count, and it's easy to scale horizontally with multiple replicas.

Xueqiu's API has no official open platform. Add your own authentication and rate limiting before exposing it publicly, and don't offload other people's request volume onto Xueqiu.

Performance & Concurrency

All resource parameters can be lowered via environment variables to fit small-memory machines:

Environment Variable

Default

Description

XUEQIU_MAX_CONNECTIONS

32

Connection pool limit

XUEQIU_MAX_CONCURRENCY

32

Max in-flight upstream requests, also acts as rate limiting on the Xueqiu side

XUEQIU_CACHE_MB

16

Response cache memory cap, measured in parsed objects — set it and it roughly uses that much

XUEQIU_CACHE

1

Set to 0 to disable the cache

XUEQIU_HTTP2

1

Set to 0 to disable HTTP/2

XUEQIU_TIMEOUT

15

Per-request timeout (seconds)

The cache is tiered by endpoint: quotes 3 seconds, K-line 30 seconds, financials 1 hour, company profile 6 hours, industry classification and screener metrics 24 hours. When concurrent requests hit the same data, only one request goes out and the rest wait for its result.

Real-World Measurements

The numbers below come from real-world testing (hitting the real Xueqiu API during A-share trading hours, ~1,500 requests total):

Scenario

Result

Measurement conditions

Cold-call latency for 22 tools

Median 51.0 ms

3 cold samples per tool, take median, then median across tools

After cache hit

Median 1.84 ms

9 hot samples per tool

This project's own overhead

Median 4.4 ms

End-to-end minus upstream wall clock, including MCP encode/decode and formatting

Repeated queries (old vs. new A/B)

15.8x faster, upstream requests -90%

Same instrument queried 10 times in a row

Concurrency 32

Zero failures, P50 86 ms

Stepped load 1→4→8→16→32, 193 requests total

The bottleneck is not this project: stock.xueqiu.com has a median of 40.4 ms per request, api.xueqiu.com (community) 84.8 ms, while this project itself accounts for only 4.4 ms.

The gains come mainly from caching and request coalescing, followed by HTTP/2 multiplexing during cold-connection bursts. Pure pipeline throughput (cache disabled) is roughly on par with before optimization — don't expect it to get faster from that.

tests/bench.py hits a local mock upstream (mock numbers, not representative of real performance), its purpose is regression detection rather than performance claims:

.venv/bin/python tests/bench.py            # 默认模拟 30ms 网络延迟
MOCK_RTT=0 .venv/bin/python tests/bench.py # 零延迟,放大纯代码开销

How to read the results: focus on whether upstream request count and peak concurrency match expectations. The QPS figure is heavily affected by the mock server's own scheduling overhead; QPS dropping as concurrency rises on the local loopback is an artifact of the test environment, not a problem with the code under test.

The cache layer has another set of zero-network regression tests covering request coalescing, cancellation propagation, LRU eviction, and byte accounting:

.venv/bin/python tests/test_cache.py

Known Limitations

  • The concurrency gate is not a rate limiter. It only constrains "in-flight requests", not requests per unit time. Based on measured latency, 32 concurrent connections theoretically allows ~700 req/s toward Xueqiu. Please control your own pacing on the calling side.

  • Real-world testing only validated up to 32 concurrent connections; there's no real data for higher concurrency.

  • XUEQIU_CACHE_MB is an optimistic estimate; measured real memory growth is about 1.2~1.9x that value (higher for small-entry scenarios). For small-memory machines, 8 is recommended.

Testing

.venv/bin/python tests/test_mcp_e2e.py

This script connects to the server over stdio as a real MCP client, lists all tools and calls each one live (including Chinese-name resolution, indices/ETFs/convertible bonds, and error messages for various parameter validations), then prints the pass count.

Project Structure

src/xueqiu_mcp/
├── client.py        HTTP 客户端:令牌续期、连接池与 HTTP/2、并发闸门、风控识别
├── cache.py         响应缓存:分级 TTL、LRU 内存上限、并发请求合并
├── symbols.py       代码规范化(600519 → SH600519)
├── resolve.py       代码解析,中文名走搜索兜底
├── fields.py        A 股字段中文映射表
├── fields_intl.py   港股 / 美股字段映射表(经会计恒等式校验)
├── screener.py      选股器指标元数据(读雪球官方接口并缓存)
├── formatting.py    数值单位换算、Markdown 表格、HTML 正文清洗
├── server.py        MCP 工具注册
└── tools/
    ├── quote.py     行情、K 线、分时
    ├── finance.py   财务报表、主营构成
    ├── f10.py       公司资料、股东、分红
    ├── capital.py   资金流、两融、大宗交易
    ├── market.py    选股器、行业、人气榜
    └── social.py    论坛:讨论、公告新闻、热帖、评论

Notes

  • All data comes from Xueqiu's public APIs; quotes may be delayed and do not constitute investment advice.

  • This project is for learning and research only. Please comply with Xueqiu's terms of service and avoid high-frequency requests.

  • Xueqiu's API is not an official open platform; fields and availability may change at any time.

Available Tools

22 tools
get_block_tradesC

大宗交易明细:成交价、折溢价率与买卖双方营业部。

Args: symbol: 股票代码 count: 取最近几笔,最多 50

Inputs: symbol (required), count. Returns: result

get_business_breakdownA

主营构成:按产品和地区拆分的收入、成本与毛利率(仅 A 股)。

Args: symbol: 股票代码 count: 取最近几个报告期,最多 8

Inputs: symbol (required), count. Returns: result

get_capital_flowA

主力资金流向:每日净流入走势,以及当日大中小单的成交结构。

Args: symbol: 股票代码 days: 回溯天数,接口最多提供约 20 个交易日

Inputs: symbol (required), days. Returns: result

get_company_profileB

公司资料:简介、主营、实控人、员工数、所属行业与概念板块(仅 A 股)。

Args: symbol: 股票代码

Inputs: symbol (required). Returns: result

get_dividendsA

历年分红送配方案与除权除息日(仅 A 股)。

Args: symbol: 股票代码 count: 取最近几次,最多 50

Inputs: symbol (required), count. Returns: result

get_financial_statementA

财务报表与核心指标,按「指标 × 报告期」排版便于跨期对比。

A 股 / 港股 / 美股都支持,字段已翻译成中文并换算单位。

Args: symbol: 股票代码 statement: indicator 主要指标 / income 利润表 / balance 资产负债表 / cash_flow 现金流量表 report_type: all 全部报告期 / Q1 一季报 / Q2 中报 / Q3 三季报 / Q4 年报 count: 取最近几期,最多 20 detail: 为 true 时输出全部科目,否则只给核心科目

Inputs: symbol (required), count, detail, statement, +1 more. Returns: result

get_hot_postsC

雪球首页热门讨论,用于了解当前全市场关注的话题。

Args: count: 条数,最多 30

Inputs: count. Returns: result

get_hot_stocksB

雪球人气榜:按用户关注热度排序的股票及热度变化。

Args: market: CN A股 / HK 港股 / US 美股 limit: 取前多少名,最多 100

Inputs: limit, market. Returns: result

get_klineB

历史 K 线,可选带上每根 K 线的 PE / PB / PS / 市值。

Args: symbol: 股票代码 period: 周期,1m/5m/15m/30m/60m/120m/day/week/month/quarter/year count: 最近多少根 K 线,最多 500 adjust: 复权方式,before 前复权 / after 后复权 / normal 不复权 with_valuation: 为 true 时附带估值指标,适合做估值分位分析

Inputs: symbol (required), count, adjust, period, +1 more. Returns: result

get_margin_tradingA

融资融券余额、融资买入与净买入(仅两融标的)。

Args: symbol: 股票代码 days: 回溯交易日数,最多 90

Inputs: symbol (required), days. Returns: result

get_minuteA

当日或近 5 日分时走势(自动抽样到约 40 个点)。

Args: symbol: 股票代码 period: 1d 当日 / 5d 近五日

Inputs: symbol (required), period. Returns: result

get_postA

按帖子 ID 取全文及热门评论。ID 可从讨论列表或热帖列表中获得。

Args: post_id: 帖子数字 ID,或完整帖子链接 with_comments: 是否附带评论 comment_count: 评论条数,最多 30

Inputs: post_id (required), comment_count, with_comments. Returns: result

get_quoteA

实时行情快照:价格、涨跌、成交、市值、PE/PB、股息率等。

支持一次查多个标的,用逗号分隔,也支持 A 股 / 港股 / 美股 / 指数 / ETF / 可转债。

Args: symbols: 一个或多个代码,如 "600519" 或 "600519,00700,AAPL" detail: 为 true 时返回全部行情字段(含质押比例、商誉占比等)

Inputs: symbols (required), detail. Returns: result

get_shareholdersB

股东结构:股东户数走势、十大流通股东、基金/社保/QFII 等机构持仓(仅 A 股)。

Args: symbol: 股票代码 top_n: 展示前几大流通股东,最多 20

Inputs: symbol (required), top_n. Returns: result

get_stock_discussionsA

个股讨论区帖子:作者、粉丝数、点赞评论数与正文。

想了解市场情绪、散户与大 V 观点时使用。

Args: symbol: 股票代码 sort: hot 按热度(高赞高评论)/ time 按最新 count: 条数,最多 30 page: 页码

Inputs: symbol (required), page, sort, count. Returns: result

get_stock_newsB

个股新闻或公告流。

Args: symbol: 股票代码 kind: news 新闻 / notice 公司公告 count: 条数,最多 30 page: 页码

Inputs: symbol (required), kind, page, count. Returns: result

get_user_postsA

查看某位雪球用户的发帖动态,用于跟踪特定作者的观点。

Args: user_id: 雪球用户数字 ID(见帖子链接 xueqiu.com/<user_id>/<post_id>) count: 条数,最多 30 page: 页码

Inputs: user_id (required), page, count. Returns: result

list_industriesA

申万行业分类列表,返回的 encode 可作为 screen_stocks 的 industry 参数。

Args: market: CN / HK / US

Inputs: market. Returns: result

list_screener_metricsA

列出选股器支持的全部指标及其中文名(雪球官方元数据)。

在使用 screen_stocks 前调用,以确认指标名的正确写法。 建议总是带上 keyword:不带时会列出全部指标,返回内容大约是带 keyword 时的 9 倍。

Args: market: CN / HK / US keyword: 按中文名或指标名过滤,如「市盈」「roe」。省略则返回全部指标

Inputs: market, keyword. Returns: result

screen_stocksA

选股器:按估值、财务、行情等指标筛选并排序股票。

filters 写成 指标:下限~上限,多条用逗号分隔,边界可留空。 例:pettm:0~20,dy_l:3~,mc:100000000000~ 表示市盈率 0~20 倍、 股息率 3% 以上、市值 1000 亿以上。 指标名请先用 list_screener_metrics 查询;_l 后缀表示取最新报告期。

Args: market: CN A股 / HK 港股 / US 美股 order_by: 排序指标,如 mc 总市值、pct 涨跌幅、pettm 市盈率 order: desc 降序 / asc 升序 limit: 每页条数,最多 100 page: 页码 filters: 筛选条件串 industry: 行业代码,用 list_industries 查询 exchange: A 股范围,sh_sz 沪深 / sh / sz / bj columns: 额外展示的指标,逗号分隔;注意会排除该指标为空的标的

Inputs: page, limit, order, market, +5 more. Returns: result

search_postsA

全站搜索雪球帖子。

Args: query: 关键词,如「宇树」「红利策略」 count: 条数,最多 30 page: 页码

Inputs: query (required), page, count. Returns: result

search_stockA

按名称、拼音或代码搜索股票,返回雪球标准代码。

当用户给的是公司名称而不是代码,且需要确认具体标的时使用。

Args: query: 名称 / 拼音首字母 / 代码,如「茅台」「gzmt」「600519」 limit: 返回条数,最多 20

Inputs: query (required), limit. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 22 tools

    Disambiguation5/5

    每个工具都针对明确不同的数据或操作,如行情、K线、财务、股东、资金流、讨论区、帖子等,没有重叠或模糊地带。即使类似概念如热门讨论和热门股票,也明确区分了对象。

    Naming Consistency5/5

    全部工具采用动词+名词的蛇形命名,如get_开头和search_/screen_/list_开头,风格统一,模式可预测。没有混合camelCase或异常命名。

    Tool Count4/5

    22个工具略多于理想的3-15范围,但考虑到服务器覆盖雪球平台的海量数据(行情、财务、社交、选股等),每个工具都有独立用途,无冗余,数量合理。

    Completeness5/5

    工具集覆盖了雪球的主要功能域,包括实时行情、历史K线、财务分析、股东结构、资金流向、新闻公告、讨论区、帖子搜索、选股器以及元数据查询,没有明显缺口。

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to query real-time A-share stock data, including quotes, fund flows, sector flows, and K-line history, without needing an API key.
      5
      20
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI assistants to fetch realtime stock quotes, fundamentals, and search for stocks across A-share, Hong Kong, and US markets without requiring API keys.
      5
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to pull live China A-share market data through 24 tools spanning real-time quotes, K-lines, five-level order books, financials, money flow, dragon-tiger lists, sector and valuation data, convertible bonds, ETFs, IPOs, macro indicators, and factor-based stock screening. Five of the tools work with no API key, while the rest require a paid key.
      577 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to query real-time and historical market data across A-shares, Hong Kong, US stocks, funds, futures, and options, including K-lines, technical indicators (MA/MACD/BOLL/KDJ/RSI), sector and capital-flow data. It also provides composite analysis tools, presets, and prompts for stock screening, multi-stock comparison, portfolio monitoring, and market overviews.
      140 npm
      ISC