qlib-sync
This server lets an AI assistant inspect, update, and query a local Qlib China A-share dataset.
Check data status (
cn_status): see the latest local trading date, dataset size, available stock pools, and whether a newer community release exists; optionally skip the network check withoffline=true.Install or update data (
cn_update): download, verify, and swap in the latest community release; returns quickly if current, restores previous data on failure, and reports new trading days and listed/delisted symbols.Run health checks (
cn_health_check): validate the local dataset's structure and perform a real Qlib read, returningok, errors, and checks.Fetch daily price bars (
cn_get_prices): get daily data for up to 20 symbols over a date range, choosing fields such as OHLC, vwap, volume, amount, change, and factor, with raw or adjusted prices and a row cap.List stock pool members (
cn_list_pool): list members of pools such asall,csi100,csi300,csi500,csi800,csi1000,csiall, or local pools on a given or latest date.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@qlib-sync check my Qlib A-share dataset health and show today's index pool"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
qlib-sync
Website: randyy179.github.io/qlib-sync
One command to install and keep current a local Qlib China A-share dataset, and an MCP server so AI assistants can read it.
pip install qlib-sync
qlib-sync cn updateOr without installing anything first: uvx --python 3.12 qlib-sync cn update.
(--python 3.12 because pyqlib publishes wheels up to Python 3.12; uv fetches that Python
for you if needed. With pip, use Python 3.10 to 3.12.)

