@ppdocs/mcp 2.6.5 → 2.6.7
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/cli.js +15 -4
- package/dist/storage/httpClient.d.ts +2 -10
- package/dist/storage/types.d.ts +1 -7
- package/dist/tools/index.js +2 -6
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +7 -28
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -135,15 +135,24 @@ function commandExists(cmd) {
|
|
|
135
135
|
return false;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/** 静默执行命令 (忽略错误) */
|
|
139
|
+
function execSilent(cmd) {
|
|
140
|
+
try {
|
|
141
|
+
execSync(cmd, { stdio: 'ignore' });
|
|
142
|
+
}
|
|
143
|
+
catch { /* ignore */ }
|
|
144
|
+
}
|
|
138
145
|
/** 自动检测 AI CLI 并注册 MCP */
|
|
139
146
|
function autoRegisterMcp(apiUrl, user) {
|
|
140
147
|
const detected = [];
|
|
141
|
-
|
|
148
|
+
const serverName = 'ppdocs-kg';
|
|
149
|
+
// 检测 Claude CLI (不传环境变量,MCP启动时读取.ppdocs)
|
|
142
150
|
if (commandExists('claude')) {
|
|
143
151
|
detected.push('Claude');
|
|
144
152
|
try {
|
|
145
|
-
const cmd = `claude mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp@latest`;
|
|
146
153
|
console.log(`✅ Detected Claude CLI, registering MCP...`);
|
|
154
|
+
execSilent(`claude mcp remove ${serverName}`);
|
|
155
|
+
const cmd = `claude mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
147
156
|
execSync(cmd, { stdio: 'inherit' });
|
|
148
157
|
}
|
|
149
158
|
catch (e) {
|
|
@@ -154,8 +163,9 @@ function autoRegisterMcp(apiUrl, user) {
|
|
|
154
163
|
if (commandExists('codex')) {
|
|
155
164
|
detected.push('Codex');
|
|
156
165
|
try {
|
|
157
|
-
const cmd = `codex mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp@latest`;
|
|
158
166
|
console.log(`✅ Detected Codex CLI, registering MCP...`);
|
|
167
|
+
execSilent(`codex mcp remove ${serverName}`);
|
|
168
|
+
const cmd = `codex mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
159
169
|
execSync(cmd, { stdio: 'inherit' });
|
|
160
170
|
}
|
|
161
171
|
catch (e) {
|
|
@@ -166,8 +176,9 @@ function autoRegisterMcp(apiUrl, user) {
|
|
|
166
176
|
if (commandExists('gemini')) {
|
|
167
177
|
detected.push('Gemini');
|
|
168
178
|
try {
|
|
169
|
-
const cmd = `gemini mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp@latest`;
|
|
170
179
|
console.log(`✅ Detected Gemini CLI, registering MCP...`);
|
|
180
|
+
execSilent(`gemini mcp remove ${serverName}`);
|
|
181
|
+
const cmd = `gemini mcp add ${serverName} "npx -y @ppdocs/mcp@latest"`;
|
|
171
182
|
execSync(cmd, { stdio: 'inherit' });
|
|
172
183
|
}
|
|
173
184
|
catch (e) {
|
|
@@ -16,11 +16,7 @@ export declare class PpdocsApiClient {
|
|
|
16
16
|
updateRoot(updates: {
|
|
17
17
|
title?: string;
|
|
18
18
|
description?: string;
|
|
19
|
-
userStyles?:
|
|
20
|
-
key: string;
|
|
21
|
-
value: string;
|
|
22
|
-
category: 'config' | 'style' | 'reference';
|
|
23
|
-
}>;
|
|
19
|
+
userStyles?: string[];
|
|
24
20
|
}): Promise<NodeData | null>;
|
|
25
21
|
deleteNode(nodeId: string): Promise<boolean>;
|
|
26
22
|
lockNode(nodeId: string, locked: boolean): Promise<NodeData | null>;
|
|
@@ -63,11 +59,7 @@ export declare function updateNode(_projectId: string, nodeId: string, updates:
|
|
|
63
59
|
export declare function updateRoot(_projectId: string, updates: {
|
|
64
60
|
title?: string;
|
|
65
61
|
description?: string;
|
|
66
|
-
userStyles?:
|
|
67
|
-
key: string;
|
|
68
|
-
value: string;
|
|
69
|
-
category: 'config' | 'style' | 'reference';
|
|
70
|
-
}>;
|
|
62
|
+
userStyles?: string[];
|
|
71
63
|
}): Promise<NodeData | null>;
|
|
72
64
|
export declare function deleteNode(_projectId: string, nodeId: string): Promise<boolean>;
|
|
73
65
|
export declare function lockNode(_projectId: string, nodeId: string, locked: boolean): Promise<NodeData | null>;
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -17,12 +17,6 @@ export interface Dependency {
|
|
|
17
17
|
description: string;
|
|
18
18
|
nodePath?: string;
|
|
19
19
|
}
|
|
20
|
-
export type UserStyleCategory = 'config' | 'style' | 'reference';
|
|
21
|
-
export interface UserStyleItem {
|
|
22
|
-
key: string;
|
|
23
|
-
value: string;
|
|
24
|
-
category: UserStyleCategory;
|
|
25
|
-
}
|
|
26
20
|
export interface VersionRecord {
|
|
27
21
|
version: number;
|
|
28
22
|
date: string;
|
|
@@ -51,7 +45,7 @@ export interface NodeData {
|
|
|
51
45
|
dataOutput?: DataRef;
|
|
52
46
|
dependencies: Dependency[];
|
|
53
47
|
relatedFiles?: string[];
|
|
54
|
-
userStyles?:
|
|
48
|
+
userStyles?: string[];
|
|
55
49
|
createdAt?: string;
|
|
56
50
|
updatedAt?: string;
|
|
57
51
|
lastAccessedAt?: string;
|
package/dist/tools/index.js
CHANGED
|
@@ -68,14 +68,10 @@ export function registerTools(server, projectId, _user) {
|
|
|
68
68
|
return wrap(projectId, node ? JSON.stringify(node, null, 2) : '更新失败(节点不存在或已锁定)');
|
|
69
69
|
});
|
|
70
70
|
// 3.5 更新根节点 (专用方法,支持 userStyles)
|
|
71
|
-
server.tool('kg_update_root', '更新根节点(
|
|
71
|
+
server.tool('kg_update_root', '更新根节点(项目规则,锁定时不可更新)', {
|
|
72
72
|
title: z.string().optional().describe('项目标题'),
|
|
73
73
|
description: z.string().optional().describe('项目描述(Markdown)'),
|
|
74
|
-
userStyles: z.array(z.
|
|
75
|
-
key: z.string().describe('配置键'),
|
|
76
|
-
value: z.string().describe('配置值'),
|
|
77
|
-
category: z.enum(['config', 'style', 'reference']).describe('分类: config=基本规则, style=编码风格, reference=测试参数')
|
|
78
|
-
})).optional().describe('用户风格配置(完全替换,非合并)')
|
|
74
|
+
userStyles: z.array(z.string()).optional().describe('项目规则列表(字符串数组,每条一个规则)')
|
|
79
75
|
}, async (args) => {
|
|
80
76
|
// 空参数检查
|
|
81
77
|
if (args.title === undefined && args.description === undefined && args.userStyles === undefined) {
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -5,35 +5,16 @@ import * as storage from './storage/httpClient.js';
|
|
|
5
5
|
// 缓存根节点风格 (避免每次调用都请求)
|
|
6
6
|
let cachedRootStyle = null;
|
|
7
7
|
let cacheProjectId = null;
|
|
8
|
-
// 风格分类标签
|
|
9
|
-
const STYLE_CATEGORY_LABELS = {
|
|
10
|
-
config: '配置',
|
|
11
|
-
style: '风格',
|
|
12
|
-
reference: '参考'
|
|
13
|
-
};
|
|
14
8
|
/**
|
|
15
|
-
* 将 userStyles
|
|
9
|
+
* 将 userStyles 字符串数组格式化为 Markdown 列表
|
|
16
10
|
*/
|
|
17
11
|
function formatUserStyles(styles) {
|
|
18
12
|
if (!styles || styles.length === 0)
|
|
19
13
|
return '';
|
|
20
|
-
|
|
21
|
-
styles.forEach(s => {
|
|
22
|
-
if (groups[s.category])
|
|
23
|
-
groups[s.category].push(s);
|
|
24
|
-
});
|
|
25
|
-
const lines = [];
|
|
26
|
-
for (const [cat, items] of Object.entries(groups)) {
|
|
27
|
-
if (items.length === 0)
|
|
28
|
-
continue;
|
|
29
|
-
lines.push(`### ${STYLE_CATEGORY_LABELS[cat] || cat}`);
|
|
30
|
-
items.forEach(item => lines.push(`- **${item.key}**: ${item.value}`));
|
|
31
|
-
lines.push('');
|
|
32
|
-
}
|
|
33
|
-
return lines.join('\n').trim();
|
|
14
|
+
return styles.map(s => `- ${s}`).join('\n');
|
|
34
15
|
}
|
|
35
16
|
/**
|
|
36
|
-
* 获取根节点的用户风格
|
|
17
|
+
* 获取根节点的用户风格
|
|
37
18
|
*/
|
|
38
19
|
export async function getRootStyle(projectId) {
|
|
39
20
|
// 缓存命中
|
|
@@ -47,13 +28,12 @@ export async function getRootStyle(projectId) {
|
|
|
47
28
|
cacheProjectId = projectId;
|
|
48
29
|
return '';
|
|
49
30
|
}
|
|
50
|
-
//
|
|
31
|
+
// 使用 userStyles 字符串数组
|
|
51
32
|
if (rootNode.userStyles && rootNode.userStyles.length > 0) {
|
|
52
33
|
cachedRootStyle = formatUserStyles(rootNode.userStyles);
|
|
53
34
|
}
|
|
54
35
|
else {
|
|
55
|
-
|
|
56
|
-
cachedRootStyle = rootNode.description || '';
|
|
36
|
+
cachedRootStyle = '';
|
|
57
37
|
}
|
|
58
38
|
cacheProjectId = projectId;
|
|
59
39
|
return cachedRootStyle;
|
|
@@ -74,11 +54,10 @@ export function clearStyleCache() {
|
|
|
74
54
|
*/
|
|
75
55
|
export async function wrapResult(projectId, result) {
|
|
76
56
|
const style = await getRootStyle(projectId);
|
|
77
|
-
|
|
78
|
-
if (!style || style.trim() === '' || /^#\s+\S+\s*\n\n(项目根节点|Project root)?\s*$/.test(style)) {
|
|
57
|
+
if (!style || style.trim() === '') {
|
|
79
58
|
return result;
|
|
80
59
|
}
|
|
81
|
-
return `[
|
|
60
|
+
return `[项目规则]\n${style}\n\n---\n[结果]\n${result}`;
|
|
82
61
|
}
|
|
83
62
|
/**
|
|
84
63
|
* 解码 Unicode 转义序列
|