@ppdocs/mcp 2.6.5 → 2.6.6

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 CHANGED
@@ -135,39 +135,50 @@ 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 = [];
148
+ const serverName = 'ppdocs-kg';
141
149
  // 检测 Claude CLI
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} -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp@latest`;
147
156
  execSync(cmd, { stdio: 'inherit' });
148
157
  }
149
158
  catch (e) {
150
159
  console.log(`⚠️ Claude MCP registration failed: ${e}`);
151
160
  }
152
161
  }
153
- // 检测 Codex CLI (OpenAI)
162
+ // 检测 Codex CLI (OpenAI) - 使用 --env 而非 -e
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} --env PPDOCS_API_URL=${apiUrl} --env PPDOCS_USER=${user} -- npx -y @ppdocs/mcp@latest`;
159
169
  execSync(cmd, { stdio: 'inherit' });
160
170
  }
161
171
  catch (e) {
162
172
  console.log(`⚠️ Codex MCP registration failed: ${e}`);
163
173
  }
164
174
  }
165
- // 检测 Gemini CLI
175
+ // 检测 Gemini CLI - 命令在位置参数,-e 在后面
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" -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user}`;
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?: Array<{
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?: Array<{
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>;
@@ -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?: UserStyleItem[];
48
+ userStyles?: string[];
55
49
  createdAt?: string;
56
50
  updatedAt?: string;
57
51
  lastAccessedAt?: string;
@@ -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.object({
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
@@ -2,7 +2,7 @@
2
2
  * MCP Server 工具函数
3
3
  */
4
4
  /**
5
- * 获取根节点的用户风格 (优先 userStyles, 兼容 description)
5
+ * 获取根节点的用户风格
6
6
  */
7
7
  export declare function getRootStyle(projectId: string): Promise<string>;
8
8
  /**
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 数组格式化为 Markdown 文本
9
+ * 将 userStyles 字符串数组格式化为 Markdown 列表
16
10
  */
17
11
  function formatUserStyles(styles) {
18
12
  if (!styles || styles.length === 0)
19
13
  return '';
20
- const groups = { config: [], style: [], reference: [] };
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
- * 获取根节点的用户风格 (优先 userStyles, 兼容 description)
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
- // 优先使用结构化 userStyles
31
+ // 使用 userStyles 字符串数组
51
32
  if (rootNode.userStyles && rootNode.userStyles.length > 0) {
52
33
  cachedRootStyle = formatUserStyles(rootNode.userStyles);
53
34
  }
54
35
  else {
55
- // 兼容旧版: 使用 description 字段
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 `[项目风格]\n${style}\n\n---\n[结果]\n${result}`;
60
+ return `[项目规则]\n${style}\n\n---\n[结果]\n${result}`;
82
61
  }
83
62
  /**
84
63
  * 解码 Unicode 转义序列
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ppdocs/mcp",
3
- "version": "2.6.5",
3
+ "version": "2.6.6",
4
4
  "description": "ppdocs MCP Server - Knowledge Graph for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",