Skip to main content

知乎开放平台的 Skill、CLI、MCP 与 OpenAPI 工具

Project description

zhihu-search

用一个命令调用知乎开放平台:搜索、直答、热榜、用户公开数据、PDF 解析、PPT 生成和 OAuth 辅助流程。

推荐按下面的顺序选择入口:

顺序 方式 适合场景
1 Skill 推荐;让 Agent 自动选择并执行正确的 CLI 命令
2 CLI 临时查询、脚本和调试
3 MCP 在 AI 客户端中高频、持续调用
4 OpenWebUI 少数需要 HTTP 工具服务器的场景

1. Skill(推荐)

安装 Skill:

npx skills add klarkxy/zhihu-search --skill zhihu-search

Skill 使用 uvx zhihu-search 执行任务,因此本机还需安装 uvuvx 会按需 创建隔离环境,无需长期安装 Python 包。

首次使用只需在自己的终端保存并验证 Access Secret:

uvx zhihu-search --save-token "<你的 Access Secret>"
uvx zhihu-search --probe

Access Secret 在 知乎开放平台个人中心创建。不要把它 发到聊天、截图或仓库。

2. CLI

不需要 Agent 时,直接用 uvx

uvx zhihu-search search "RAG 评测方法" --count 5
uvx zhihu-search ask "什么是 ReAct Agent?" --model thinking
uvx zhihu-search trending --limit 10

用户数据、PDF、PPT 和 OAuth 也都可以从 CLI 调用:

uvx zhihu-search user-contents --content-type article --limit 10
uvx zhihu-search pdf-upload "./report.pdf"
uvx zhihu-search pdf-create "file_..."
uvx zhihu-search ppt-create "https://zhuanlan.zhihu.com/p/123" --pages 12
uvx zhihu-search oauth-url "<app_id>" "<redirect_uri>"

所有业务命令支持 --format json。完整参数见:

uvx zhihu-search --help
uvx zhihu-search <command> --help

在仓库目录验证尚未发布的代码时,把命令开头改为 uvx --from . zhihu-search

3. MCP(高频使用)

MCP 默认使用 compact,只暴露三个常用工具和一个按需入口:

command: uvx
args:    zhihu-search serve --tools compact
配置 暴露内容
compact(默认) searchasktrendingother
full 全部 13 个工具
逗号 allowlist 严格只允许指定工具,例如 search,ask,pdf_status

other 管理当前 MCP 会话中的低频工具:

  • enable:展开 5 个用户数据工具、2 个 PDF 工具和 2 个 PPT 工具。
  • disable:收起这 9 个工具。
  • reset:恢复启动时的工具集合。

compactfull 下,other 可管理全部 9 个低频工具;自定义 allowlist 下,它只能管理列表里已经允许的低频工具,不能越过开关。

也可以用 ZHIHU_MCP_TOOLS 设置默认配置;命令行 --tools 优先于环境 变量。需要全部显式工具时运行:

uvx zhihu-search serve --tools full

通用 JSON 配置:

{
  "mcpServers": {
    "zhihu": {
      "command": "uvx",
      "args": ["zhihu-search", "serve", "--tools", "compact"]
    }
  }
}

客户端指南:

PDF 本机上传和 OAuth token 交换仍只允许 CLI/Python 执行,不会成为模型 可调用的工具。

4. OpenWebUI(少数场景)

只有需要 HTTP OpenAPI 工具服务器时才使用:

uvx zhihu-search openwebui \
  --host 0.0.0.0 --port 8000 --api-key "<服务访问口令>"

在 Open WebUI 中添加 External Tool Server:

  • URL:http://<server>:8000
  • Authentication:Bearer token

也可用 ZHIHU_OPENWEBUI_API_KEY 设置访问口令。未配置口令时服务不做 入站认证,只能用于 localhost 或受控私网。

更完整的安装说明见 setup/README.md

能力覆盖

能力 端点数 说明
搜索、直答、热榜 4 知乎搜索、全网搜索、直答、热榜
用户公开数据 5 创作、关注、近期收藏和收藏夹
PDF 解析 3 上传、创建任务、查询状态
PPT 生成 2 创建任务、查询状态
OAuth 辅助 2 授权 URL、授权码换 token

逐端点说明、官方文档差异和安全边界见 API_COVERAGE.md

凭证与诊断

Access Secret 读取顺序:

  1. ZHIHU_ACCESS_SECRET
  2. ~/.config/zhihu-search/credentials.json
uvx zhihu-search --check-token
uvx zhihu-search --probe
uvx zhihu-search --quota
uvx zhihu-search --clear-token

常见问题:

现象 处理
找不到 uvx 安装 uv 后重开终端
凭证不存在或失效 回个人中心创建并重新保存 Access Secret
Code=30002 到知乎开发者后台检查额度或接口权限
MCP 工具未出现 检查配置后重启客户端
PDF/PPT 长时间处理中 稍后再查状态,不要紧密轮询

Agent 代为安装和验证时,参见 AGENT_SETUP.md

开发

git clone https://github.com/klarkxy/zhihu-search
cd zhihu-search
uv sync --extra dev
uv run pytest
uv build

许可证

SATA License v2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zhihu_search-1.4.0.tar.gz (66.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zhihu_search-1.4.0-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file zhihu_search-1.4.0.tar.gz.

File metadata

  • Download URL: zhihu_search-1.4.0.tar.gz
  • Upload date:
  • Size: 66.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for zhihu_search-1.4.0.tar.gz
Algorithm Hash digest
SHA256 a25b21478e08e2af9c71f39946482669b7ce035214602b2a419ae587d5d933eb
MD5 609c9c4bea3e65cec46b264cf33caaec
BLAKE2b-256 8e2eac205f8d1c81e34d1c66c76e31758ab78008f26b03ee238442c39f6c52fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for zhihu_search-1.4.0.tar.gz:

Publisher: release.yml on klarkxy/zhihu-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zhihu_search-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: zhihu_search-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 48.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for zhihu_search-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33a683c5b62eda275482b90c6e734332aab3e5085c265d168a0853f9275634e9
MD5 ea424f30e2adf17da9c6c57c9ef8e011
BLAKE2b-256 0b87dd06dff86cb2fdf7ba2fc438c8a97597f9a675e46325f9fdfa73b22d7b0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for zhihu_search-1.4.0-py3-none-any.whl:

Publisher: release.yml on klarkxy/zhihu-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page