Skip to main content

jq-docs-mcp

聚宽(JoinQuant)公开 API 文档 MCP Server。把 20 个公开文档页里的函数签名、参数默认值、未来函数与避坑提示、策略对象、数据表和字段含义,整理成一个随包发布的本地 SQLite 知识库,让 AI 编程助手在离线状态下准确查文档。

查询全程只读本地数据库:零登录、零流量、运行时零网络请求。

核心特性

  • 20 页公开文档全覆盖:策略 API、JQData、股票/基金/期货/期权/债券/指数、因子库、Alpha101/Alpha191、技术指标、宏观、板块、组合优化等。
  • 零登录依赖:文档抓取走聚宽公开帮助页,不需要账号、Cookie 或 Token;服务运行时也不联网。
  • 参数默认值齐全:1,862 个参数中 1,084 个带默认值,755 个必填,直接给出可复制的调用形态。
  • 未来函数与避坑提示:140 条风险提示,覆盖未来函数、日期边界、接口弃用、配额限制、回测/研究环境差异、停牌与涨跌停等。
  • 中文语义字段反查:5,039 个表字段,支持「市盈率」「净资产收益率」「北向资金」这类中文说法直接定位到 valuation.pe_ratio、indicator.roe、STK_ML_QUOTA 等真实字段。
  • 渐进式返回,节省 Token:搜索只回 top-K 摘要卡片,并给出下一步该调哪个工具;完整文档、示例代码、全量字段按需展开。按 o200k 分词实测,search_jq_docs("市盈率") 约 256 tokens,而完整 get_function_doc("get_price") 约 2,489 tokens。
  • 双传输:默认 stdio,也支持 Streamable HTTP;同时提供 3 个 MCP Resources。

数据覆盖

以下数字来自知识库 meta 表实测(schema 2.0,构建于 2026-12-03):

维度 数量 说明
覆盖文档页 20 全部为聚宽公开帮助页
函数 / 方法 543 平台 API、JQData、因子、技术指标等
函数参数 1,862 带默认值 1,084,必填 755
风险提示 140 未来函数 33、通用 53、日期边界 21、弃用 16、配额 16、环境差异 6、交易状态 3
策略对象 10 Context、Portfolio、Position、Order、Trade 等
对象属性 99 对象字段与含义
数据表 195 宏观 115、财务 45、基金 10、债券 8、期权 7、板块 4 等
表字段 5,039 含字段类型、中文含义与说明
全文索引 5,787 行 FTS5,实体与索引一一对应
知识库体积 10.5 MiB 随 wheel 一起发布

函数按领域分布:

领域 函数数
Alpha191 / Alpha101 / 因子库 191 / 82 / 40
技术指标 99
核心策略 API 84
JQData 25
指数、期货、期权、基金、优化器等 22

快速安装

需要 Python 3.11+ 和 uv。

# 已发布到 PyPI 后
uvx jq-docs-mcp

# 从源码安装(当前仓库未发布到 PyPI 时使用)
git clone https://github.com/jimmer-code/jq-docs-mcp.git
cd jq-docs-mcp
uv tool install .

# 或者不安装,在仓库目录里直接运行
uvx --from . jq-docs-mcp

安装后命令为 jq-docs-mcp。如果使用 uvx,每次启动都会复用 uv 缓存,冷启动约 0.5 秒。

Claude Code

claude mcp add jq-docs -- uvx jq-docs-mcp

用源码安装时把命令换成 jq-docs-mcp:

claude mcp add jq-docs -- jq-docs-mcp

Cursor / Claude Desktop

在 MCP 配置文件中加入:

{
  "mcpServers": {
    "jq-docs": {
      "command": "uvx",
      "args": ["jq-docs-mcp"]
    }
  }
}

Cursor 的配置文件是 ~/.cursor/mcp.json;Claude Desktop 是 claude_desktop_config.json。Windows 上若找不到 uvx,把 command 写成 uvx.exe 的绝对路径。

Codex

在 ~/.codex/config.toml 中加入:

[mcp_servers.jq-docs]
command = "uvx"
args = ["jq-docs-mcp"]

通用 MCP JSON

任何支持 stdio MCP 的客户端都可以用同一份配置:

{
  "mcpServers": {
    "jq-docs": {
      "command": "uvx",
      "args": ["jq-docs-mcp"],
      "env": {}
    }
  }
}

