yuque-ai-mcp 2.7.9 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/README_CN.md +15 -11
- package/SKILL.md +21 -1
- package/dist/common/register-tools.d.ts +1 -0
- package/dist/common/register-tools.js +3 -0
- package/dist/common/register-tools.js.map +1 -1
- package/dist/common/web-request.d.ts +1 -1
- package/dist/common/web-request.js.map +1 -1
- package/dist/web-doc/get-doc.d.ts +13 -0
- package/dist/web-doc/get-doc.js +129 -0
- package/dist/web-doc/get-doc.js.map +1 -0
- package/dist/web-doc/get-toc.d.ts +12 -0
- package/dist/web-doc/get-toc.js +88 -0
- package/dist/web-doc/get-toc.js.map +1 -0
- package/dist/web-doc/index.d.ts +6 -0
- package/dist/web-doc/index.js +10 -0
- package/dist/web-doc/index.js.map +1 -0
- package/dist/web-doc/list-docs.d.ts +13 -0
- package/dist/web-doc/list-docs.js +109 -0
- package/dist/web-doc/list-docs.js.map +1 -0
- package/dist/web-doc/list-repos.d.ts +14 -0
- package/dist/web-doc/list-repos.js +111 -0
- package/dist/web-doc/list-repos.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://
|
|
2
|
+
<img src="https://raw.githubusercontent.com/yehuoshun/yuque-ai-mcp/main/assets/banner.png" width="800" alt="yuque-ai-mcp" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">yuque-ai-mcp</h1>
|
|
6
6
|
<p align="center">
|
|
7
|
-
<b>
|
|
7
|
+
<b>67 fine-grained MCP tools for the full Yuque OpenAPI</b>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
<a href="https://github.com/yehuoshun/yuque-ai-mcp"><img src="https://img.shields.io/badge/version-2.
|
|
11
|
+
<a href="https://github.com/yehuoshun/yuque-ai-mcp"><img src="https://img.shields.io/badge/version-2.8.0-blue" alt="version" /></a>
|
|
12
12
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
|
|
13
|
-
<a href="https://github.com/yehuoshun/yuque-ai-skills"><img src="https://img.shields.io/badge/skills-
|
|
13
|
+
<a href="https://github.com/yehuoshun/yuque-ai-skills"><img src="https://img.shields.io/badge/skills-67%20guides-orange" alt="skills" /></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
<p align="center">
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
|
-
A full-featured Yuque (语雀) MCP Server built on the [Model Context Protocol](https://modelcontextprotocol.io/). Provides
|
|
22
|
+
A full-featured Yuque (语雀) MCP Server built on the [Model Context Protocol](https://modelcontextprotocol.io/). Provides 67 fine-grained tools across 16 domains — every Yuque OpenAPI endpoint as a dedicated tool.
|
|
23
23
|
|
|
24
24
|
## Why
|
|
25
25
|
|
|
26
|
-
- **19 →
|
|
26
|
+
- **19 → 67 tools** — 3x more coverage than the official [yuque-mcp-server](https://github.com/yuque/yuque-mcp-server)
|
|
27
27
|
- **Dual transport** — stdio + HTTP SSE, shared registry, zero downtime on reload
|
|
28
28
|
- **Modular architecture** — 15 domains, barrel exports, single source of truth registry
|
|
29
29
|
- **Full API coverage** — group, recycle, upload, statistics, versions, boards — all the missing pieces
|
|
30
|
-
- **[Skill layer](https://github.com/yehuoshun/yuque-ai-skills)** —
|
|
30
|
+
- **[Skill layer](https://github.com/yehuoshun/yuque-ai-skills)** — 67 usage guides for AI agents
|
|
31
31
|
|
|
32
32
|
## Table of Contents
|
|
33
33
|
|
|
@@ -76,9 +76,9 @@ npm run dev:http # HTTP SSE mode (http://localhost:3099)
|
|
|
76
76
|
| **rss** | 3 | Source list, fetch + dedup + save, schedule analysis |
|
|
77
77
|
| **crawler** | 4 | Fetch, CSS extract, dedup save, schedule analysis |
|
|
78
78
|
| **kv** | 4 | Get, set, delete, list — incremental sharding, 250KB/doc limit |
|
|
79
|
-
| **Total** | **
|
|
79
|
+
| **Total** | **67** | |
|
|
80
80
|
|
|
81
|
-
### All
|
|
81
|
+
### All 67 Tools
|
|
82
82
|
|
|
83
83
|
| Tool | Domain | Description |
|
|
84
84
|
|------|--------|-------------|
|
|
@@ -152,13 +152,13 @@ See [SKILL.md](SKILL.md) or [yuque-ai-skills](https://github.com/yehuoshun/yuque
|
|
|
152
152
|
|
|
153
153
|
| Feature | Official yuque-mcp-server | yuque-ai-mcp |
|
|
154
154
|
|---------|--------------------------|--------------|
|
|
155
|
-
| Tools | 19 | **
|
|
155
|
+
| Tools | 19 | **67** |
|
|
156
156
|
| Granularity | Coarse | **Fine-grained** (1 tool / endpoint) |
|
|
157
157
|
| Group, Recycle, Upload, Statistics | ❌ | ✅ |
|
|
158
158
|
| Versions, Diff, Cross-book Copy | ❌ | ✅ |
|
|
159
159
|
| Transport | stdio only | **stdio + HTTP SSE** |
|
|
160
160
|
| Config | Env var | **config.json** (token + cookie) |
|
|
161
|
-
| Skill Layer | ❌ | ✅
|
|
161
|
+
| Skill Layer | ❌ | ✅ 67 guides |
|
|
162
162
|
|
|
163
163
|
## Architecture
|
|
164
164
|
|
package/README_CN.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/yehuoshun/yuque-ai-mcp/main/assets/banner.png" width="800" alt="yuque-ai-mcp" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
<p align="center">
|
|
2
6
|
<h1 align="center">yuque-ai-mcp</h1>
|
|
3
7
|
<p align="center">
|
|
4
|
-
<b>
|
|
8
|
+
<b>67 个细粒度 MCP 工具,覆盖语雀 OpenAPI 全部能力</b>
|
|
5
9
|
</p>
|
|
6
10
|
</p>
|
|
7
11
|
|
|
8
12
|
<p align="center">
|
|
9
|
-
<a href="https://github.com/yehuoshun/yuque-ai-mcp"><img src="https://img.shields.io/badge/版本-2.
|
|
13
|
+
<a href="https://github.com/yehuoshun/yuque-ai-mcp"><img src="https://img.shields.io/badge/版本-2.8.0-blue" alt="version" /></a>
|
|
10
14
|
<a href="LICENSE"><img src="https://img.shields.io/badge/许可-MIT-green" alt="license" /></a>
|
|
11
|
-
<a href="https://github.com/yehuoshun/yuque-ai-skills"><img src="https://img.shields.io/badge/skills-
|
|
15
|
+
<a href="https://github.com/yehuoshun/yuque-ai-skills"><img src="https://img.shields.io/badge/skills-67%20指导-orange" alt="skills" /></a>
|
|
12
16
|
</p>
|
|
13
17
|
|
|
14
18
|
<p align="center">
|
|
@@ -17,15 +21,15 @@
|
|
|
17
21
|
|
|
18
22
|
---
|
|
19
23
|
|
|
20
|
-
基于 [Model Context Protocol](https://modelcontextprotocol.io/) 的语雀全功能 MCP Server。
|
|
24
|
+
基于 [Model Context Protocol](https://modelcontextprotocol.io/) 的语雀全功能 MCP Server。67 个工具,16 个域——每个语雀 OpenAPI 端点一个专用工具。
|
|
21
25
|
|
|
22
26
|
## 为什么选这个
|
|
23
27
|
|
|
24
|
-
- **19 →
|
|
28
|
+
- **19 → 67 工具** — 比官方 [yuque-mcp-server](https://github.com/yuque/yuque-mcp-server) 多 3 倍覆盖
|
|
25
29
|
- **双传输模式** — stdio + HTTP SSE,共享注册中心,修改无需重启
|
|
26
|
-
- **模块化架构** —
|
|
30
|
+
- **模块化架构** — 16 个域,barrel export,唯一注册中心
|
|
27
31
|
- **完整 API 覆盖** — 团队、回收站、上传、统计、版本、画板——补全官方缺失
|
|
28
|
-
- **[Skill 层](https://github.com/yehuoshun/yuque-ai-skills)** —
|
|
32
|
+
- **[Skill 层](https://github.com/yehuoshun/yuque-ai-skills)** — 67 个 AI Agent 使用指导
|
|
29
33
|
|
|
30
34
|
## 目录
|
|
31
35
|
|
|
@@ -75,9 +79,9 @@ npm run dev:http # HTTP SSE 模式 (http://localhost:3099)
|
|
|
75
79
|
| **rss** | 3 | 数据源列表、抓取+去重+写入、定时策略分析 |
|
|
76
80
|
| **crawler** | 4 | 抓取、CSS 提取、去重写入、定时策略分析 |
|
|
77
81
|
| **kv** | 4 | 增删查列——增量分片,单文档 250KB 上限 |
|
|
78
|
-
| **合计** | **
|
|
82
|
+
| **合计** | **67** | |
|
|
79
83
|
|
|
80
|
-
### 全部
|
|
84
|
+
### 全部 67 个工具
|
|
81
85
|
|
|
82
86
|
| 工具 | 域 | 说明 |
|
|
83
87
|
|------|--------|-------------|
|
|
@@ -151,13 +155,13 @@ npm run dev:http # HTTP SSE 模式 (http://localhost:3099)
|
|
|
151
155
|
|
|
152
156
|
| 功能 | 官方 yuque-mcp-server | yuque-ai-mcp |
|
|
153
157
|
|---------|--------------------------|--------------|
|
|
154
|
-
| 工具数 | 19 | **
|
|
158
|
+
| 工具数 | 19 | **67** |
|
|
155
159
|
| 粒度 | 粗粒度 | **细粒度**(1 端点 = 1 工具) |
|
|
156
160
|
| 团队、回收站、上传、统计 | ❌ | ✅ |
|
|
157
161
|
| 版本、Diff、跨库复制 | ❌ | ✅ |
|
|
158
162
|
| 传输模式 | 仅 stdio | **stdio + HTTP SSE** |
|
|
159
163
|
| 配置 | 环境变量 | **config.json**(token + cookie) |
|
|
160
|
-
| Skill 层 | ❌ | ✅
|
|
164
|
+
| Skill 层 | ❌ | ✅ 67 指导 |
|
|
161
165
|
|
|
162
166
|
## 架构
|
|
163
167
|
|
package/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# yuque-ai-mcp
|
|
2
2
|
|
|
3
|
-
语雀全功能 MCP Server,
|
|
3
|
+
语雀全功能 MCP Server,67 个工具 / 16 个域。当用户提到「语雀」「yuque」「知识库」「文档」「团队」等关键词时触发。
|
|
4
4
|
|
|
5
5
|
## 触发场景
|
|
6
6
|
|
|
@@ -135,6 +135,14 @@
|
|
|
135
135
|
| `yuque_get_book_stacks` | 获取知识库分组(书架)列表 |
|
|
136
136
|
| `yuque_get_editor_center` | 获取个人编辑中心全景数据 |
|
|
137
137
|
|
|
138
|
+
### web_doc(4 工具,Cookie 态)
|
|
139
|
+
| 工具 | 说明 |
|
|
140
|
+
|------|------|
|
|
141
|
+
| `yuque_web_get_doc` | Cookie 态读文档正文(含 body/content),不受会员过期限流 |
|
|
142
|
+
| `yuque_web_list_docs` | Cookie 态列文档列表,更丰富的字段 |
|
|
143
|
+
| `yuque_web_list_repos` | Cookie 态列知识库列表,含权限信息 |
|
|
144
|
+
| `yuque_web_get_toc` | Cookie 态获取知识库目录 TOC |
|
|
145
|
+
|
|
138
146
|
### kv(4 工具)
|
|
139
147
|
| 工具 | 说明 |
|
|
140
148
|
|------|------|
|
|
@@ -149,6 +157,18 @@
|
|
|
149
157
|
|
|
150
158
|
完整错误码及处理策略见 `references/api/errors.md`。
|
|
151
159
|
|
|
160
|
+
## 🎯 降级策略(长文档 Fallback)
|
|
161
|
+
|
|
162
|
+
**触发场景**:`yuque_get_doc` 读取超长文档(>1MB 或超时)时 MCP stdio 可能撑爆缓冲区。
|
|
163
|
+
|
|
164
|
+
**自动降级链路**:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
yuque_get_doc ──(失败)──→ yuque_export_doc → 读本地文件 → 返回内容
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
执行方式:Agent 检测到 get_doc 失败 → 自动调用 `yuque_export_doc` + 本地 read 替代,不回退到直接 curl 语雀 API。
|
|
171
|
+
|
|
152
172
|
## 配置
|
|
153
173
|
|
|
154
174
|
```json
|
|
@@ -14,6 +14,7 @@ import { rssTools } from "../rss/index.js";
|
|
|
14
14
|
import { crawlerTools } from "../crawler/index.js";
|
|
15
15
|
import { mineTools } from "../mine/index.js";
|
|
16
16
|
import { kvTools } from "../kv/index.js";
|
|
17
|
+
import { webDocTools } from "../web-doc/index.js";
|
|
17
18
|
/** 所有工具(按域展开,唯一真实来源) */
|
|
18
19
|
export const ALL_TOOLS = [
|
|
19
20
|
...userTools,
|
|
@@ -31,6 +32,7 @@ export const ALL_TOOLS = [
|
|
|
31
32
|
...crawlerTools,
|
|
32
33
|
...mineTools,
|
|
33
34
|
...kvTools,
|
|
35
|
+
...webDocTools,
|
|
34
36
|
];
|
|
35
37
|
/** 按域统计工具数 */
|
|
36
38
|
export const DOMAIN_COUNTS = {
|
|
@@ -49,6 +51,7 @@ export const DOMAIN_COUNTS = {
|
|
|
49
51
|
crawler: crawlerTools.length,
|
|
50
52
|
mine: mineTools.length,
|
|
51
53
|
kv: kvTools.length,
|
|
54
|
+
web_doc: webDocTools.length,
|
|
52
55
|
};
|
|
53
56
|
/** 将 JSON Schema 转为 Zod raw shape 并注册到 McpServer */
|
|
54
57
|
export function registerAllTools(server) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tools.js","sourceRoot":"","sources":["../../src/common/register-tools.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAA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-doc — Cookie 态读文档正文
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/docs/{id}?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回文档完整内容(含 content/body 正文),支持 markdown/lake/lakesheet 格式
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 get_doc 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流(429)
|
|
9
|
+
* - 返回更丰富的字段(54 个 vs v2 的 ~30 个)
|
|
10
|
+
* - 含 abilities/joinToken/masterUser 等额外信息
|
|
11
|
+
*/
|
|
12
|
+
import type { McpTool } from "../common/types.js";
|
|
13
|
+
export declare const webDocGet: McpTool;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/get-doc — Cookie 态读文档正文
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/docs/{id}?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回文档完整内容(含 content/body 正文),支持 markdown/lake/lakesheet 格式
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 get_doc 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流(429)
|
|
9
|
+
* - 返回更丰富的字段(54 个 vs v2 的 ~30 个)
|
|
10
|
+
* - 含 abilities/joinToken/masterUser 等额外信息
|
|
11
|
+
*/
|
|
12
|
+
import { isErrorResult } from "../common/api-client.js";
|
|
13
|
+
import { webRequest } from "../common/web-request.js";
|
|
14
|
+
import { check, requiredString } from "../common/validate.js";
|
|
15
|
+
const DOC_REFERER = "https://www.yuque.com/";
|
|
16
|
+
/**
|
|
17
|
+
* 格式化文档详情,提取关键字段
|
|
18
|
+
*/
|
|
19
|
+
function formatDocDetail(data) {
|
|
20
|
+
const body = data.body || "";
|
|
21
|
+
const content = data.content || "";
|
|
22
|
+
const bodyAsl = data.body_asl || "";
|
|
23
|
+
const contentHtml = data.content_html || "";
|
|
24
|
+
const format = data.format || "";
|
|
25
|
+
// 根据 format 确定正文内容和类型
|
|
26
|
+
// lake → content 字段是 HTML
|
|
27
|
+
// lakesheet → body 字段是 JSON
|
|
28
|
+
// markdown → body 字段是 Markdown
|
|
29
|
+
let bodyContent = "";
|
|
30
|
+
let bodyType = "none";
|
|
31
|
+
if (content) {
|
|
32
|
+
bodyContent = content;
|
|
33
|
+
bodyType = "html";
|
|
34
|
+
}
|
|
35
|
+
else if (body) {
|
|
36
|
+
bodyContent = body;
|
|
37
|
+
bodyType = format === "lakesheet" ? "lake_json" : "raw";
|
|
38
|
+
}
|
|
39
|
+
else if (bodyAsl) {
|
|
40
|
+
bodyContent = bodyAsl;
|
|
41
|
+
bodyType = "asl";
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
id: data.id,
|
|
45
|
+
type: data.type,
|
|
46
|
+
sub_type: data.sub_type,
|
|
47
|
+
slug: data.slug,
|
|
48
|
+
title: data.title,
|
|
49
|
+
format,
|
|
50
|
+
body: bodyContent,
|
|
51
|
+
body_type: bodyType,
|
|
52
|
+
word_count: data.word_count,
|
|
53
|
+
description: data.description,
|
|
54
|
+
cover: data.cover,
|
|
55
|
+
status: data.status,
|
|
56
|
+
public: data.public,
|
|
57
|
+
read_status: data.read_status,
|
|
58
|
+
view_status: data.view_status,
|
|
59
|
+
draft_version: data.draft_version,
|
|
60
|
+
comments_count: data.comments_count,
|
|
61
|
+
likes_count: data.likes_count,
|
|
62
|
+
read_count: data.read_count,
|
|
63
|
+
created_at: data.created_at,
|
|
64
|
+
updated_at: data.updated_at,
|
|
65
|
+
content_updated_at: data.content_updated_at,
|
|
66
|
+
published_at: data.published_at,
|
|
67
|
+
first_published_at: data.first_published_at,
|
|
68
|
+
book: data.book
|
|
69
|
+
? { id: data.book.id, name: data.book.name, slug: data.book.slug }
|
|
70
|
+
: { id: data.book_id },
|
|
71
|
+
user: data.user
|
|
72
|
+
? { id: data.user.id, login: data.user.login, name: data.user.name }
|
|
73
|
+
: { id: data.user_id },
|
|
74
|
+
abilities: data.abilities,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export const webDocGet = {
|
|
78
|
+
name: "yuque_web_get_doc",
|
|
79
|
+
description: "Cookie-based: Get full document detail with body/content. " +
|
|
80
|
+
"Supports markdown/lake/lakesheet formats. " +
|
|
81
|
+
"Returns richer fields than v2 get_doc (54 fields including abilities, joinToken, etc.). " +
|
|
82
|
+
"No membership required, no Token rate limiting. " +
|
|
83
|
+
"GET /api/docs/{id}?book_id={book_id}. " +
|
|
84
|
+
"详见 references/api/doc_api.md",
|
|
85
|
+
inputSchema: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
id: { type: "string", description: "Document ID (numeric, required)" },
|
|
89
|
+
book_id: { type: "string", description: "Repository ID (numeric, required)" },
|
|
90
|
+
raw: { type: "boolean", description: "Return raw full JSON (default false, returns trimmed fields)" },
|
|
91
|
+
},
|
|
92
|
+
required: ["id", "book_id"],
|
|
93
|
+
},
|
|
94
|
+
async handler(args) {
|
|
95
|
+
// @validate
|
|
96
|
+
const __v = check(requiredString(args?.id, "id"), requiredString(args?.book_id, "book_id"));
|
|
97
|
+
if (__v)
|
|
98
|
+
return __v;
|
|
99
|
+
const id = Number(args?.id);
|
|
100
|
+
const bookId = Number(args?.book_id);
|
|
101
|
+
if (!id || !bookId) {
|
|
102
|
+
return {
|
|
103
|
+
content: [{ type: "text", text: JSON.stringify({ error: "id 和 book_id 必须为有效数字 / id and book_id must be valid numbers" }, null, 2) }],
|
|
104
|
+
isError: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const raw = args?.raw;
|
|
108
|
+
const url = `https://www.yuque.com/api/docs/${id}?book_id=${bookId}`;
|
|
109
|
+
const result = await webRequest(url, { referer: DOC_REFERER });
|
|
110
|
+
if (isErrorResult(result))
|
|
111
|
+
return result;
|
|
112
|
+
const data = result?.data;
|
|
113
|
+
if (!data) {
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: "text", text: JSON.stringify({ error: "NO_DATA" }, null, 2) }],
|
|
116
|
+
isError: true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (raw) {
|
|
120
|
+
return {
|
|
121
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
content: [{ type: "text", text: JSON.stringify(formatDocDetail(data), null, 2) }],
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=get-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-doc.js","sourceRoot":"","sources":["../../src/web-doc/get-doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,SAAS,eAAe,CAAC,IAA6B;IACpD,MAAM,IAAI,GAAI,IAAI,CAAC,IAAe,IAAI,EAAE,CAAC;IACzC,MAAM,OAAO,GAAI,IAAI,CAAC,OAAkB,IAAI,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAI,IAAI,CAAC,QAAmB,IAAI,EAAE,CAAC;IAChD,MAAM,WAAW,GAAI,IAAI,CAAC,YAAuB,IAAI,EAAE,CAAC;IACxD,MAAM,MAAM,GAAI,IAAI,CAAC,MAAiB,IAAI,EAAE,CAAC;IAE7C,sBAAsB;IACtB,0BAA0B;IAC1B,4BAA4B;IAC5B,+BAA+B;IAC/B,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,QAAQ,GAAG,MAAM,CAAC;IACtB,IAAI,OAAO,EAAE,CAAC;QACZ,WAAW,GAAG,OAAO,CAAC;QACtB,QAAQ,GAAG,MAAM,CAAC;I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E,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SAC3F,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/get-toc — Cookie 态获取知识库目录
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/catalog_nodes?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回知识库完整目录树(扁平数组,通过 uuid 父子关系导航)
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 get_toc 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回结构相同,兼容现有 TOC 处理逻辑
|
|
10
|
+
*/
|
|
11
|
+
import type { McpTool } from "../common/types.js";
|
|
12
|
+
export declare const webTocGet: McpTool;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/get-toc — Cookie 态获取知识库目录
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/catalog_nodes?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回知识库完整目录树(扁平数组,通过 uuid 父子关系导航)
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 get_toc 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回结构相同,兼容现有 TOC 处理逻辑
|
|
10
|
+
*/
|
|
11
|
+
import { isErrorResult } from "../common/api-client.js";
|
|
12
|
+
import { webRequest } from "../common/web-request.js";
|
|
13
|
+
import { check, requiredString } from "../common/validate.js";
|
|
14
|
+
const TOC_REFERER = "https://www.yuque.com/";
|
|
15
|
+
/**
|
|
16
|
+
* 格式化 TOC 节点
|
|
17
|
+
*/
|
|
18
|
+
function formatTocItem(item) {
|
|
19
|
+
return {
|
|
20
|
+
uuid: item.uuid,
|
|
21
|
+
type: item.type,
|
|
22
|
+
title: item.title,
|
|
23
|
+
url: item.url,
|
|
24
|
+
doc_id: item.doc_id,
|
|
25
|
+
slug: item.slug,
|
|
26
|
+
level: item.level,
|
|
27
|
+
depth: item.depth,
|
|
28
|
+
open_window: item.open_window,
|
|
29
|
+
visible: item.visible,
|
|
30
|
+
prev_uuid: item.prev_uuid,
|
|
31
|
+
sibling_uuid: item.sibling_uuid,
|
|
32
|
+
child_uuid: item.child_uuid,
|
|
33
|
+
parent_uuid: item.parent_uuid,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export const webTocGet = {
|
|
37
|
+
name: "yuque_web_get_toc",
|
|
38
|
+
description: "Cookie-based: Get repo TOC tree (flat array, navigable via uuid/parent_uuid/child_uuid). " +
|
|
39
|
+
"Same structure as v2 get_toc, but no membership required. " +
|
|
40
|
+
"GET /api/catalog_nodes?book_id={book_id}. " +
|
|
41
|
+
"详见 references/api/toc_api.md",
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: {
|
|
45
|
+
book_id: { type: "string", description: "Repository ID (numeric, required)" },
|
|
46
|
+
raw: { type: "boolean", description: "Return raw full JSON (default false, returns trimmed fields)" },
|
|
47
|
+
},
|
|
48
|
+
required: ["book_id"],
|
|
49
|
+
},
|
|
50
|
+
async handler(args) {
|
|
51
|
+
// @validate
|
|
52
|
+
const __v = check(requiredString(args?.book_id, "book_id"));
|
|
53
|
+
if (__v)
|
|
54
|
+
return __v;
|
|
55
|
+
const bookId = Number(args?.book_id);
|
|
56
|
+
const raw = args?.raw;
|
|
57
|
+
if (!bookId) {
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: "text", text: JSON.stringify({ error: "book_id 必须为有效数字 / book_id must be a valid number" }, null, 2) }],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const url = `https://www.yuque.com/api/catalog_nodes?book_id=${bookId}`;
|
|
64
|
+
const result = await webRequest(url, { referer: TOC_REFERER });
|
|
65
|
+
if (isErrorResult(result))
|
|
66
|
+
return result;
|
|
67
|
+
const res = result;
|
|
68
|
+
const items = res?.data ?? [];
|
|
69
|
+
if (raw) {
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: "text", text: JSON.stringify(items, null, 2) }],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: JSON.stringify({
|
|
79
|
+
total: items.length,
|
|
80
|
+
book_id: bookId,
|
|
81
|
+
data: items.map(formatTocItem),
|
|
82
|
+
}, null, 2),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=get-toc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-toc.js","sourceRoot":"","sources":["../../src/web-doc/get-toc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,SAAS,aAAa,CAAC,IAA6B;IAClD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC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,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QAE/D,IAAI,aAAa,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;QAEzC,MAAM,GAAG,GAAG,MAAmD,CAAC;QAChE,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;QAE9B,IAAI,GAAG,EAAE,CAAC;YACR,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aAC3E,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,KAAK,EAAE,KAAK,CAAC,MAAM;wBACnB,OAAO,EAAE,MAAM;wBACf,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC;qBAC/B,EAAE,IAAI,EAAE,CAAC,CAAC;iBACZ;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { webDocGet } from "./get-doc.js";
|
|
2
|
+
export { webDocList } from "./list-docs.js";
|
|
3
|
+
export { webRepoList } from "./list-repos.js";
|
|
4
|
+
export { webTocGet } from "./get-toc.js";
|
|
5
|
+
import type { McpTool } from "../common/types.js";
|
|
6
|
+
export declare const webDocTools: McpTool[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { webDocGet } from "./get-doc.js";
|
|
2
|
+
export { webDocList } from "./list-docs.js";
|
|
3
|
+
export { webRepoList } from "./list-repos.js";
|
|
4
|
+
export { webTocGet } from "./get-toc.js";
|
|
5
|
+
import { webDocGet } from "./get-doc.js";
|
|
6
|
+
import { webDocList } from "./list-docs.js";
|
|
7
|
+
import { webRepoList } from "./list-repos.js";
|
|
8
|
+
import { webTocGet } from "./get-toc.js";
|
|
9
|
+
export const webDocTools = [webDocGet, webDocList, webRepoList, webTocGet];
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web-doc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAc,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/list-docs — Cookie 态列文档列表
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/docs?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回指定知识库下的文档列表,支持分页
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 list_docs 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回更丰富的字段(含 draft_version/editor_meta/read_status 等)
|
|
10
|
+
* - 可获取 doc_versions 补充版本信息
|
|
11
|
+
*/
|
|
12
|
+
import type { McpTool } from "../common/types.js";
|
|
13
|
+
export declare const webDocList: McpTool;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/list-docs — Cookie 态列文档列表
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/docs?book_id={book_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回指定知识库下的文档列表,支持分页
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 list_docs 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回更丰富的字段(含 draft_version/editor_meta/read_status 等)
|
|
10
|
+
* - 可获取 doc_versions 补充版本信息
|
|
11
|
+
*/
|
|
12
|
+
import { isErrorResult } from "../common/api-client.js";
|
|
13
|
+
import { webRequest } from "../common/web-request.js";
|
|
14
|
+
import { check, requiredString, positiveInt, maxValue } from "../common/validate.js";
|
|
15
|
+
const DOC_REFERER = "https://www.yuque.com/";
|
|
16
|
+
/**
|
|
17
|
+
* 格式化文档摘要列表
|
|
18
|
+
*/
|
|
19
|
+
function formatDocSummary(item) {
|
|
20
|
+
return {
|
|
21
|
+
id: item.id,
|
|
22
|
+
type: item.type,
|
|
23
|
+
sub_type: item.sub_type,
|
|
24
|
+
slug: item.slug,
|
|
25
|
+
title: item.title,
|
|
26
|
+
format: item.format,
|
|
27
|
+
status: item.status,
|
|
28
|
+
public: item.public,
|
|
29
|
+
word_count: item.word_count,
|
|
30
|
+
description: item.description,
|
|
31
|
+
cover: item.cover,
|
|
32
|
+
read_status: item.read_status,
|
|
33
|
+
draft_version: item.draft_version,
|
|
34
|
+
comments_count: item.comments_count,
|
|
35
|
+
likes_count: item.likes_count,
|
|
36
|
+
read_count: item.read_count,
|
|
37
|
+
created_at: item.created_at,
|
|
38
|
+
updated_at: item.updated_at,
|
|
39
|
+
content_updated_at: item.content_updated_at,
|
|
40
|
+
published_at: item.published_at,
|
|
41
|
+
book: item.book
|
|
42
|
+
? { id: item.book.id, name: item.book.name }
|
|
43
|
+
: { id: item.book_id },
|
|
44
|
+
user: item.user
|
|
45
|
+
? { id: item.user.id, login: item.user.login }
|
|
46
|
+
: { id: item.user_id },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export const webDocList = {
|
|
50
|
+
name: "yuque_web_list_docs",
|
|
51
|
+
description: "Cookie-based: List documents in a repo. " +
|
|
52
|
+
"Returns richer fields than v2 list_docs (draft_version, editor_meta, read_status, etc.). " +
|
|
53
|
+
"No membership required. " +
|
|
54
|
+
"GET /api/docs?book_id={book_id}. " +
|
|
55
|
+
"详见 references/api/doc_api.md",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
book_id: { type: "string", description: "Repository ID (numeric, required)" },
|
|
60
|
+
offset: { type: "number", description: "Pagination offset, default 0" },
|
|
61
|
+
limit: { type: "number", description: "Page size, max 100, default 100" },
|
|
62
|
+
raw: { type: "boolean", description: "Return raw full JSON (default false, returns trimmed fields)" },
|
|
63
|
+
},
|
|
64
|
+
required: ["book_id"],
|
|
65
|
+
},
|
|
66
|
+
async handler(args) {
|
|
67
|
+
// @validate
|
|
68
|
+
const __v = check(requiredString(args?.book_id, "book_id"), positiveInt(args?.limit, "limit"), maxValue(args?.limit, "limit", 100));
|
|
69
|
+
if (__v)
|
|
70
|
+
return __v;
|
|
71
|
+
const bookId = Number(args?.book_id);
|
|
72
|
+
const offset = args?.offset ?? 0;
|
|
73
|
+
const limit = args?.limit ?? 100;
|
|
74
|
+
const raw = args?.raw;
|
|
75
|
+
if (!bookId) {
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: "text", text: JSON.stringify({ error: "book_id 必须为有效数字 / book_id must be a valid number" }, null, 2) }],
|
|
78
|
+
isError: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const url = `https://www.yuque.com/api/docs?book_id=${bookId}&offset=${offset}&limit=${Math.min(limit, 100)}`;
|
|
82
|
+
const result = await webRequest(url, { referer: DOC_REFERER });
|
|
83
|
+
if (isErrorResult(result))
|
|
84
|
+
return result;
|
|
85
|
+
const res = result;
|
|
86
|
+
const items = res?.data ?? [];
|
|
87
|
+
const meta = res?.meta ?? {};
|
|
88
|
+
if (raw) {
|
|
89
|
+
return {
|
|
90
|
+
content: [{ type: "text", text: JSON.stringify({ meta, data: items }, null, 2) }],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: "text",
|
|
97
|
+
text: JSON.stringify({
|
|
98
|
+
meta,
|
|
99
|
+
total: items.length,
|
|
100
|
+
offset,
|
|
101
|
+
limit,
|
|
102
|
+
data: items.map(formatDocSummary),
|
|
103
|
+
}, null, 2),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=list-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-docs.js","sourceRoot":"","sources":["../../src/web-doc/list-docs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAErF,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAA6B;IACrD,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,WAAW,EAAE,IAAI,CAAC,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,OAAO,MAAM,CAAC;QAEzC,MAAM,GAAG,GAAG,MAAmF,CAAC;QAChG,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;QAE7B,IAAI,GAAG,EAAE,CAAC;YACR,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aAC3F,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,IAAI;wBACJ,KAAK,EAAE,KAAK,CAAC,MAAM;wBACnB,MAAM;wBACN,KAAK;wBACL,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC;qBAClC,EAAE,IAAI,EAAE,CAAC,CAAC;iBACZ;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/list-repos — Cookie 态列知识库列表
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/books?user_id={user_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回当前用户或指定用户的知识库列表
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 list_repos 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回更丰富的字段(含 abilities/extend_private/stack_id/layout 等)
|
|
10
|
+
* - 支持权限检查(abilities.create_doc 等)
|
|
11
|
+
* - 不传 user_id 时自动从 /api/mine 获取当前用户
|
|
12
|
+
*/
|
|
13
|
+
import type { McpTool } from "../common/types.js";
|
|
14
|
+
export declare const webRepoList: McpTool;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-doc/list-repos — Cookie 态列知识库列表
|
|
3
|
+
*
|
|
4
|
+
* 端点:GET /api/books?user_id={user_id}(Web API,Cookie 认证)
|
|
5
|
+
* 职责:返回当前用户或指定用户的知识库列表
|
|
6
|
+
*
|
|
7
|
+
* 相比 v2 list_repos 的优势:
|
|
8
|
+
* - 不走 Token,不受会员过期限流
|
|
9
|
+
* - 返回更丰富的字段(含 abilities/extend_private/stack_id/layout 等)
|
|
10
|
+
* - 支持权限检查(abilities.create_doc 等)
|
|
11
|
+
* - 不传 user_id 时自动从 /api/mine 获取当前用户
|
|
12
|
+
*/
|
|
13
|
+
import { isErrorResult } from "../common/api-client.js";
|
|
14
|
+
import { webRequest } from "../common/web-request.js";
|
|
15
|
+
import { positiveInt, maxValue } from "../common/validate.js";
|
|
16
|
+
const BOOK_REFERER = "https://www.yuque.com/dashboard/books";
|
|
17
|
+
/**
|
|
18
|
+
* 格式化知识库摘要
|
|
19
|
+
*/
|
|
20
|
+
function formatRepo(item) {
|
|
21
|
+
return {
|
|
22
|
+
id: item.id,
|
|
23
|
+
type: item.type,
|
|
24
|
+
slug: item.slug,
|
|
25
|
+
name: item.name,
|
|
26
|
+
description: item.description,
|
|
27
|
+
items_count: item.items_count,
|
|
28
|
+
likes_count: item.likes_count,
|
|
29
|
+
watches_count: item.watches_count,
|
|
30
|
+
public: item.public,
|
|
31
|
+
status: item.status,
|
|
32
|
+
scene: item.scene,
|
|
33
|
+
source: item.source,
|
|
34
|
+
cover: item.cover,
|
|
35
|
+
cover_color: item.cover_color,
|
|
36
|
+
abilities: item.abilities,
|
|
37
|
+
user: item.user
|
|
38
|
+
? { id: item.user.id, login: item.user.login, name: item.user.name }
|
|
39
|
+
: { id: item.user_id },
|
|
40
|
+
creator: item.creator
|
|
41
|
+
? { id: item.creator.id, login: item.creator.login }
|
|
42
|
+
: null,
|
|
43
|
+
created_at: item.created_at,
|
|
44
|
+
updated_at: item.updated_at,
|
|
45
|
+
content_updated_at: item.content_updated_at,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export const webRepoList = {
|
|
49
|
+
name: "yuque_web_list_repos",
|
|
50
|
+
description: "Cookie-based: List repos for current user. " +
|
|
51
|
+
"Returns richer fields than v2 list_repos (abilities, cover_color, scene, etc.). " +
|
|
52
|
+
"Includes permission info (abilities.create_doc, modify_setting, destroy). " +
|
|
53
|
+
"No membership required. " +
|
|
54
|
+
"GET /api/books. " +
|
|
55
|
+
"详见 references/api/repo_api.md",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
user_id: { type: "string", description: "User ID (numeric, optional, defaults to current user)" },
|
|
60
|
+
offset: { type: "number", description: "Pagination offset, default 0" },
|
|
61
|
+
limit: { type: "number", description: "Page size, max 100, default 100" },
|
|
62
|
+
raw: { type: "boolean", description: "Return raw full JSON (default false, returns trimmed fields)" },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
async handler(args) {
|
|
66
|
+
// @validate
|
|
67
|
+
const __v = positiveInt(args?.limit, "limit")
|
|
68
|
+
|| maxValue(args?.limit, "limit", 100);
|
|
69
|
+
if (__v)
|
|
70
|
+
return __v;
|
|
71
|
+
let userId = args?.user_id ? Number(args?.user_id) : undefined;
|
|
72
|
+
const offset = args?.offset ?? 0;
|
|
73
|
+
const limit = args?.limit ?? 100;
|
|
74
|
+
const raw = args?.raw;
|
|
75
|
+
// 没传 user_id 时从 /api/mine 获取
|
|
76
|
+
if (!userId) {
|
|
77
|
+
const mineResult = await webRequest("https://www.yuque.com/api/mine", { referer: BOOK_REFERER });
|
|
78
|
+
if (!isErrorResult(mineResult)) {
|
|
79
|
+
const mineData = mineResult;
|
|
80
|
+
userId = mineData?.data?.id;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let url = `https://www.yuque.com/api/books?offset=${offset}&limit=${Math.min(limit, 100)}`;
|
|
84
|
+
if (userId)
|
|
85
|
+
url += `&user_id=${userId}`;
|
|
86
|
+
const result = await webRequest(url, { referer: BOOK_REFERER });
|
|
87
|
+
if (isErrorResult(result))
|
|
88
|
+
return result;
|
|
89
|
+
const res = result;
|
|
90
|
+
const items = res?.data ?? [];
|
|
91
|
+
if (raw) {
|
|
92
|
+
return {
|
|
93
|
+
content: [{ type: "text", text: JSON.stringify({ total: items.length, data: items }, null, 2) }],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: "text",
|
|
100
|
+
text: JSON.stringify({
|
|
101
|
+
total: items.length,
|
|
102
|
+
offset,
|
|
103
|
+
limit,
|
|
104
|
+
data: items.map(formatRepo),
|
|
105
|
+
}, null, 2),
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=list-repos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-repos.js","sourceRoot":"","sources":["../../src/web-doc/list-repos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,YAAY,GAAG,uCAAuC,CAAC;AAE7D;;GAEG;AACH,SAAS,UAAU,CAAC,IAA6B;IAC/C,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI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