docz-cli 0.5.0 → 0.7.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/dist/{chunk-EBJ32KUL.js → chunk-BHXHIHWH.js} +366 -109
- package/dist/chunk-BHXHIHWH.js.map +1 -0
- package/dist/index.js +3 -3
- package/dist/mcp-AU2BEEPP.js +685 -0
- package/dist/mcp-AU2BEEPP.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-EBJ32KUL.js.map +0 -1
- package/dist/mcp-26HFT6SQ.js +0 -384
- package/dist/mcp-26HFT6SQ.js.map +0 -1
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ConflictError,
|
|
4
|
+
DocSyncClient,
|
|
5
|
+
getBaseUrl,
|
|
6
|
+
getToken,
|
|
7
|
+
parseExpires
|
|
8
|
+
} from "./chunk-BHXHIHWH.js";
|
|
9
|
+
|
|
10
|
+
// src/mcp.ts
|
|
11
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
12
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
|
+
import {
|
|
14
|
+
CallToolRequestSchema,
|
|
15
|
+
ListToolsRequestSchema
|
|
16
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
17
|
+
function getClient() {
|
|
18
|
+
const token = getToken();
|
|
19
|
+
if (!token) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"DOCSYNC_API_TOKEN not set. Run `docz login --token <token>` or set the env var."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return new DocSyncClient(getBaseUrl(), token);
|
|
25
|
+
}
|
|
26
|
+
async function resolveSpaceId(client, nameOrId) {
|
|
27
|
+
const space = await client.resolveSpace(nameOrId);
|
|
28
|
+
return space.id;
|
|
29
|
+
}
|
|
30
|
+
function formatSize(bytes) {
|
|
31
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
32
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
33
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
34
|
+
}
|
|
35
|
+
function ok(text) {
|
|
36
|
+
return { content: [{ type: "text", text }] };
|
|
37
|
+
}
|
|
38
|
+
function fail(err) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
isError: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function startMcpServer() {
|
|
50
|
+
const server = new Server(
|
|
51
|
+
{ name: "docz-mcp", version: "0.5.0" },
|
|
52
|
+
{ capabilities: { tools: {} } }
|
|
53
|
+
);
|
|
54
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
55
|
+
tools: [
|
|
56
|
+
{
|
|
57
|
+
name: "docz_list_spaces",
|
|
58
|
+
description: "\u5217\u51FA\u6240\u6709\u53EF\u8BBF\u95EE\u7684 DocSync Space\uFF08\u4E2A\u4EBA\u7A7A\u95F4\u548C\u56E2\u961F\u7A7A\u95F4\uFF09",
|
|
59
|
+
inputSchema: { type: "object", properties: {} }
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "docz_list_files",
|
|
63
|
+
description: "\u5217\u51FA DocSync Space \u4E2D\u6307\u5B9A\u76EE\u5F55\u7684\u6587\u4EF6\u548C\u6587\u4EF6\u5939",
|
|
64
|
+
inputSchema: {
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
space: {
|
|
68
|
+
type: "string",
|
|
69
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
70
|
+
},
|
|
71
|
+
path: {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "\u76EE\u5F55\u8DEF\u5F84\uFF0C\u7A7A\u5B57\u7B26\u4E32\u8868\u793A\u6839\u76EE\u5F55",
|
|
74
|
+
default: ""
|
|
75
|
+
},
|
|
76
|
+
recursive: {
|
|
77
|
+
type: "boolean",
|
|
78
|
+
description: "\u662F\u5426\u9012\u5F52\u5217\u51FA\u6240\u6709\u5B50\u76EE\u5F55",
|
|
79
|
+
default: false
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
required: ["space"]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "docz_read_file",
|
|
87
|
+
description: "\u8BFB\u53D6 DocSync \u6587\u4EF6\u5185\u5BB9\uFF08Markdown\u3001CSV\u3001HTML \u7B49\u6587\u672C\u6587\u4EF6\uFF09\u3002\u8FD4\u56DE\u683C\u5F0F\uFF1A\u7B2C\u4E00\u884C [ref: <commit_hash>]\uFF0C\u7A7A\u884C\u540E\u662F\u6587\u4EF6\u5185\u5BB9\u3002\u4FDD\u5B58\u65F6\u8BF7\u5C06 ref \u503C\u4F5C\u4E3A base_ref \u4F20\u5165 docz_save_file \u4EE5\u68C0\u6D4B\u51B2\u7A81",
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
space: {
|
|
92
|
+
type: "string",
|
|
93
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
94
|
+
},
|
|
95
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" }
|
|
96
|
+
},
|
|
97
|
+
required: ["space", "path"]
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "docz_save_file",
|
|
102
|
+
description: "\u4FDD\u5B58/\u7F16\u8F91\u6587\u6863\u5185\u5BB9\uFF08\u652F\u6301\u51B2\u7A81\u68C0\u6D4B\uFF09\u3002\u5EFA\u8BAE\u5148\u7528 docz_read_file \u83B7\u53D6 ref\uFF0C\u518D\u4F20\u5165 base_ref \u4EE5\u68C0\u6D4B\u5E76\u53D1\u51B2\u7A81\u3002\u5982\u679C\u8FD4\u56DE\u51B2\u7A81\u9519\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u7528 docz_read_file \u83B7\u53D6\u6700\u65B0\u5185\u5BB9\uFF0C\u91CD\u65B0\u4FEE\u6539\u540E\u518D\u4FDD\u5B58",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: {
|
|
106
|
+
space: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
109
|
+
},
|
|
110
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" },
|
|
111
|
+
content: { type: "string", description: "\u6587\u4EF6\u5185\u5BB9" },
|
|
112
|
+
base_ref: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "\u8BFB\u53D6\u65F6\u83B7\u5F97\u7684 ref\uFF0C\u7528\u4E8E\u51B2\u7A81\u68C0\u6D4B\uFF08\u53EF\u9009\uFF09"
|
|
115
|
+
},
|
|
116
|
+
message: {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: "\u63D0\u4EA4\u6D88\u606F\uFF08\u53EF\u9009\uFF09"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
required: ["space", "path", "content"]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "docz_upload_file",
|
|
126
|
+
description: "\u4E0A\u4F20/\u521B\u5EFA\u6587\u4EF6\u5230 DocSync Space",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
space: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
133
|
+
},
|
|
134
|
+
path: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "\u76EE\u6807\u76EE\u5F55\u8DEF\u5F84\uFF08\u5982 reports\uFF09"
|
|
137
|
+
},
|
|
138
|
+
filename: {
|
|
139
|
+
type: "string",
|
|
140
|
+
description: "\u6587\u4EF6\u540D\uFF08\u5982 summary.md\uFF09"
|
|
141
|
+
},
|
|
142
|
+
content: { type: "string", description: "\u6587\u4EF6\u5185\u5BB9" }
|
|
143
|
+
},
|
|
144
|
+
required: ["space", "filename", "content"]
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "docz_mkdir",
|
|
149
|
+
description: "\u5728 DocSync Space \u4E2D\u521B\u5EFA\u6587\u4EF6\u5939",
|
|
150
|
+
inputSchema: {
|
|
151
|
+
type: "object",
|
|
152
|
+
properties: {
|
|
153
|
+
space: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
156
|
+
},
|
|
157
|
+
path: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "\u8981\u521B\u5EFA\u7684\u6587\u4EF6\u5939\u8DEF\u5F84"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
required: ["space", "path"]
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "docz_delete",
|
|
167
|
+
description: "\u5220\u9664\u6587\u4EF6\u6216\u6587\u4EF6\u5939\uFF08\u8FDB\u5165\u56DE\u6536\u7AD9\uFF0C30 \u5929\u5185\u53EF\u6062\u590D\uFF09",
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: {
|
|
171
|
+
space: {
|
|
172
|
+
type: "string",
|
|
173
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
174
|
+
},
|
|
175
|
+
path: { type: "string", description: "\u8981\u5220\u9664\u7684\u8DEF\u5F84" }
|
|
176
|
+
},
|
|
177
|
+
required: ["space", "path"]
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: "docz_file_history",
|
|
182
|
+
description: "\u67E5\u770B\u6587\u4EF6\u7684\u53D8\u66F4\u5386\u53F2\uFF08\u57FA\u4E8E Git \u7248\u672C\u63A7\u5236\uFF09",
|
|
183
|
+
inputSchema: {
|
|
184
|
+
type: "object",
|
|
185
|
+
properties: {
|
|
186
|
+
space: {
|
|
187
|
+
type: "string",
|
|
188
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
189
|
+
},
|
|
190
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" }
|
|
191
|
+
},
|
|
192
|
+
required: ["space"]
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "docz_rollback",
|
|
197
|
+
description: "\u5C06\u6587\u4EF6\u56DE\u6EDA\u5230\u6307\u5B9A\u7684\u5386\u53F2\u7248\u672C\uFF08\u901A\u8FC7 commit hash\uFF09",
|
|
198
|
+
inputSchema: {
|
|
199
|
+
type: "object",
|
|
200
|
+
properties: {
|
|
201
|
+
space: {
|
|
202
|
+
type: "string",
|
|
203
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
204
|
+
},
|
|
205
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" },
|
|
206
|
+
commit: {
|
|
207
|
+
type: "string",
|
|
208
|
+
description: "\u76EE\u6807 commit hash\uFF08\u901A\u8FC7 docz_file_history \u83B7\u53D6\uFF09"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
required: ["space", "path", "commit"]
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "docz_trash",
|
|
216
|
+
description: "\u67E5\u770B\u56DE\u6536\u7AD9\u4E2D\u7684\u5DF2\u5220\u9664\u6587\u4EF6\u5217\u8868",
|
|
217
|
+
inputSchema: {
|
|
218
|
+
type: "object",
|
|
219
|
+
properties: {
|
|
220
|
+
space: {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
required: ["space"]
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "docz_restore",
|
|
230
|
+
description: "\u4ECE\u56DE\u6536\u7AD9\u6062\u590D\u5DF2\u5220\u9664\u7684\u6587\u4EF6",
|
|
231
|
+
inputSchema: {
|
|
232
|
+
type: "object",
|
|
233
|
+
properties: {
|
|
234
|
+
space: {
|
|
235
|
+
type: "string",
|
|
236
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
237
|
+
},
|
|
238
|
+
path: {
|
|
239
|
+
type: "string",
|
|
240
|
+
description: "\u88AB\u5220\u9664\u7684\u6587\u4EF6\u8DEF\u5F84"
|
|
241
|
+
},
|
|
242
|
+
commit: {
|
|
243
|
+
type: "string",
|
|
244
|
+
description: "\u5220\u9664\u65F6\u7684 commit hash\uFF08\u901A\u8FC7 docz_trash \u83B7\u53D6\uFF09"
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
required: ["space", "path", "commit"]
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: "docz_list_comments",
|
|
252
|
+
description: "\u5217\u51FA\u6587\u4EF6\u7684\u8BC4\u8BBA\u548C\u56DE\u590D",
|
|
253
|
+
inputSchema: {
|
|
254
|
+
type: "object",
|
|
255
|
+
properties: {
|
|
256
|
+
space: {
|
|
257
|
+
type: "string",
|
|
258
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
259
|
+
},
|
|
260
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" }
|
|
261
|
+
},
|
|
262
|
+
required: ["space", "path"]
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "docz_add_comment",
|
|
267
|
+
description: "\u5728\u6587\u4EF6\u4E0A\u6DFB\u52A0\u8BC4\u8BBA\u3002\u652F\u6301 @email \u683C\u5F0F\u63D0\u53CA\u5176\u4ED6\u7528\u6237",
|
|
268
|
+
inputSchema: {
|
|
269
|
+
type: "object",
|
|
270
|
+
properties: {
|
|
271
|
+
space: {
|
|
272
|
+
type: "string",
|
|
273
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
274
|
+
},
|
|
275
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" },
|
|
276
|
+
content: {
|
|
277
|
+
type: "string",
|
|
278
|
+
description: "\u8BC4\u8BBA\u5185\u5BB9"
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
required: ["space", "path", "content"]
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "docz_reply_comment",
|
|
286
|
+
description: "\u56DE\u590D\u6307\u5B9A\u8BC4\u8BBA",
|
|
287
|
+
inputSchema: {
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
space: {
|
|
291
|
+
type: "string",
|
|
292
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
293
|
+
},
|
|
294
|
+
comment_id: {
|
|
295
|
+
type: "number",
|
|
296
|
+
description: "\u8BC4\u8BBA ID"
|
|
297
|
+
},
|
|
298
|
+
content: {
|
|
299
|
+
type: "string",
|
|
300
|
+
description: "\u56DE\u590D\u5185\u5BB9"
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
required: ["space", "comment_id", "content"]
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: "docz_close_comment",
|
|
308
|
+
description: "\u5173\u95ED\u8BC4\u8BBA\uFF08\u6807\u8BB0\u4E3A\u5DF2\u89E3\u51B3\uFF09",
|
|
309
|
+
inputSchema: {
|
|
310
|
+
type: "object",
|
|
311
|
+
properties: {
|
|
312
|
+
space: {
|
|
313
|
+
type: "string",
|
|
314
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
315
|
+
},
|
|
316
|
+
comment_id: {
|
|
317
|
+
type: "number",
|
|
318
|
+
description: "\u8BC4\u8BBA ID"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
required: ["space", "comment_id"]
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "docz_share_create",
|
|
326
|
+
description: "\u521B\u5EFA\u6587\u4EF6\u5206\u4EAB\u94FE\u63A5",
|
|
327
|
+
inputSchema: {
|
|
328
|
+
type: "object",
|
|
329
|
+
properties: {
|
|
330
|
+
space: {
|
|
331
|
+
type: "string",
|
|
332
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
333
|
+
},
|
|
334
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" },
|
|
335
|
+
expires: {
|
|
336
|
+
type: "string",
|
|
337
|
+
description: "\u8FC7\u671F\u65F6\u95F4\uFF0C\u5982 7d, 24h"
|
|
338
|
+
},
|
|
339
|
+
userIds: {
|
|
340
|
+
type: "array",
|
|
341
|
+
items: { type: "string" },
|
|
342
|
+
description: "\u53EF\u89C1\u7528\u6237 ID \u5217\u8868"
|
|
343
|
+
},
|
|
344
|
+
groupIds: {
|
|
345
|
+
type: "array",
|
|
346
|
+
items: { type: "string" },
|
|
347
|
+
description: "\u53EF\u89C1\u7EC4 ID \u5217\u8868"
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
required: ["space", "path"]
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "docz_share_list",
|
|
355
|
+
description: "\u5217\u51FA\u7A7A\u95F4\u7684\u5206\u4EAB\u94FE\u63A5",
|
|
356
|
+
inputSchema: {
|
|
357
|
+
type: "object",
|
|
358
|
+
properties: {
|
|
359
|
+
space: {
|
|
360
|
+
type: "string",
|
|
361
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
362
|
+
},
|
|
363
|
+
filePath: {
|
|
364
|
+
type: "string",
|
|
365
|
+
description: "\u6309\u6587\u4EF6\u8DEF\u5F84\u8FC7\u6EE4"
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
required: ["space"]
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "docz_share_read",
|
|
373
|
+
description: "\u901A\u8FC7\u5206\u4EAB token \u8BFB\u53D6\u6587\u4EF6\u5185\u5BB9",
|
|
374
|
+
inputSchema: {
|
|
375
|
+
type: "object",
|
|
376
|
+
properties: {
|
|
377
|
+
token: {
|
|
378
|
+
type: "string",
|
|
379
|
+
description: "\u5206\u4EAB\u94FE\u63A5 token"
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
required: ["token"]
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: "docz_share_info",
|
|
387
|
+
description: "\u67E5\u770B\u5206\u4EAB\u94FE\u63A5\u4FE1\u606F",
|
|
388
|
+
inputSchema: {
|
|
389
|
+
type: "object",
|
|
390
|
+
properties: {
|
|
391
|
+
token: {
|
|
392
|
+
type: "string",
|
|
393
|
+
description: "\u5206\u4EAB\u94FE\u63A5 token"
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
required: ["token"]
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: "docz_share_delete",
|
|
401
|
+
description: "\u5220\u9664\u5206\u4EAB\u94FE\u63A5",
|
|
402
|
+
inputSchema: {
|
|
403
|
+
type: "object",
|
|
404
|
+
properties: {
|
|
405
|
+
space: {
|
|
406
|
+
type: "string",
|
|
407
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
408
|
+
},
|
|
409
|
+
linkId: {
|
|
410
|
+
type: "string",
|
|
411
|
+
description: "\u5206\u4EAB\u94FE\u63A5 ID"
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
required: ["space", "linkId"]
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
name: "docz_shortlink",
|
|
419
|
+
description: "\u83B7\u53D6\u6587\u4EF6\u7684\u77ED\u94FE\u63A5 URL\uFF0C\u53EF\u76F4\u63A5\u5728\u6D4F\u89C8\u5668\u6253\u5F00",
|
|
420
|
+
inputSchema: {
|
|
421
|
+
type: "object",
|
|
422
|
+
properties: {
|
|
423
|
+
space: {
|
|
424
|
+
type: "string",
|
|
425
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
426
|
+
},
|
|
427
|
+
path: { type: "string", description: "\u6587\u4EF6\u8DEF\u5F84" }
|
|
428
|
+
},
|
|
429
|
+
required: ["space", "path"]
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
name: "docz_diff",
|
|
434
|
+
description: "\u67E5\u770B\u6587\u4EF6\u6216 Space \u7684\u53D8\u66F4 diff",
|
|
435
|
+
inputSchema: {
|
|
436
|
+
type: "object",
|
|
437
|
+
properties: {
|
|
438
|
+
space: {
|
|
439
|
+
type: "string",
|
|
440
|
+
description: "Space \u540D\u79F0\u6216 ID"
|
|
441
|
+
},
|
|
442
|
+
path: {
|
|
443
|
+
type: "string",
|
|
444
|
+
description: "\u6587\u4EF6\u8DEF\u5F84\uFF08\u7A7A\u5219\u8FD4\u56DE\u53D8\u66F4\u6587\u4EF6\u5217\u8868\uFF09"
|
|
445
|
+
},
|
|
446
|
+
to: {
|
|
447
|
+
type: "string",
|
|
448
|
+
description: "\u76EE\u6807 commit hash"
|
|
449
|
+
},
|
|
450
|
+
from: {
|
|
451
|
+
type: "string",
|
|
452
|
+
description: "\u8D77\u59CB commit hash\uFF08\u9ED8\u8BA4 to^\uFF09"
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
required: ["space", "to"]
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
}));
|
|
460
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
461
|
+
const args = request.params.arguments ?? {};
|
|
462
|
+
try {
|
|
463
|
+
const client = getClient();
|
|
464
|
+
switch (request.params.name) {
|
|
465
|
+
case "docz_list_spaces": {
|
|
466
|
+
const spaces = await client.listSpaces();
|
|
467
|
+
const lines = spaces.map(
|
|
468
|
+
(s) => `${s.name} (${s.is_private ? "\u79C1\u6709" : "\u56E2\u961F"}, ${s.member_count} \u4EBA) id=${s.id}`
|
|
469
|
+
);
|
|
470
|
+
return ok(lines.join("\n"));
|
|
471
|
+
}
|
|
472
|
+
case "docz_list_files": {
|
|
473
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
474
|
+
const entries = args.recursive ? await client.treeFull(sid) : await client.ls(sid, String(args.path ?? ""));
|
|
475
|
+
if (entries.length === 0) return ok("\uFF08\u7A7A\u76EE\u5F55\uFF09");
|
|
476
|
+
const lines = entries.map((e) => {
|
|
477
|
+
const size = e.type === "blob" ? ` (${formatSize(e.size)})` : "";
|
|
478
|
+
return `${e.type === "tree" ? "\u{1F4C1}" : "\u{1F4C4}"} ${e.name}${size}`;
|
|
479
|
+
});
|
|
480
|
+
return ok(lines.join("\n"));
|
|
481
|
+
}
|
|
482
|
+
case "docz_read_file": {
|
|
483
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
484
|
+
const result = await client.catWithRef(sid, String(args.path));
|
|
485
|
+
const header = result.ref ? `[ref: ${result.ref}]
|
|
486
|
+
|
|
487
|
+
` : "";
|
|
488
|
+
return ok(header + result.content);
|
|
489
|
+
}
|
|
490
|
+
case "docz_save_file": {
|
|
491
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
492
|
+
const savePath = String(args.path);
|
|
493
|
+
const saveContent = String(args.content);
|
|
494
|
+
const saveMessage = args.message ? String(args.message) : void 0;
|
|
495
|
+
const baseRef = args.base_ref ? String(args.base_ref) : void 0;
|
|
496
|
+
if (Buffer.byteLength(saveContent, "utf-8") > 2 * 1024 * 1024) {
|
|
497
|
+
return fail("\u5185\u5BB9\u8D85\u8FC7 2MB \u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 docz_upload_file \u4E0A\u4F20");
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
const result = await client.save(sid, savePath, saveContent, {
|
|
501
|
+
baseRef,
|
|
502
|
+
message: saveMessage
|
|
503
|
+
});
|
|
504
|
+
return ok(`\u5DF2\u4FDD\u5B58: ${result.path} (ref: ${result.ref})`);
|
|
505
|
+
} catch (err) {
|
|
506
|
+
if (err instanceof ConflictError) {
|
|
507
|
+
return fail(
|
|
508
|
+
`\u51B2\u7A81\uFF1A\u6587\u4EF6\u5DF2\u88AB\u4ED6\u4EBA\u4FEE\u6539\uFF08\u5F53\u524D ref: ${err.detail.current_ref}\uFF09\u3002\u8BF7\u5148\u7528 docz_read_file \u83B7\u53D6\u6700\u65B0\u5185\u5BB9\uFF0C\u91CD\u65B0\u4FEE\u6539\u540E\u518D\u4FDD\u5B58\u3002`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
throw err;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
case "docz_upload_file": {
|
|
515
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
516
|
+
const result = await client.upload(
|
|
517
|
+
sid,
|
|
518
|
+
String(args.path ?? ""),
|
|
519
|
+
String(args.filename),
|
|
520
|
+
String(args.content)
|
|
521
|
+
);
|
|
522
|
+
return ok(`\u5DF2\u4E0A\u4F20: ${result.path}`);
|
|
523
|
+
}
|
|
524
|
+
case "docz_mkdir": {
|
|
525
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
526
|
+
await client.mkdir(sid, String(args.path));
|
|
527
|
+
return ok(`\u5DF2\u521B\u5EFA: ${args.path}`);
|
|
528
|
+
}
|
|
529
|
+
case "docz_delete": {
|
|
530
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
531
|
+
await client.rm(sid, String(args.path));
|
|
532
|
+
return ok(`\u5DF2\u5220\u9664: ${args.path}\uFF0830 \u5929\u5185\u53EF\u4ECE\u56DE\u6536\u7AD9\u6062\u590D\uFF09`);
|
|
533
|
+
}
|
|
534
|
+
case "docz_file_history": {
|
|
535
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
536
|
+
const logs = await client.log(
|
|
537
|
+
sid,
|
|
538
|
+
args.path ? String(args.path) : void 0
|
|
539
|
+
);
|
|
540
|
+
if (logs.length === 0) return ok("\u6CA1\u6709\u53D8\u66F4\u5386\u53F2\u3002");
|
|
541
|
+
const lines = logs.map((l) => `${l.hash} ${l.date} ${l.message}`);
|
|
542
|
+
return ok(lines.join("\n"));
|
|
543
|
+
}
|
|
544
|
+
case "docz_rollback": {
|
|
545
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
546
|
+
await client.rollback(sid, String(args.path), String(args.commit));
|
|
547
|
+
return ok(
|
|
548
|
+
`\u5DF2\u56DE\u6EDA: ${args.path} \u2192 ${String(args.commit).substring(0, 7)}`
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
case "docz_trash": {
|
|
552
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
553
|
+
const items = await client.trash(sid);
|
|
554
|
+
if (items.length === 0) return ok("\u56DE\u6536\u7AD9\u4E3A\u7A7A\u3002");
|
|
555
|
+
const lines = items.map(
|
|
556
|
+
(t) => `${t.path} \u5220\u9664\u4E8E ${t.deleted_at} commit: ${t.commit.substring(0, 7)}`
|
|
557
|
+
);
|
|
558
|
+
return ok(lines.join("\n"));
|
|
559
|
+
}
|
|
560
|
+
case "docz_restore": {
|
|
561
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
562
|
+
await client.restore(sid, String(args.path), String(args.commit));
|
|
563
|
+
return ok(`\u5DF2\u6062\u590D: ${args.path}`);
|
|
564
|
+
}
|
|
565
|
+
case "docz_list_comments": {
|
|
566
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
567
|
+
const comments = await client.listComments(sid, String(args.path));
|
|
568
|
+
if (comments.length === 0) return ok("\u6CA1\u6709\u8BC4\u8BBA\u3002");
|
|
569
|
+
const lines = comments.map((c) => {
|
|
570
|
+
const status = c.is_closed ? " [\u5DF2\u5173\u95ED]" : "";
|
|
571
|
+
let text = `#${c.id} ${c.user_name}${status}: ${c.content}`;
|
|
572
|
+
for (const r of c.replies) {
|
|
573
|
+
text += `
|
|
574
|
+
\u21B3 ${r.user_name}: ${r.content}`;
|
|
575
|
+
}
|
|
576
|
+
return text;
|
|
577
|
+
});
|
|
578
|
+
return ok(lines.join("\n\n"));
|
|
579
|
+
}
|
|
580
|
+
case "docz_add_comment": {
|
|
581
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
582
|
+
const c = await client.createComment(
|
|
583
|
+
sid,
|
|
584
|
+
String(args.path),
|
|
585
|
+
String(args.content)
|
|
586
|
+
);
|
|
587
|
+
return ok(`\u8BC4\u8BBA #${c.id} \u5DF2\u521B\u5EFA`);
|
|
588
|
+
}
|
|
589
|
+
case "docz_reply_comment": {
|
|
590
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
591
|
+
const r = await client.replyComment(
|
|
592
|
+
sid,
|
|
593
|
+
Number(args.comment_id),
|
|
594
|
+
String(args.content)
|
|
595
|
+
);
|
|
596
|
+
return ok(`\u56DE\u590D #${r.id} \u5DF2\u521B\u5EFA`);
|
|
597
|
+
}
|
|
598
|
+
case "docz_close_comment": {
|
|
599
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
600
|
+
await client.closeComment(sid, Number(args.comment_id));
|
|
601
|
+
return ok(`\u8BC4\u8BBA #${args.comment_id} \u5DF2\u5173\u95ED`);
|
|
602
|
+
}
|
|
603
|
+
case "docz_share_create": {
|
|
604
|
+
const sharePath = String(args.path ?? "");
|
|
605
|
+
if (!sharePath) return fail("path is required");
|
|
606
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
607
|
+
const opts = {};
|
|
608
|
+
if (args.expires) opts.expiresAt = parseExpires(String(args.expires));
|
|
609
|
+
if (args.userIds) opts.userIds = args.userIds;
|
|
610
|
+
if (args.groupIds) opts.groupIds = args.groupIds;
|
|
611
|
+
const link = await client.createShareLink(sid, sharePath, opts);
|
|
612
|
+
return ok(
|
|
613
|
+
`\u5DF2\u521B\u5EFA\u5206\u4EAB\u94FE\u63A5:
|
|
614
|
+
token: ${link.token}
|
|
615
|
+
url: ${getBaseUrl()}/share/${link.token}
|
|
616
|
+
\u8FC7\u671F: ${link.expires_at ?? "\u6C38\u4E0D"}`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
case "docz_share_list": {
|
|
620
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
621
|
+
const links = await client.listShareLinks(
|
|
622
|
+
sid,
|
|
623
|
+
args.filePath ? String(args.filePath) : void 0
|
|
624
|
+
);
|
|
625
|
+
if (links.length === 0) return ok("\u6CA1\u6709\u5206\u4EAB\u94FE\u63A5\u3002");
|
|
626
|
+
const lines = links.map(
|
|
627
|
+
(l) => `${l.token} ${l.file_path} \u8FC7\u671F: ${l.expires_at ?? "\u6C38\u4E0D"} \u521B\u5EFA\u8005: ${l.created_by_name ?? l.created_by_email ?? l.created_by}`
|
|
628
|
+
);
|
|
629
|
+
return ok(lines.join("\n"));
|
|
630
|
+
}
|
|
631
|
+
case "docz_share_read": {
|
|
632
|
+
const content = await client.getSharedFile(String(args.token));
|
|
633
|
+
return ok(content);
|
|
634
|
+
}
|
|
635
|
+
case "docz_share_info": {
|
|
636
|
+
const info = await client.getSharedFileInfo(String(args.token));
|
|
637
|
+
return ok(
|
|
638
|
+
`\u6587\u4EF6: ${info.file_path}
|
|
639
|
+
Space: ${info.space_name}
|
|
640
|
+
\u5206\u4EAB\u8005: ${info.created_by_name}
|
|
641
|
+
\u8FC7\u671F: ${info.expires_at ?? "\u6C38\u4E0D"}`
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
case "docz_share_delete": {
|
|
645
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
646
|
+
await client.deleteShareLink(sid, String(args.linkId));
|
|
647
|
+
return ok(`\u5DF2\u5220\u9664\u5206\u4EAB\u94FE\u63A5: ${args.linkId}`);
|
|
648
|
+
}
|
|
649
|
+
case "docz_shortlink": {
|
|
650
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
651
|
+
const ref = await client.getFileRef(sid, String(args.path));
|
|
652
|
+
return ok(ref.url);
|
|
653
|
+
}
|
|
654
|
+
case "docz_diff": {
|
|
655
|
+
const sid = await resolveSpaceId(client, String(args.space));
|
|
656
|
+
const path = args.path ? String(args.path) : "";
|
|
657
|
+
const from = args.from ? String(args.from) : void 0;
|
|
658
|
+
if (path) {
|
|
659
|
+
const result2 = await client.diffFile(
|
|
660
|
+
sid,
|
|
661
|
+
path,
|
|
662
|
+
String(args.to),
|
|
663
|
+
from
|
|
664
|
+
);
|
|
665
|
+
return ok(result2.diff || "\u6CA1\u6709\u53D8\u66F4\u3002");
|
|
666
|
+
}
|
|
667
|
+
const result = await client.diffSummary(sid, String(args.to), from);
|
|
668
|
+
if (result.files.length === 0) return ok("\u6CA1\u6709\u53D8\u66F4\u3002");
|
|
669
|
+
const lines = result.files.map((f) => `${f.status} ${f.path}`);
|
|
670
|
+
return ok(lines.join("\n"));
|
|
671
|
+
}
|
|
672
|
+
default:
|
|
673
|
+
return fail(`Unknown tool: ${request.params.name}`);
|
|
674
|
+
}
|
|
675
|
+
} catch (err) {
|
|
676
|
+
return fail(err);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
const transport = new StdioServerTransport();
|
|
680
|
+
await server.connect(transport);
|
|
681
|
+
}
|
|
682
|
+
export {
|
|
683
|
+
startMcpServer
|
|
684
|
+
};
|
|
685
|
+
//# sourceMappingURL=mcp-AU2BEEPP.js.map
|