命令行

# stdio(默认,供 MCP 客户端拉起)
jq-docs-mcp

# Streamable HTTP
jq-docs-mcp --transport http --host 127.0.0.1 --port 8000

# 使用自定义知识库(也可用环境变量 JQ_DB_PATH)
jq-docs-mcp --db /path/to/jq_knowledge.db

# 版本
jq-docs-mcp --version
参数 默认值 说明
--transport stdio stdio 或 http
--host 127.0.0.1 HTTP 监听地址
--port 8000 HTTP 监听端口
--db 包内数据库 自定义 jq_knowledge.db 路径
--version — 打印版本

MCP 工具

search_jq_docs

渐进式检索函数、策略对象、数据表和字段。命中函数名或对象名时直接返回完整文档;否则返回 top-K 摘要卡片,并附带下一步建议。

参数 类型 默认值 说明
query string 必填 中英文、错别字、自然语言均可
entity_type all / function / table / column / object all 限定实体类型
limit int 5 返回条数
search_jq_docs("市盈率", limit=3)
## Search Results: `市盈率` — top 3
1. **valuation.pe_ratio_lyr** `column` — 市盈率(PE)
   `column` · `col:valuation.pe_ratio_lyr` → `get_table_schema("valuation", column_filter="pe_ratio_lyr")`
2. **valuation.pe_ratio** `column` — 市盈率(PE, TTM)
   `column` · `col:valuation.pe_ratio` → `get_table_schema("valuation", column_filter="pe_ratio")`
3. **valuation.code** `column` — 股票代码
   `column` · `col:valuation.code` → `get_table_schema("valuation", column_filter="code")`

get_function_doc

返回一个函数或策略对象的完整文档:签名、参数表(含类型、是否必填、默认值)、风险提示、返回类型和官方来源链接。

参数 类型 默认值 说明
name string 必填 函数名或对象名,如 get_price、Context
include_examples bool false 是否附带示例代码
get_function_doc("get_price")
get_function_doc("Context")
get_function_doc("get_bars", include_examples=True)

找不到时会给出最接近的函数名建议,并用 get_function_doc("建议名") 指路。

get_table_schema

数据表字段反查与分页浏览。支持中文别名(如「资产负债表」→ balance、「估值表」→ valuation);column_filter 会同时匹配字段名、中文含义和字段说明。

参数 类型 默认值 说明
table_name string 必填 表名或常用别名
column_filter string / null null 按字段名或含义过滤
limit int 25 每页条数,取值 1–200
offset int 0 偏移量
get_table_schema("valuation", column_filter="市盈")

输出节选(字段说明已截断):

# Table: `valuation` — 估值数据(市值、市盈率、市净率等)
**Columns:** showing 1–2 of 2 matching `市盈`

| Column | Type | Meaning | Description |
|---|---|---|---|
| pe_ratio | - | 市盈率(PE, TTM) | 每股市价为每股收益的倍数…… |
| pe_ratio_lyr | - | 市盈率(PE) | 以上一年度每股盈利计算的静态市盈率…… |

剩余字段会用 get_table_schema("valuation", limit=25, offset=25) 提示翻页。limit 超过 200 会按 200 截断。

list_catalog

列出文档分区、数据表或策略对象目录,适合先看全貌再检索。

参数 类型 默认值 说明
scope sections / tables / objects sections 目录类型
filter string / null null 按关键词过滤条目
limit int 40 返回条数,取值 1–200
list_catalog("tables", filter="财务")
list_catalog("objects")

MCP Resources

URI 内容
jq://function/{name} 单个函数的完整文档,含示例代码(等价于 include_examples=true)
jq://table/{table_name} 单张表的完整字段表(最多 50 行)
jq://meta JSON 元数据:构建时间、文档页数、各类实体数量、内容哈希

jq://meta 适合让客户端自检知识库版本,例如比较 built_at 或 content_sha256 是否变化。

Streamable HTTP

jq-docs-mcp --transport http --host 127.0.0.1 --port 8000

服务端点为 http://127.0.0.1:8000/mcp。用 FastMCP 客户端连接:

import asyncio
from fastmcp import Client

