@ppdocs/mcp 3.1.10 → 3.2.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.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * 💬 kg_discuss (6→1)
3
+ * 合并: kg_discussion_list, kg_discussion_read, kg_discussion_create,
4
+ * kg_discussion_reply, kg_discussion_close_and_archive, kg_discussion_delete
5
+ */
6
+ import { z } from 'zod';
7
+ import { getClient } from '../storage/httpClient.js';
8
+ import { decodeObjectStrings } from '../utils.js';
9
+ import { wrap, safeTool } from './shared.js';
10
+ import { DiscussionManager } from '../storage/discussion.js';
11
+ export function registerDiscussionTools(server, projectId) {
12
+ const client = () => getClient();
13
+ server.tool('kg_discuss', '💬 跨项目讨论 — 发起、回复、归档协同讨论。action: list(列出活跃讨论)|read(读取详情)|create(发起)|reply(回复)|close(结案归档)|delete(删除)', {
14
+ action: z.enum(['list', 'read', 'create', 'reply', 'close', 'delete'])
15
+ .describe('操作类型'),
16
+ id: z.string().optional()
17
+ .describe('讨论哈希ID (read/reply/close/delete)'),
18
+ ids: z.array(z.string()).optional()
19
+ .describe('批量读取的讨论ID数组 (read)'),
20
+ title: z.string().optional()
21
+ .describe('讨论标题 (create)'),
22
+ participants: z.array(z.string()).optional()
23
+ .describe('参与项目ID数组 (create, 不含自己)'),
24
+ content: z.string().optional()
25
+ .describe('消息内容Markdown (create/reply)'),
26
+ conclusion: z.string().optional()
27
+ .describe('结案总结 (close)'),
28
+ newSummary: z.string().optional()
29
+ .describe('更新进展摘要 (reply)'),
30
+ }, async (args) => safeTool(async () => {
31
+ const decoded = decodeObjectStrings(args);
32
+ switch (decoded.action) {
33
+ case 'list': {
34
+ const cleaned = DiscussionManager.cleanExpired(7);
35
+ const active = DiscussionManager.listActive();
36
+ const cleanMsg = cleaned > 0 ? `\n⚠️ 已自动清理 ${cleaned} 条超过7天不活跃的讨论` : '';
37
+ if (active.length === 0)
38
+ return wrap(`当前无活跃的讨论 (本项目ID: ${projectId})${cleanMsg}`);
39
+ return wrap(`本项目ID: ${projectId}\n活跃讨论区 (${active.length} 个):${cleanMsg}\n\n` + JSON.stringify(active, null, 2));
40
+ }
41
+ case 'read': {
42
+ const readIds = decoded.ids || (decoded.id ? [decoded.id] : []);
43
+ if (readIds.length === 0)
44
+ return wrap('❌ read 需要 id 或 ids');
45
+ const discussions = DiscussionManager.readByIds(readIds);
46
+ if (discussions.length === 0)
47
+ return wrap('未找到对应的讨论记录');
48
+ return wrap(JSON.stringify(discussions, null, 2));
49
+ }
50
+ case 'create': {
51
+ if (!decoded.title)
52
+ return wrap('❌ create 需要 title');
53
+ if (!decoded.participants)
54
+ return wrap('❌ create 需要 participants');
55
+ if (!decoded.content)
56
+ return wrap('❌ create 需要 content');
57
+ const count = DiscussionManager.activeCount();
58
+ if (count >= 10)
59
+ return wrap('❌ 活跃讨论已达上限(10条)');
60
+ const id = DiscussionManager.create(decoded.title, projectId, decoded.participants, decoded.content);
61
+ return wrap(`✅ 讨论已发起,ID: ${id}\n发起方: ${projectId}\n参与方: ${decoded.participants.join(', ')}`);
62
+ }
63
+ case 'reply': {
64
+ if (!decoded.id)
65
+ return wrap('❌ reply 需要 id');
66
+ if (!decoded.content)
67
+ return wrap('❌ reply 需要 content');
68
+ const success = DiscussionManager.reply(decoded.id, projectId, decoded.content, decoded.newSummary);
69
+ return wrap(success ? `✅ 回复成功 (ID: ${decoded.id})` : `❌ 回复失败,讨论不存在或已关闭`);
70
+ }
71
+ case 'close': {
72
+ if (!decoded.id)
73
+ return wrap('❌ close 需要 id');
74
+ if (!decoded.conclusion)
75
+ return wrap('❌ close 需要 conclusion');
76
+ const topic = DiscussionManager.getAndRemove(decoded.id);
77
+ if (!topic)
78
+ return wrap('❌ 讨论不存在或已被归档清理');
79
+ let md = `# 跨项目协同: ${topic.title}\n\n`;
80
+ md += `**发起方**: ${topic.initiator}\n`;
81
+ md += `**参与方**: ${topic.participants.join(', ')}\n`;
82
+ md += `**结案总结**: ${decoded.conclusion}\n\n`;
83
+ md += `## 讨论还原 (Timeline)\n\n`;
84
+ for (const msg of topic.messages) {
85
+ md += `### [${msg.sender}] (${msg.timestamp})\n${msg.content}\n\n`;
86
+ }
87
+ const safeTitle = topic.title.replace(/[\/\\?%*:|"<>]/g, '_');
88
+ const path = `/跨项目协同记录/${decoded.id}_${safeTitle}`;
89
+ try {
90
+ await client().createDoc(path, {
91
+ summary: decoded.conclusion, content: md,
92
+ versions: [{ version: 1.0, date: new Date().toISOString(), changes: '结案归档' }],
93
+ bugfixes: [], status: '已完成'
94
+ });
95
+ return wrap(`✅ 讨论已结案并归档: \`${path}\``);
96
+ }
97
+ catch (err) {
98
+ return wrap(`⚠️ 讨论已清除,但归档失败: ${err}\n\n${md}`);
99
+ }
100
+ }
101
+ case 'delete': {
102
+ if (!decoded.id)
103
+ return wrap('❌ delete 需要 id');
104
+ const success = DiscussionManager.delete(decoded.id);
105
+ return wrap(success ? `✅ 讨论已删除 (ID: ${decoded.id})` : `❌ 讨论不存在或已被删除`);
106
+ }
107
+ default:
108
+ return wrap(`❌ 未知 action: ${decoded.action}`);
109
+ }
110
+ }));
111
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * 文档管理工具 (7个)
3
- * kg_create_node, kg_delete_node, kg_update_node, kg_read_node,
4
- * kg_get_tree, kg_get_docs_by_status, kg_copy_node
2
+ * 📄 kg_doc (5合1) + 🏗️ kg_tree (2合1)
3
+ * 合并: kg_create_node, kg_delete_node, kg_update_node, kg_read_node, kg_copy_node
4
+ * kg_get_tree, kg_get_docs_by_status
5
5
  */
6
6
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
7
  export declare function registerDocTools(server: McpServer, projectId: string): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * 文档管理工具 (7个)
3
- * kg_create_node, kg_delete_node, kg_update_node, kg_read_node,
4
- * kg_get_tree, kg_get_docs_by_status, kg_copy_node
2
+ * 📄 kg_doc (5合1) + 🏗️ kg_tree (2合1)
3
+ * 合并: kg_create_node, kg_delete_node, kg_update_node, kg_read_node, kg_copy_node
4
+ * kg_get_tree, kg_get_docs_by_status
5
5
  */
6
6
  import { z } from 'zod';
7
7
  import { getClient } from '../storage/httpClient.js';
@@ -9,52 +9,24 @@ import { decodeObjectStrings } from '../utils.js';
9
9
  import { wrap, safeTool, crossPrefix, formatDocMarkdown, formatTreeText, countTreeDocs } from './shared.js';
10
10
  export function registerDocTools(server, projectId) {
11
11
  const client = () => getClient();
12
- // 创建文档
13
- server.tool('kg_create_node', '创建知识文档。使用目录路径分类,文件名作为文档名', {
14
- path: z.string().min(1).describe('完整文档路径(如"/前端/组件/Modal")'),
15
- summary: z.string().optional().describe('一句话简介'),
16
- content: z.string().describe('Markdown内容'),
17
- status: z.string().optional().describe('文档状态(默认"已完成")')
18
- }, async (args) => safeTool(async () => {
19
- const d = decodeObjectStrings(args);
20
- const doc = await client().createDoc(d.path, {
21
- summary: d.summary || '',
22
- content: d.content,
23
- versions: [{ version: 0.1, date: new Date().toISOString(), changes: '初始创建' }],
24
- bugfixes: [],
25
- status: d.status || '已完成'
26
- });
27
- return wrap(`✅ 文档已创建: ${d.path}\n\n${JSON.stringify(doc, null, 2)}`);
28
- }));
29
- // 删除文档或目录 (支持批量)
30
- server.tool('kg_delete_node', '删除文档或目录(支持批量,根不可删除,目录会递归删除)', { nodeId: z.union([z.string(), z.array(z.string())]).describe('文档路径或路径数组') }, async (args) => safeTool(async () => {
31
- const paths = Array.isArray(args.nodeId) ? args.nodeId : [args.nodeId];
32
- const results = [];
33
- for (const p of paths) {
34
- results.push({ path: p, success: await client().deleteDoc(p) });
35
- }
36
- const successCount = results.filter(r => r.success).length;
37
- if (paths.length === 1) {
38
- return wrap(results[0].success ? '删除成功' : '删除失败(文档不存在或是根文档)');
39
- }
40
- const failedPaths = results.filter(r => !r.success).map(r => r.path);
41
- let msg = `✅ 批量删除完成: ${successCount}/${paths.length} 成功`;
42
- if (failedPaths.length > 0)
43
- msg += `\n❌ 失败: ${failedPaths.join(', ')}`;
44
- return wrap(msg);
45
- }));
46
- // 更新文档 (支持单个/批量)
47
- server.tool('kg_update_node', '更新文档内容。【单个模式】nodeId+字段;【批量模式】仅传updates数组。两种模式二选一', {
48
- nodeId: z.string().optional().describe('【单个模式】文档路径,如"/前端/组件/Button"'),
49
- summary: z.string().optional().describe('【单个模式】一句话简介'),
50
- content: z.string().optional().describe('【单个模式】Markdown内容'),
51
- status: z.string().optional().describe('【单个模式】文档状态'),
12
+ // ========== kg_doc: 文档 CRUD 统一入口 ==========
13
+ server.tool('kg_doc', '📄 知识文档操作 — 创建、读取、更新、删除、复制文档。action: create(创建)|read(读取)|update(更新)|delete(删除)|batch_update(批量更新)|copy(跨项目复制)', {
14
+ action: z.enum(['create', 'read', 'update', 'delete', 'batch_update', 'copy'])
15
+ .describe('操作类型'),
16
+ path: z.string().optional()
17
+ .describe('文档路径("/前端/组件/Modal")。create/read/update/delete 必填'),
18
+ content: z.string().optional()
19
+ .describe('Markdown内容 (create/update)'),
20
+ summary: z.string().optional()
21
+ .describe('一句话简介 (create/update)'),
22
+ status: z.string().optional()
23
+ .describe('文档状态 (create/update, 默认"已完成")'),
52
24
  versions: z.array(z.object({
53
25
  version: z.number(), date: z.string(), changes: z.string()
54
- })).optional().describe('【单个模式】版本记录数组'),
26
+ })).optional().describe('版本记录 (update)'),
55
27
  bugfixes: z.array(z.object({
56
28
  date: z.string(), issue: z.string(), solution: z.string()
57
- })).optional().describe('【单个模式】修复记录数组'),
29
+ })).optional().describe('修复记录 (update)'),
58
30
  updates: z.array(z.object({
59
31
  nodeId: z.string().describe('文档路径'),
60
32
  summary: z.string().optional(),
@@ -66,83 +38,201 @@ export function registerDocTools(server, projectId) {
66
38
  bugfixes: z.array(z.object({
67
39
  date: z.string(), issue: z.string(), solution: z.string()
68
40
  })).optional()
69
- })).optional().describe('【批量模式】更新数组,每项包含nodeId和要更新的字段')
41
+ })).optional().describe('批量更新数组 (batch_update)'),
42
+ targetProject: z.string().optional()
43
+ .describe('跨项目读取时的目标项目ID (read)'),
44
+ sourceProject: z.string().optional()
45
+ .describe('复制源项目ID (copy)'),
46
+ sourcePath: z.union([z.string(), z.array(z.string())]).optional()
47
+ .describe('复制源路径 (copy, 单个或数组)'),
48
+ targetPath: z.string().optional()
49
+ .describe('复制目标路径前缀 (copy)'),
70
50
  }, async (args) => safeTool(async () => {
71
- const decoded = decodeObjectStrings(args);
72
- // 批量更新模式
73
- if (decoded.updates && Array.isArray(decoded.updates)) {
74
- const results = [];
75
- for (const item of decoded.updates) {
76
- if (item.nodeId === '/' || item.nodeId === '_root') {
77
- results.push({ path: item.nodeId, success: false });
78
- continue;
79
- }
80
- const existing = await client().getDoc(item.nodeId);
81
- if (!existing) {
82
- results.push({ path: item.nodeId, success: false });
83
- continue;
51
+ const d = decodeObjectStrings(args);
52
+ switch (d.action) {
53
+ // ---- CREATE ----
54
+ case 'create': {
55
+ if (!d.path)
56
+ return wrap(' create 需要 path');
57
+ if (!d.content)
58
+ return wrap('❌ create 需要 content');
59
+ const doc = await client().createDoc(d.path, {
60
+ summary: d.summary || '',
61
+ content: d.content,
62
+ versions: [{ version: 0.1, date: new Date().toISOString(), changes: '初始创建' }],
63
+ bugfixes: [],
64
+ status: d.status || '已完成'
65
+ });
66
+ return wrap(`✅ 文档已创建: ${d.path}\n\n${JSON.stringify(doc, null, 2)}`);
67
+ }
68
+ // ---- READ ----
69
+ case 'read': {
70
+ if (!d.path)
71
+ return wrap('❌ read 需要 path');
72
+ const doc = d.targetProject
73
+ ? await client().crossGetDoc(d.targetProject, d.path)
74
+ : await client().getDoc(d.path);
75
+ if (!doc)
76
+ return wrap(d.targetProject ? `文档不存在(项目: ${d.targetProject})` : '文档不存在');
77
+ const lines = formatDocMarkdown(doc, d.path);
78
+ return wrap(d.targetProject ? crossPrefix(d.targetProject) + lines.join('\n') : lines.join('\n'));
79
+ }
80
+ // ---- UPDATE ----
81
+ case 'update': {
82
+ if (!d.path)
83
+ return wrap('❌ update 需要 path');
84
+ if (d.path === '/' || d.path === '_root') {
85
+ // 根文档更新
86
+ const existing = await client().getDoc('/');
87
+ if (!existing)
88
+ return wrap('更新失败(根文档不存在)');
89
+ const updates = {};
90
+ if (d.summary !== undefined)
91
+ updates.summary = d.summary;
92
+ if (d.content !== undefined)
93
+ updates.content = d.content;
94
+ const upd = await client().updateDoc('/', updates);
95
+ return wrap(upd ? '✅ 项目介绍已更新' : '更新失败');
84
96
  }
97
+ const existing = await client().getDoc(d.path);
98
+ if (!existing)
99
+ return wrap('更新失败(文档不存在)');
85
100
  const updates = {};
86
- if (item.summary !== undefined)
87
- updates.summary = item.summary;
88
- if (item.content !== undefined)
89
- updates.content = item.content;
90
- if (item.status !== undefined)
91
- updates.status = item.status;
92
- if (item.versions !== undefined)
93
- updates.versions = item.versions;
94
- if (item.bugfixes !== undefined)
95
- updates.bugfixes = item.bugfixes;
96
- const doc = await client().updateDoc(item.nodeId, updates);
97
- results.push({ path: item.nodeId, success: !!doc });
101
+ if (d.summary !== undefined)
102
+ updates.summary = d.summary;
103
+ if (d.content !== undefined)
104
+ updates.content = d.content;
105
+ if (d.status !== undefined)
106
+ updates.status = d.status;
107
+ if (d.versions !== undefined)
108
+ updates.versions = d.versions;
109
+ if (d.bugfixes !== undefined)
110
+ updates.bugfixes = d.bugfixes;
111
+ const doc = await client().updateDoc(d.path, updates);
112
+ return wrap(doc ? JSON.stringify(doc, null, 2) : '更新失败');
113
+ }
114
+ // ---- DELETE ----
115
+ case 'delete': {
116
+ if (!d.path)
117
+ return wrap('❌ delete 需要 path');
118
+ const paths = Array.isArray(d.path) ? d.path : [d.path];
119
+ const results = [];
120
+ for (const p of paths) {
121
+ results.push({ path: p, success: await client().deleteDoc(p) });
122
+ }
123
+ if (paths.length === 1) {
124
+ return wrap(results[0].success ? '删除成功' : '删除失败(文档不存在或是根文档)');
125
+ }
126
+ const ok = results.filter(r => r.success).length;
127
+ const failed = results.filter(r => !r.success).map(r => r.path);
128
+ let msg = `✅ 批量删除: ${ok}/${paths.length} 成功`;
129
+ if (failed.length > 0)
130
+ msg += `\n❌ 失败: ${failed.join(', ')}`;
131
+ return wrap(msg);
132
+ }
133
+ // ---- BATCH UPDATE ----
134
+ case 'batch_update': {
135
+ if (!d.updates || !Array.isArray(d.updates))
136
+ return wrap('❌ batch_update 需要 updates 数组');
137
+ const results = [];
138
+ for (const item of d.updates) {
139
+ if (item.nodeId === '/' || item.nodeId === '_root') {
140
+ results.push({ path: item.nodeId, success: false });
141
+ continue;
142
+ }
143
+ const existing = await client().getDoc(item.nodeId);
144
+ if (!existing) {
145
+ results.push({ path: item.nodeId, success: false });
146
+ continue;
147
+ }
148
+ const upd = {};
149
+ if (item.summary !== undefined)
150
+ upd.summary = item.summary;
151
+ if (item.content !== undefined)
152
+ upd.content = item.content;
153
+ if (item.status !== undefined)
154
+ upd.status = item.status;
155
+ if (item.versions !== undefined)
156
+ upd.versions = item.versions;
157
+ if (item.bugfixes !== undefined)
158
+ upd.bugfixes = item.bugfixes;
159
+ const doc = await client().updateDoc(item.nodeId, upd);
160
+ results.push({ path: item.nodeId, success: !!doc });
161
+ }
162
+ const ok = results.filter(r => r.success).length;
163
+ const failed = results.filter(r => !r.success).map(r => r.path);
164
+ let msg = `✅ 批量更新: ${ok}/${d.updates.length} 成功`;
165
+ if (failed.length > 0)
166
+ msg += `\n❌ 失败: ${failed.join(', ')}`;
167
+ return wrap(msg);
168
+ }
169
+ // ---- COPY ----
170
+ case 'copy': {
171
+ if (!d.sourceProject)
172
+ return wrap('❌ copy 需要 sourceProject');
173
+ if (!d.sourcePath)
174
+ return wrap('❌ copy 需要 sourcePath');
175
+ const paths = Array.isArray(d.sourcePath) ? d.sourcePath : [d.sourcePath];
176
+ const results = [];
177
+ for (const srcPath of paths) {
178
+ try {
179
+ const doc = await client().crossGetDoc(d.sourceProject, srcPath);
180
+ if (!doc) {
181
+ results.push({ path: srcPath, success: false, error: '源文档不存在' });
182
+ continue;
183
+ }
184
+ const destPath = d.targetPath
185
+ ? `${d.targetPath.replace(/\/$/, '')}${srcPath}`
186
+ : srcPath;
187
+ const existing = await client().getDoc(destPath);
188
+ if (existing) {
189
+ await client().updateDoc(destPath, { summary: doc.summary, content: doc.content });
190
+ }
191
+ else {
192
+ await client().createDoc(destPath, { summary: doc.summary, content: doc.content, status: doc.status });
193
+ }
194
+ results.push({ path: destPath, success: true });
195
+ }
196
+ catch (e) {
197
+ results.push({ path: srcPath, success: false, error: String(e) });
198
+ }
199
+ }
200
+ const ok = results.filter(r => r.success).length;
201
+ if (paths.length === 1) {
202
+ return wrap(results[0].success
203
+ ? `✅ 已复制: ${results[0].path}\n来源: [${d.sourceProject}] ${paths[0]}`
204
+ : `❌ 复制失败: ${results[0].error}`);
205
+ }
206
+ const failed = results.filter(r => !r.success);
207
+ let msg = `✅ 批量复制: ${ok}/${paths.length} 成功`;
208
+ if (failed.length > 0)
209
+ msg += `\n❌ 失败:\n${failed.map(f => ` - ${f.path}: ${f.error}`).join('\n')}`;
210
+ return wrap(msg);
98
211
  }
99
- const successCount = results.filter(r => r.success).length;
100
- const failedPaths = results.filter(r => !r.success).map(r => r.path);
101
- let msg = `✅ 批量更新完成: ${successCount}/${decoded.updates.length} 成功`;
102
- if (failedPaths.length > 0)
103
- msg += `\n❌ 失败: ${failedPaths.join(', ')}`;
104
- return wrap(msg);
212
+ default:
213
+ return wrap(`❌ 未知 action: ${d.action}`);
105
214
  }
106
- // 单个更新模式
107
- const { nodeId, summary, content, status, versions, bugfixes } = decoded;
108
- if (!nodeId)
109
- return wrap('❌ 请提供 nodeId(单个模式)或 updates 数组(批量模式)');
110
- if (nodeId === '/' || nodeId === '_root')
111
- return wrap('❌ 根文档请使用 kg_update_root 方法更新');
112
- const existing = await client().getDoc(nodeId);
113
- if (!existing)
114
- return wrap('更新失败(文档不存在)');
115
- const updates = {};
116
- if (summary !== undefined)
117
- updates.summary = summary;
118
- if (content !== undefined)
119
- updates.content = content;
120
- if (status !== undefined)
121
- updates.status = status;
122
- if (versions !== undefined)
123
- updates.versions = versions;
124
- if (bugfixes !== undefined)
125
- updates.bugfixes = bugfixes;
126
- const doc = await client().updateDoc(nodeId, updates);
127
- return wrap(doc ? JSON.stringify(doc, null, 2) : '更新失败');
128
215
  }));
129
- // 读取单个文档详情
130
- server.tool('kg_read_node', '读取文档完整内容(简介、正文、版本历史、修复记录)。支持跨项目只读访问(需先用kg_list_projects获取项目ID)', {
131
- nodeId: z.string().describe('文档路径'),
132
- targetProject: z.string().optional().describe('目标项目ID或名称(不填=当前项目)。ID可从kg_list_projects获取')
133
- }, async (args) => safeTool(async () => {
134
- const doc = args.targetProject
135
- ? await client().crossGetDoc(args.targetProject, args.nodeId)
136
- : await client().getDoc(args.nodeId);
137
- if (!doc)
138
- return wrap(args.targetProject ? `文档不存在(项目: ${args.targetProject})` : '文档不存在');
139
- const lines = formatDocMarkdown(doc, args.nodeId);
140
- return wrap(args.targetProject ? crossPrefix(args.targetProject) + lines.join('\n') : lines.join('\n'));
141
- }));
142
- // 获取知识库树状图
143
- server.tool('kg_get_tree', '获取知识库目录树。格式: 📄 文档名 # 简介。支持跨项目只读访问(需先用kg_list_projects获取项目ID)', {
144
- targetProject: z.string().optional().describe('目标项目ID或名称(不填=当前项目)。ID可从kg_list_projects获取')
216
+ // ========== kg_tree: 知识全景图 ==========
217
+ server.tool('kg_tree', '🏗️ 项目知识全景图 ★最快了解项目的方式★ 获取完整知识库目录树(含文档数统计)。传 statusFilter 可筛选特定状态文档。建议任何操作前先调用获取全局视图', {
218
+ statusFilter: z.array(z.string()).optional()
219
+ .describe('按状态筛选(如["未完成","待修复"]),不传则展示全景目录树'),
220
+ targetProject: z.string().optional()
221
+ .describe('跨项目查看,填目标项目ID或名称'),
145
222
  }, async (args) => safeTool(async () => {
223
+ // 状态筛选模式
224
+ if (args.statusFilter && args.statusFilter.length > 0) {
225
+ const docs = args.targetProject
226
+ ? await client().crossGetDocsByStatus(args.targetProject, args.statusFilter)
227
+ : await client().getDocsByStatus(args.statusFilter);
228
+ if (docs.length === 0) {
229
+ return wrap(`未找到状态为 [${args.statusFilter.join(', ')}] 的文档${args.targetProject ? `(项目: ${args.targetProject})` : ''}`);
230
+ }
231
+ const lines = docs.map(d => `- ${d.path} (${d.status || '已完成'}): ${d.summary || '无简介'}`);
232
+ const prefix = args.targetProject ? crossPrefix(args.targetProject) : '';
233
+ return wrap(`${prefix}找到 ${docs.length} 个文档:\n\n${lines.join('\n')}`);
234
+ }
235
+ // 全景目录树模式
146
236
  const tree = args.targetProject
147
237
  ? await client().crossGetTree(args.targetProject)
148
238
  : await client().getTree();
@@ -154,64 +244,4 @@ export function registerDocTools(server, projectId) {
154
244
  const prefix = args.targetProject ? crossPrefix(args.targetProject) : '';
155
245
  return wrap(`${prefix}共 ${docCount} 个文档\n\n${treeText}`);
156
246
  }));
157
- // 按状态筛选文档
158
- server.tool('kg_get_docs_by_status', '获取指定状态的文档列表。支持跨项目只读访问(需先用kg_list_projects获取项目ID)', {
159
- statusList: z.array(z.string()).describe('状态列表(如["未完成","待修复"])'),
160
- targetProject: z.string().optional().describe('目标项目ID或名称(不填=当前项目)。ID可从kg_list_projects获取')
161
- }, async (args) => safeTool(async () => {
162
- const docs = args.targetProject
163
- ? await client().crossGetDocsByStatus(args.targetProject, args.statusList)
164
- : await client().getDocsByStatus(args.statusList);
165
- if (docs.length === 0) {
166
- return wrap(`未找到状态为 [${args.statusList.join(', ')}] 的文档${args.targetProject ? `(项目: ${args.targetProject})` : ''}`);
167
- }
168
- const lines = docs.map(d => `- ${d.path} (${d.status || '已完成'}): ${d.summary || '无简介'}`);
169
- const prefix = args.targetProject ? crossPrefix(args.targetProject) : '';
170
- return wrap(`${prefix}找到 ${docs.length} 个文档:\n\n${lines.join('\n')}`);
171
- }));
172
- // 跨项目复制文档
173
- server.tool('kg_copy_node', '从其他项目复制文档到当前项目。支持单个或批量复制,可指定新路径。用于跨项目协作:拉取别的项目的知识文档到当前项目', {
174
- sourceProject: z.string().describe('源项目ID或名称(从kg_list_projects获取)'),
175
- sourcePath: z.union([z.string(), z.array(z.string())]).describe('源文档路径(单个或数组)'),
176
- targetPath: z.string().optional().describe('目标路径前缀(如"/参考/项目B")。不填则保持原路径'),
177
- }, async (args) => safeTool(async () => {
178
- const decoded = decodeObjectStrings(args);
179
- const paths = Array.isArray(decoded.sourcePath) ? decoded.sourcePath : [decoded.sourcePath];
180
- const results = [];
181
- for (const srcPath of paths) {
182
- try {
183
- const doc = await client().crossGetDoc(decoded.sourceProject, srcPath);
184
- if (!doc) {
185
- results.push({ path: srcPath, success: false, error: '源文档不存在' });
186
- continue;
187
- }
188
- const destPath = decoded.targetPath
189
- ? `${decoded.targetPath.replace(/\/$/, '')}${srcPath}`
190
- : srcPath;
191
- const existing = await client().getDoc(destPath);
192
- if (existing) {
193
- await client().updateDoc(destPath, { summary: doc.summary, content: doc.content });
194
- }
195
- else {
196
- await client().createDoc(destPath, { summary: doc.summary, content: doc.content, status: doc.status });
197
- }
198
- results.push({ path: destPath, success: true });
199
- }
200
- catch (e) {
201
- results.push({ path: srcPath, success: false, error: String(e) });
202
- }
203
- }
204
- const successCount = results.filter(r => r.success).length;
205
- if (paths.length === 1) {
206
- return wrap(results[0].success
207
- ? `✅ 已复制文档: ${results[0].path}\n\n来源: [${decoded.sourceProject}] ${paths[0]}`
208
- : `❌ 复制失败: ${results[0].error}`);
209
- }
210
- const failedItems = results.filter(r => !r.success);
211
- let msg = `✅ 批量复制完成: ${successCount}/${paths.length} 成功`;
212
- if (failedItems.length > 0) {
213
- msg += `\n❌ 失败:\n${failedItems.map(f => ` - ${f.path}: ${f.error}`).join('\n')}`;
214
- }
215
- return wrap(msg);
216
- }));
217
247
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * 项目文件访问工具 (5)
3
- * project_upload, project_clear_files, project_list_files,
4
- * project_read_file, project_download
2
+ * 📁 kg_files (5→1)
3
+ * 合并: project_list_files, project_read_file, project_upload, project_download
4
+ * 删除: project_clear_files (危险操作)
5
5
  */
6
6
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
7
  export declare function registerFileTools(server: McpServer): void;