@ppdocs/mcp 3.1.3 → 3.1.4
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/tools/index.js +59 -0
- package/package.json +1 -1
package/dist/tools/index.js
CHANGED
|
@@ -407,6 +407,65 @@ export function registerTools(server, projectId, _user) {
|
|
|
407
407
|
const lines = docs.map(d => `- ${d.path} (${d.status || '已完成'}): ${d.summary || '无简介'}`);
|
|
408
408
|
return wrap(`找到 ${docs.length} 个文档:\n\n${lines.join('\n')}`);
|
|
409
409
|
});
|
|
410
|
+
// 12. 跨项目复制文档到当前项目
|
|
411
|
+
server.tool('kg_copy_node', '从其他项目复制文档到当前项目。支持单个或批量复制,可指定新路径。用于跨项目协作:拉取别的项目的知识文档到当前项目', {
|
|
412
|
+
sourceProject: z.string().describe('源项目ID或名称(从kg_list_projects获取)'),
|
|
413
|
+
sourcePath: z.union([z.string(), z.array(z.string())]).describe('源文档路径(单个或数组,如"/架构/数据流"或["/架构/数据流","/MCP/tools"])'),
|
|
414
|
+
targetPath: z.string().optional().describe('目标路径前缀(如"/参考/项目B")。不填则保持原路径'),
|
|
415
|
+
}, async (args) => {
|
|
416
|
+
const decoded = decodeObjectStrings(args);
|
|
417
|
+
const paths = Array.isArray(decoded.sourcePath) ? decoded.sourcePath : [decoded.sourcePath];
|
|
418
|
+
const results = [];
|
|
419
|
+
for (const srcPath of paths) {
|
|
420
|
+
try {
|
|
421
|
+
// 从源项目读取文档
|
|
422
|
+
const doc = await storage.crossGetDoc(decoded.sourceProject, srcPath);
|
|
423
|
+
if (!doc) {
|
|
424
|
+
results.push({ path: srcPath, success: false, error: '源文档不存在' });
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
// 计算目标路径
|
|
428
|
+
const destPath = decoded.targetPath
|
|
429
|
+
? `${decoded.targetPath.replace(/\/$/, '')}${srcPath}`
|
|
430
|
+
: srcPath;
|
|
431
|
+
// 检查目标是否已存在
|
|
432
|
+
const existing = await storage.getDoc(projectId, destPath);
|
|
433
|
+
if (existing) {
|
|
434
|
+
// 已存在则更新
|
|
435
|
+
await storage.updateDoc(projectId, destPath, {
|
|
436
|
+
summary: doc.summary,
|
|
437
|
+
content: doc.content,
|
|
438
|
+
});
|
|
439
|
+
results.push({ path: destPath, success: true });
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
// 不存在则创建
|
|
443
|
+
await storage.createDoc(projectId, destPath, {
|
|
444
|
+
summary: doc.summary,
|
|
445
|
+
content: doc.content,
|
|
446
|
+
status: doc.status,
|
|
447
|
+
});
|
|
448
|
+
results.push({ path: destPath, success: true });
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch (e) {
|
|
452
|
+
results.push({ path: srcPath, success: false, error: String(e) });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const successCount = results.filter(r => r.success).length;
|
|
456
|
+
const failedItems = results.filter(r => !r.success);
|
|
457
|
+
if (paths.length === 1) {
|
|
458
|
+
if (results[0].success) {
|
|
459
|
+
return wrap(`✅ 已复制文档: ${results[0].path}\n\n来源: [${decoded.sourceProject}] ${paths[0]}`);
|
|
460
|
+
}
|
|
461
|
+
return wrap(`❌ 复制失败: ${results[0].error}`);
|
|
462
|
+
}
|
|
463
|
+
let msg = `✅ 批量复制完成: ${successCount}/${paths.length} 成功`;
|
|
464
|
+
if (failedItems.length > 0) {
|
|
465
|
+
msg += `\n❌ 失败:\n${failedItems.map(f => ` - ${f.path}: ${f.error}`).join('\n')}`;
|
|
466
|
+
}
|
|
467
|
+
return wrap(msg);
|
|
468
|
+
});
|
|
410
469
|
// ===================== 任务管理 =====================
|
|
411
470
|
// 7. 创建任务
|
|
412
471
|
server.tool('task_create', '创建开发任务', {
|