async def main():
    async with Client("http://127.0.0.1:8000/mcp") as client:
        tools = await client.list_tools()
        print([tool.name for tool in tools])
        result = await client.call_tool("search_jq_docs", {"query": "市盈率"})
        print(result.content[0].text)

asyncio.run(main())

对外提供服务时建议放在反向代理之后,并自行加认证;服务本身不内置鉴权。

Docker

docker build -t jq-docs-mcp .
docker run --rm -p 8000:8000 jq-docs-mcp

镜像内默认执行:

jq-docs-mcp --transport http --host 0.0.0.0 --port 8000

容器监听 0.0.0.0:8000,端点同样是 /mcp。知识库已打进镜像,运行时不访问外网。

更新知识库与质量体检

知识库重新构建需要联网抓取聚宽公开文档,并安装可选的抓取依赖:

uv sync --extra scraper

# 重新抓取并生成 src/jq_docs_mcp/data/jq_knowledge.db
uv run python -m jq_docs_mcp.scraper.build_db --refresh

# 只重建部分页面(页面名见 src/jq_docs_mcp/scraper/pages.py)
uv run python -m jq_docs_mcp.scraper.build_db --refresh --pages api JQDatadoc stock

# 指定缓存目录和输出路径
uv run python -m jq_docs_mcp.scraper.build_db \
  --cache-dir /tmp/jq-raw \
  --db-path /tmp/jq_knowledge.db \
  --refresh

build_db 会输出 JSON 统计(实体数量、content_sha256、integrity_check 等),并写入 meta 表。抓取缓存默认放在仓库外的 exp/raw_20/,不会进入 wheel 或 sdist。

质量体检:

# 12 项数据库质量门:完整性、数量、命名空间、FTS、meta 等
uv run python -m jq_docs_mcp.scraper.audit_db

# 单元与集成测试(tests/)
uv run pytest -q

audit_db 全部通过时最后一行是 PASS,失败返回非零退出码,可直接接进 CI。

开发仓库还带一套 v1/v2 检索对照基准:eval/queries.jsonl(70 条查询,覆盖精确函数、错别字、混合意图、中文表/字段、参数与避坑、v2 扩展六类场景)和 eval/run_retrieval_eval.py。脚本会从仓库 main 分支取出 v1.0.0 的 server.py 和数据库作为基线,逐条回放两版检索链路,输出 Recall@1、Recall@5、MRR@10、零结果率、平均 Token 与延迟;没有 v1 历史产物时无法运行。eval/ 不随 wheel 或 sdist 发布。

开源协议

MIT License,见 LICENSE。

免责声明

  • 数据抓取自聚宽(JoinQuant)公开帮助文档,文档版权归聚宽所有;本项目仅做本地索引与检索,与聚宽无隶属或合作关系。
  • 文档内容可能随官方更新而滞后,交易接口、字段与权限请以聚宽官网和实际账户权限为准。
  • 本项目只提供文档查询,不构成任何投资建议;据此做出的策略与交易决策风险自负。

Metadata

Release files for jq-docs-mcp 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jq-docs-mcp 2.0.0
File Size Uploaded Provenance Actions
jq_docs_mcp-2.0.0.tar.gz 2.6 MB With provenance Details for jq_docs_mcp-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jq-docs-mcp 2.0.0
File Interpreter ABI Platform Actions
jq_docs_mcp-2.0.0-py3-none-any.whl Python 3 none any Details for jq_docs_mcp-2.0.0-py3-none-any.whl

Total release size: 5.2 MB

Release files / jq_docs_mcp-2.0.0.tar.gz

Download URL jq_docs_mcp-2.0.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
1a9f7a996071ae9aba7cbf20f2a38b146bc6b82e95c1c85a0995b47eb5006f06
BLAKE2b-256 checksum
How to use checksums
02dad77e4fc85203567aff3c42be95f5f670a53e00b39eb73bc75778e5039ef6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / jq_docs_mcp-2.0.0-py3-none-any.whl

Download URL jq_docs_mcp-2.0.0-py3-none-any.whl
Size 2.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe3ea3d4b671cec1209684878ba3cbb5eda5b6301ed89abe1d39e773863aad2
BLAKE2b-256 checksum
How to use checksums
cf82db7f6976f22208a80970061bc9dd09cb4337076deac20758273f6cf9e7f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for jq-docs-mcp 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jq_docs_mcp-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page