That installs the daily community release from
chenditc/investment_data into
~/.qlib/qlib_data/cn_data, the location Qlib reads by default. Run the same command again
any time; when the data is already current it finishes in about a second.
Why not just wget and tar?
Qlib's README points A-share users to the community release with a wget and tar one-liner.
That works until it doesn't:
An interrupted or truncated download extracts into a half-written dataset, or fails after the old one has already been overwritten.
Upstream republishes releases. In November 2026 a data error was found and corrected (investment_data#163) and releases were republished under the same date. A date check alone never sees the fix.
Every check downloads 550 MB, even when nothing changed.
The investment_data README itself describes a careful manual process: download the release
manifest, check the archive with qlib/validate_archive.py --require-publishable, then
extract. qlib-sync runs that validator itself, on every update: an unmodified copy (from
commit 68fdc66,
Apache-2.0) checks the manifest before the download and the archive after it. A test suite
feeds the same malformed releases to the upstream script and to qlib-sync and requires the same
verdict, and a weekly job flags any change upstream makes to the validator.
On top of that, qlib-sync skips the download when nothing changed, pins the manifest and the archive to one release tag, extracts beside the live data and swaps it in with rollback (rather than extracting on top of the existing folder), and picks up republished releases.
qlib-sync treats the dataset like a production system:
Step | What happens |
Check | Pins the latest release by tag and reads its 500-byte manifest. Already current: done, nothing downloaded. |
Download | Resumes interrupted downloads; shows progress; optional mirror for slow links to GitHub. |
Verify | investment_data's own |
Stage | Extracts next to the active dataset; refuses downgrades. |
Swap | Renames the new dataset into place, then runs a real Qlib read. |
Roll back | Any failure after the swap moves the previous dataset back. |
Report | New trading days, newly listed and delisted symbols. |
Verification is required by default. If the manifest is missing, unreadable, or rejected by
the validator, the update stops and your data stays as it was. --allow-unverified installs
anyway when the manifest cannot be verified, and the result and install record are then marked
unverified; a package whose checksum disagrees with a valid manifest is always refused.
The checks catch broken, truncated, tampered, or malformed packages. They cannot catch wrong
values inside a correctly published release (like the one in #163); for that, keep a rollback
copy with --keep-backup.
Related MCP server: go-stock-mcp
Commands
qlib-sync status # every local Qlib dataset at a glance
qlib-sync cn status # local date, pools, and whether a newer release exists
qlib-sync cn update # install or update (add --json for machine-readable output)
qlib-sync cn health-check # structure checks plus a real Qlib read
qlib-sync cn restore --list # rollback backups; restore --yes switches backUseful options for cn update:
Option | Effect |
| Install somewhere other than |
| Download through a prefix-style GitHub proxy such as |
| Keep the previous dataset for one rollback |
| Carry a custom stock pool in |
| Reinstall even when the dates match |
| Install when the manifest cannot be verified (marked unverified; checksum mismatches are still refused) |
The update replaces the whole cn_data folder. Anything you added there is lost unless you
pass it with --protect.
Mirrors
From mainland China, GitHub downloads can be slow or fail. Pass a mirror and qlib-sync downloads the package through it while still reading the manifest from GitHub directly when it can, so the checksum does not depend on the mirror. Mirrors are third-party services; qlib-sync does not endorse any of them.
Python
from qlib_sync import update_cn, status_cn, health_check_cn
result = update_cn() # raises qlib_sync.UpdateError on failure; data unchanged
print("\n".join(result.summary_lines()))
print(result.new_trading_days, result.added_symbols)Use it from your AI assistant
qlib-sync includes an MCP server, the open standard most AI
tools use to call local tools. Any MCP client that can start a local command works, whichever
model it runs: Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, or a local model. The server
runs on your machine and reads the dataset there; there is no service to host and nothing
leaves your computer. It is listed in the MCP Registry
as io.github.randyy179/qlib-sync.
Every client needs the same two things: the command uvx and the arguments qlib-sync mcp.
Client | How to add qlib-sync |
Claude Desktop | Download |
Claude Code |
|
OpenAI Codex CLI |
|
Cursor | The JSON below, in |
Gemini CLI | The JSON below, in |
Qwen Code | The JSON below, in |
Tencent CodeBuddy, ByteDance Trae, Alibaba Tongyi Lingma | MCP settings, add a server manually, paste the JSON below |
Cherry Studio | Settings, MCP servers, add: type STDIO, command |
VS Code (Copilot agent mode) |
|
{ "mcpServers": { "qlib-sync": { "command": "uvx", "args": ["--python", "3.12", "qlib-sync", "mcp"] } } }Menu names and file locations change between versions; check your client's MCP documentation if a path above has moved. Tested with Claude Code and OpenAI Codex CLI.
Web chat apps such as ChatGPT connect only to remote MCP servers over the internet, so they cannot start this local server.
Set QLIB_SYNC_DATA_DIR to use a dataset outside ~/.qlib/qlib_data/cn_data, and
QLIB_SYNC_MIRROR to download through a mirror.
Tool | Does |
| Local latest date, pools, and whether an update is available |
| Install or update (safe to call: failures restore the previous data) |
| Structure checks plus a real Qlib read |
| Daily bars for up to 20 symbols; real traded prices by default, adjusted on request |
| Members of csi300, csi500, and other pools on a date |
Then ask things like "Is my A-share data current? What did Moutai close at over the last
week?" Symbols accept 600519, SH600519, or 600519.SH.

skills/qlib-sync/SKILL.md teaches an assistant when to update,
how to read each failure, and the price conventions. It uses the open SKILL.md format that
Claude, Codex, and other agents load from their skills folder; any assistant can also simply
be pointed at the file.
Daily updates
A run that finds nothing new costs one small request, so schedule it daily. See docs/scheduling.md for cron and launchd examples.
Data and credits
All data comes from chenditc/investment_data
(Apache-2.0). qlib-sync only downloads the public release; it does not host or redistribute
data. Prices follow Qlib's convention: $close is adjusted and the real price is
$close / $factor.
qlib-sync is an independent project, not affiliated with Microsoft or the Qlib team.
Supported: macOS and Linux, Python 3.10 to 3.12 (pyqlib does not publish wheels for newer
versions yet; uvx picks a compatible Python automatically).
Development
uv venv && uv pip install -e ".[dev]"
.venv/bin/python -m pytestLicense
MIT
Available Tools
5 toolscn_get_pricesARead-only
Daily bars for up to 20 A-share symbols between start and end (YYYY-MM-DD, inclusive; end defaults to the latest date).
fields: any of open, high, low, close, vwap, volume, amount, change, factor
(default open, high, low, close, volume, change). change is the daily return as a
fraction (0.01 = +1%). price_basis="raw" gives real traded prices and share volume;
"adjusted" gives Qlib's split- and dividend-adjusted series. Rows are capped by max_rows.
Inputs: start (required), symbols (required), end, fields, +2 more. Returns: object
cn_health_checkARead-only
Validate the local data's structure and perform a real Qlib read; returns ok, errors, checks.
Inputs: no named parameters. Returns: object
cn_list_poolARead-only
Members of a stock pool on a date (default: the latest date). Pools: all, csi100, csi300, csi500, csi800, csi1000, csiall, plus any local pools; cn_status lists what exists.
Inputs: date, pool. Returns: object
cn_statusARead-only
Report the local A-share data's latest trading date, size, and stock pools, and whether the community release has newer data (set offline=True to skip the network check).
Inputs: offline. Returns: object
cn_updateAIdempotent
Install or update the local A-share data from the community release.
Returns quickly when already current. Otherwise downloads about 550 MB, checks it with
the dataset maintainers' own validator, and swaps it in; this takes roughly a minute.
A release that cannot be verified is refused, and on any failure the previous data is
restored. The result lists new trading days, listed/delisted symbols, and `verified`.
Inputs: force. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose: data update, price query, health validation, pool listing, and status reporting. There is no overlap or ambiguity between them.
All tools use a consistent 'cn_' prefix, but the second part mixes verb_noun (get_prices, list_pool) with noun phrases (health_check, status) and a bare verb (update). This is mostly consistent and still readable.
Five tools are well-scoped for an A-share data sync and access server. Each tool earns its place by covering a unique part of the data lifecycle.
The surface covers update, validation, status, price retrieval, and pool membership, which are the core operations. Minor gaps exist, such as querying a trading calendar or non-price data fields, but these are not critical for the stated purpose.
Maintenance
Related MCP Connectors
China A-share data for AI agents: 57 read-only tools plus 6 tools for your own watchlist.
China A-share market data for research, backtesting and AI agents via MCP.
China A-share screening, filings, holdings, flows and calendars as agent tools.
Provide access to Chinese stock market data including historical prices, real-time data, news, and…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables users to query Chinese A-share stock data, including stock basics, historical prices, financial reports, and macroeconomic indicators.1MIT
- AlicenseNot gradedqualityCmaintenanceProvides read-only access to Chinese A-share stock market data such as quotes, K-lines, financials, capital flows, news, and research reports via a stdio MCP server for DeepSeek Harness and other MCP clients.2GPL 3.0
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Chinese A-share market data — real-time quotes, K-lines, order books, financials, fund flows, dragon-tiger lists, sectors, convertible bonds, macro data, and factor screening — through 24 tools, five of which require no API key. It can be used via a hosted endpoint with no installation or self-hosted locally over stdio.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to read cited stock news, earnings, and filings; screen stocks; run point-in-time backtests; check portfolios; and query a local dashboard across US, A-share, and Hong Kong markets.198 PyPI1MIT