BYR Docs 搜索

搜索 BYR Docs 中教材、资料与试题的 API / MCP。

POST https://search.byrdocs.org/api/search MCP https://search.byrdocs.org/mcp

试一试

示例:
curl 命令

                    
结果将显示在这里

HTTP API

仅支持 POST,请求体为 JSON。跨域开放(Access-Control-Allow-Origin: *)。

请求参数

字段类型说明
keywordstring?关键词。普通词做分词检索;ISBN / 32 位 MD5 做精确匹配;留空则不过滤。
typeenum?book / doc / test / all,默认 all
jmespathstring?JMESPath 表达式,作用于关键词结果数组做结构化查询 / 投影。
limitnumber?返回条数上限,默认 20,最大 100。
shortenboolean?true 时把结果中的链接转换为 go.byrdocs.org 短链后返回(见短链接)。需带 Authorization: Bearer <token>。默认 false

示例

curl -X POST https://search-byrdocs.youx.am/api/search \
  -H 'content-type: application/json' \
  -d '{"keyword":"高等数学","type":"book","limit":5}'

响应

{
  "total": 42,
  "results": [
    {
      "type": "book",
      "id": "<md5>",
      "url": "https://byrdocs.org/files/<md5>.pdf",
      "data": {
        "title": "高等数学",
        "authors": ["同济大学数学系"],
        "isbn": ["..."],
        "filetype": "pdf"
      }
    }
  ]
}

叠加 JMESPath 时,先执行关键词 / 类型过滤,再对结果数组求值;total 为求值后数组的长度,results 为其前 limit 项。非法表达式返回 400

短链接

shorten: true 且请求头带 Authorization: Bearer <token>tokengo.byrdocs.org 短链服务的 token),则在搜索、JMESPath、limit 全部完成后,把每个结果的 url(及 test 的 data.wiki.url)并发转换为短链后返回,不返回原始链接。相同链接自动去重;转换前的链接已带 filename / f 统计参数,短链跳转仍计入下载统计;缺少 token 或个别链接转换失败时,该条回退为原始链接,整体仍返回 200

curl -X POST https://search-byrdocs.youx.am/api/search \
  -H 'content-type: application/json' \
  -H 'authorization: Bearer <token>' \
  -d '{"keyword":"高等数学","type":"book","shorten":true}'

JMESPath 查询

JMESPath 是一种 JSON 查询语言,作用于关键词 / 类型过滤后的结果数组——数组每一项形如 { type, id, url, data }。可用它做过滤、字段投影、排序、计数等。执行顺序:keyword / type 过滤 → JMESPath 求值 → limit 截断,total 为求值后数组长度。

语法约定

写法含义
data.title用点号访问嵌套字段
'book'字符串字面量用单引号
`2020`数字 / 布尔 / null 等用反引号包裹
[?…]过滤:对数组每一项求布尔表达式,保留为真的项
[]展开数组,配合 .field 做投影
{a: x, b: y}multiselect:把每项重组为新对象
@当前元素(整个数组或迭代项)
|管道:把左侧结果作为右侧表达式的新输入

示例

常用函数:lengthcontainsstarts_withends_withsort_bymax_by / min_byreversekeysto_number。完整规范见 JMESPath Specification

MCP

无状态 Streamable HTTP,端点 https://search-byrdocs.youx.am/mcp,公开免认证。

Claude Desktop 配置

{
  "mcpServers": {
    "byrdocs-search": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://search-byrdocs.youx.am/mcp"]
    }
  }
}

支持 Streamable HTTP 的客户端可直接填入端点 URL;其余客户端可用 mcp-remote 桥接。

工具 search_files

参数与 HTTP API 同构:keyword / type / jmespath / limit / shorten,返回 JSON 文本。工具描述中已内嵌 item 结构与 JMESPath 用法,便于模型直接构造查询。jmespath 写法见上方 JMESPath 查询

使用 shorten 需在连接时通过 HTTP 头 Authorization: Bearer <token> 提供 go.byrdocs.org 短链服务 token,语义同上方短链接

npx mcp-remote https://search-byrdocs.youx.am/mcp --header "Authorization: Bearer <token>"

数据结构

每个搜索结果是一个 item,字段以 TypeScript 类型给出如下——datatype 分为 book / doc / test 三种,点击标签切换查看:

{
  type: "book"
  id: string            // 文件 MD5
  url: string            // 下载链接(已含统计参数)
  data: {
    title: string
    authors: string[]
    translators?: string[]
    edition?: string
    publisher?: string
    publish_year?: string
    isbn: string[]
    filetype: "pdf"
    filesize?: number       // 字节
  }
}