@ppdocs/mcp 3.2.16 → 3.2.18
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.d.ts +2 -2
- package/dist/cli.js +48 -73
- package/dist/config.js +1 -1
- package/dist/index.js +2 -10
- package/package.json +2 -3
package/dist/cli.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* ppdocs MCP CLI
|
|
3
3
|
* 命令: init - 初始化项目配置 + 安装工作流模板 + 自动注册 MCP
|
|
4
4
|
*/
|
|
5
|
-
export declare function runCli(args: string[]): Promise<
|
|
5
|
+
export declare function runCli(args: string[]): Promise<boolean>;
|
|
6
6
|
/** 安装项目模板文件 (供授权后自动配置调用) */
|
|
7
|
-
export declare function setupProjectFiles(cwd: string, apiUrl: string): void;
|
|
7
|
+
export declare function setupProjectFiles(cwd: string, apiUrl: string, user?: string): void;
|
package/dist/cli.js
CHANGED
|
@@ -90,7 +90,6 @@ ppdocs MCP CLI
|
|
|
90
90
|
|
|
91
91
|
Commands:
|
|
92
92
|
init Initialize ppdocs config + install workflow templates
|
|
93
|
-
webui Start PPDocs Web UI (MCP management + File Sync)
|
|
94
93
|
|
|
95
94
|
Usage:
|
|
96
95
|
npx @ppdocs/mcp init -p <projectId> -k <key> [options]
|
|
@@ -122,16 +121,11 @@ export async function runCli(args) {
|
|
|
122
121
|
process.exit(1);
|
|
123
122
|
}
|
|
124
123
|
await initProject(opts);
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
if (cmd === 'webui') {
|
|
128
|
-
// 动态导入 WebUI 入口 (Web UI + 多项目管理) — 长驻进程,不退出
|
|
129
|
-
await import('./agent.js');
|
|
130
|
-
return 'keep-alive';
|
|
124
|
+
return true;
|
|
131
125
|
}
|
|
132
126
|
if (cmd === '--help' || cmd === '-h' || cmd === 'help') {
|
|
133
127
|
showHelp();
|
|
134
|
-
return
|
|
128
|
+
return true;
|
|
135
129
|
}
|
|
136
130
|
return false; // Not a CLI command, run as MCP server
|
|
137
131
|
}
|
|
@@ -164,15 +158,15 @@ async function initProject(opts) {
|
|
|
164
158
|
hasIdeDir = true;
|
|
165
159
|
}
|
|
166
160
|
if (detectedIdes.includes('cursor')) {
|
|
167
|
-
installCursorTemplates(cwd, apiUrl);
|
|
161
|
+
installCursorTemplates(cwd, apiUrl, opts.user);
|
|
168
162
|
hasIdeDir = true;
|
|
169
163
|
}
|
|
170
164
|
if (detectedIdes.includes('antigravity')) {
|
|
171
|
-
installAntigravityTemplates(cwd, apiUrl);
|
|
165
|
+
installAntigravityTemplates(cwd, apiUrl, opts.user);
|
|
172
166
|
hasIdeDir = true;
|
|
173
167
|
}
|
|
174
168
|
if (detectedIdes.includes('kiro')) {
|
|
175
|
-
installKiroTemplates(cwd, apiUrl);
|
|
169
|
+
installKiroTemplates(cwd, apiUrl, opts.user);
|
|
176
170
|
hasIdeDir = true;
|
|
177
171
|
}
|
|
178
172
|
// Fallback behavior: if no specific IDE config directories found
|
|
@@ -188,7 +182,7 @@ async function initProject(opts) {
|
|
|
188
182
|
const registered = autoRegisterMcp(apiUrl, opts.user, detectedIdes.includes('antigravity'));
|
|
189
183
|
// 如果没有检测到任何 AI CLI,并且也没有检测到配置文件夹,创建 .mcp.json 作为备用
|
|
190
184
|
if (!registered && !hasIdeDir) {
|
|
191
|
-
createMcpJson(cwd, apiUrl);
|
|
185
|
+
createMcpJson(cwd, apiUrl, opts.user);
|
|
192
186
|
}
|
|
193
187
|
// --from: 从模板项目拉取 IDE 配置文件
|
|
194
188
|
if (opts.from) {
|
|
@@ -282,61 +276,46 @@ function execSilent(cmd) {
|
|
|
282
276
|
}
|
|
283
277
|
catch { /* ignore */ }
|
|
284
278
|
}
|
|
285
|
-
/** 自动检测 AI CLI 并注册 MCP */
|
|
279
|
+
/** 自动检测 AI CLI 并注册 MCP (注入环境变量实现启动即就绪) */
|
|
286
280
|
function autoRegisterMcp(apiUrl, user, skipGemini = false) {
|
|
287
281
|
const detected = [];
|
|
288
282
|
const serverName = 'ppdocs-kg';
|
|
289
|
-
|
|
283
|
+
const envFlags = `-e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user}`;
|
|
284
|
+
// Claude CLI
|
|
290
285
|
if (commandExists('claude')) {
|
|
291
286
|
detected.push('Claude');
|
|
292
287
|
try {
|
|
293
288
|
console.log(`✅ Detected Claude CLI, registering MCP...`);
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
console.log(`✅ Claude MCP already configured`);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
const cmd = `claude mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
301
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
302
|
-
}
|
|
289
|
+
// 先移除旧配置(可能无 env),再重新注册
|
|
290
|
+
execSilent(`claude mcp remove ${serverName}`);
|
|
291
|
+
execSync(`claude mcp add ${serverName} ${envFlags} -- npx -y @ppdocs/mcp@latest`, { stdio: 'inherit' });
|
|
303
292
|
}
|
|
304
|
-
catch
|
|
305
|
-
|
|
306
|
-
try {
|
|
307
|
-
execSilent(`claude mcp remove ${serverName}`);
|
|
308
|
-
const cmd = `claude mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
309
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
310
|
-
}
|
|
311
|
-
catch {
|
|
312
|
-
console.log(`⚠️ Claude MCP registration failed`);
|
|
313
|
-
}
|
|
293
|
+
catch {
|
|
294
|
+
console.log(`⚠️ Claude MCP registration failed`);
|
|
314
295
|
}
|
|
315
296
|
}
|
|
316
|
-
//
|
|
297
|
+
// Codex CLI (OpenAI)
|
|
317
298
|
if (commandExists('codex')) {
|
|
318
299
|
detected.push('Codex');
|
|
319
300
|
try {
|
|
320
301
|
console.log(`✅ Detected Codex CLI, registering MCP...`);
|
|
321
302
|
execSilent(`codex mcp remove ${serverName}`);
|
|
322
|
-
|
|
323
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
303
|
+
execSync(`codex mcp add ${serverName} ${envFlags} -- npx -y @ppdocs/mcp@latest`, { stdio: 'inherit' });
|
|
324
304
|
}
|
|
325
|
-
catch
|
|
326
|
-
console.log(`⚠️ Codex MCP registration failed
|
|
305
|
+
catch {
|
|
306
|
+
console.log(`⚠️ Codex MCP registration failed`);
|
|
327
307
|
}
|
|
328
308
|
}
|
|
329
|
-
//
|
|
309
|
+
// Gemini CLI
|
|
330
310
|
if (commandExists('gemini') && !skipGemini) {
|
|
331
311
|
detected.push('Gemini');
|
|
332
312
|
try {
|
|
333
313
|
console.log(`✅ Detected Gemini CLI, registering MCP...`);
|
|
334
314
|
execSilent(`gemini mcp remove ${serverName}`);
|
|
335
|
-
|
|
336
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
315
|
+
execSync(`gemini mcp add ${serverName} "npx -y @ppdocs/mcp@latest"`, { stdio: 'inherit' });
|
|
337
316
|
}
|
|
338
|
-
catch
|
|
339
|
-
console.log(`⚠️ Gemini MCP registration failed
|
|
317
|
+
catch {
|
|
318
|
+
console.log(`⚠️ Gemini MCP registration failed`);
|
|
340
319
|
}
|
|
341
320
|
}
|
|
342
321
|
if (detected.length === 0) {
|
|
@@ -346,34 +325,33 @@ function autoRegisterMcp(apiUrl, user, skipGemini = false) {
|
|
|
346
325
|
console.log(`✅ Registered MCP for: ${detected.join(', ')}`);
|
|
347
326
|
return true;
|
|
348
327
|
}
|
|
349
|
-
/** 在指定路径创建或更新 mcp.json
|
|
350
|
-
function createMcpConfigAt(mcpPath,
|
|
328
|
+
/** 在指定路径创建或更新 mcp.json 配置,注入 PPDOCS_API_URL 环境变量实现启动即就绪 */
|
|
329
|
+
function createMcpConfigAt(mcpPath, apiUrl, options) {
|
|
351
330
|
let mcpConfig = {};
|
|
352
331
|
if (fs.existsSync(mcpPath)) {
|
|
353
332
|
try {
|
|
354
333
|
mcpConfig = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
|
|
355
334
|
}
|
|
356
335
|
catch {
|
|
357
|
-
// 解析失败时中止,避免清空已有配置
|
|
358
336
|
console.log(`⚠️ ${mcpPath} JSON格式无效,跳过MCP配置写入(请手动修复后重试)`);
|
|
359
337
|
return;
|
|
360
338
|
}
|
|
361
339
|
}
|
|
362
|
-
// Windows 需要 cmd /c 包装才能执行 npx
|
|
363
340
|
const isWindows = process.platform === 'win32';
|
|
364
|
-
// 对于 Mac/Linux,IDE 可能没有用户的完整 PATH,导致找不到 npx
|
|
365
341
|
const macExtraPaths = '/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin';
|
|
366
342
|
const actualPath = `${process.env.PATH || '/usr/bin:/bin'}:${macExtraPaths}`;
|
|
343
|
+
// 构建 env: 非 Windows 补 PATH + 注入项目绑定变量
|
|
344
|
+
const env = {};
|
|
345
|
+
if (!isWindows)
|
|
346
|
+
env.PATH = actualPath;
|
|
347
|
+
if (!options?.noEnv) {
|
|
348
|
+
env.PPDOCS_API_URL = apiUrl;
|
|
349
|
+
if (options?.user)
|
|
350
|
+
env.PPDOCS_USER = options.user;
|
|
351
|
+
}
|
|
367
352
|
const ppdocsServer = isWindows
|
|
368
|
-
? {
|
|
369
|
-
|
|
370
|
-
args: ['/c', 'npx', '-y', '@ppdocs/mcp@latest'],
|
|
371
|
-
}
|
|
372
|
-
: {
|
|
373
|
-
command: 'npx',
|
|
374
|
-
args: ['-y', '@ppdocs/mcp@latest'],
|
|
375
|
-
env: { "PATH": actualPath }
|
|
376
|
-
};
|
|
353
|
+
? { command: 'cmd', args: ['/c', 'npx', '-y', '@ppdocs/mcp@latest'], ...(Object.keys(env).length > 0 && { env }) }
|
|
354
|
+
: { command: 'npx', args: ['-y', '@ppdocs/mcp@latest'], env };
|
|
377
355
|
mcpConfig.mcpServers = {
|
|
378
356
|
...(mcpConfig.mcpServers || {}),
|
|
379
357
|
"ppdocs-kg": ppdocsServer,
|
|
@@ -387,8 +365,8 @@ function createMcpConfigAt(mcpPath, _apiUrl, _options) {
|
|
|
387
365
|
console.log(`✅ Configured MCP in ${mcpPath}`);
|
|
388
366
|
}
|
|
389
367
|
/** 创建 .mcp.json (手动配置备用) */
|
|
390
|
-
function createMcpJson(cwd, apiUrl) {
|
|
391
|
-
createMcpConfigAt(path.join(cwd, '.mcp.json'), apiUrl);
|
|
368
|
+
function createMcpJson(cwd, apiUrl, user) {
|
|
369
|
+
createMcpConfigAt(path.join(cwd, '.mcp.json'), apiUrl, { user });
|
|
392
370
|
}
|
|
393
371
|
/** 递归复制目录 */
|
|
394
372
|
function copyDirRecursive(src, dest) {
|
|
@@ -511,9 +489,8 @@ function generateAgentsMd(cwd) {
|
|
|
511
489
|
}
|
|
512
490
|
}
|
|
513
491
|
/** 安装 Cursor 模板 */
|
|
514
|
-
function installCursorTemplates(cwd, apiUrl) {
|
|
515
|
-
|
|
516
|
-
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'), apiUrl);
|
|
492
|
+
function installCursorTemplates(cwd, apiUrl, user) {
|
|
493
|
+
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'), apiUrl, { user });
|
|
517
494
|
// 2. 生成 .cursorrules 提示词
|
|
518
495
|
const srcRules = path.join(TEMPLATES_DIR, 'cursorrules.md');
|
|
519
496
|
const destRules = path.join(cwd, '.cursorrules');
|
|
@@ -523,9 +500,9 @@ function installCursorTemplates(cwd, apiUrl) {
|
|
|
523
500
|
}
|
|
524
501
|
}
|
|
525
502
|
/** 安装 Antigravity (Gemini IDE) 模板 */
|
|
526
|
-
function installAntigravityTemplates(cwd, apiUrl) {
|
|
527
|
-
//
|
|
528
|
-
createMcpConfigAt(path.join(cwd, '.gemini', 'settings.json'), apiUrl, { noEnv: true });
|
|
503
|
+
function installAntigravityTemplates(cwd, apiUrl, user) {
|
|
504
|
+
// Antigravity 由 gemini CLI 注册 env,文件配置不注入避免冲突
|
|
505
|
+
createMcpConfigAt(path.join(cwd, '.gemini', 'settings.json'), apiUrl, { noEnv: true, user });
|
|
529
506
|
// 2. 生成 AGENTS.md
|
|
530
507
|
generateAgentsMd(cwd);
|
|
531
508
|
// 3. 安装斜杠命令 → 全局目录 ~/.gemini/antigravity/global_workflows/
|
|
@@ -581,9 +558,8 @@ function installAntigravityTemplates(cwd, apiUrl) {
|
|
|
581
558
|
}
|
|
582
559
|
}
|
|
583
560
|
/** 安装 Kiro 模板 */
|
|
584
|
-
function installKiroTemplates(cwd, apiUrl) {
|
|
585
|
-
|
|
586
|
-
createMcpConfigAt(path.join(cwd, '.kiro', 'settings', 'mcp.json'), apiUrl);
|
|
561
|
+
function installKiroTemplates(cwd, apiUrl, user) {
|
|
562
|
+
createMcpConfigAt(path.join(cwd, '.kiro', 'settings', 'mcp.json'), apiUrl, { user });
|
|
587
563
|
// 2. 生成 Kiro Agent 规则
|
|
588
564
|
const kiroRulesDir = path.join(cwd, '.kiro', 'rules');
|
|
589
565
|
if (!fs.existsSync(kiroRulesDir)) {
|
|
@@ -610,21 +586,20 @@ function detectIDEs(cwd) {
|
|
|
610
586
|
return ides;
|
|
611
587
|
}
|
|
612
588
|
/** 安装项目模板文件 (供授权后自动配置调用) */
|
|
613
|
-
export function setupProjectFiles(cwd, apiUrl) {
|
|
589
|
+
export function setupProjectFiles(cwd, apiUrl, user) {
|
|
614
590
|
const detectedIdes = detectIDEs(cwd);
|
|
615
591
|
if (detectedIdes.includes('antigravity')) {
|
|
616
|
-
installAntigravityTemplates(cwd, apiUrl);
|
|
592
|
+
installAntigravityTemplates(cwd, apiUrl, user);
|
|
617
593
|
}
|
|
618
594
|
if (detectedIdes.includes('cursor')) {
|
|
619
|
-
installCursorTemplates(cwd, apiUrl);
|
|
595
|
+
installCursorTemplates(cwd, apiUrl, user);
|
|
620
596
|
}
|
|
621
597
|
if (detectedIdes.includes('kiro')) {
|
|
622
|
-
installKiroTemplates(cwd, apiUrl);
|
|
598
|
+
installKiroTemplates(cwd, apiUrl, user);
|
|
623
599
|
}
|
|
624
600
|
if (detectedIdes.includes('claude')) {
|
|
625
601
|
installClaudeTemplates(cwd);
|
|
626
602
|
}
|
|
627
|
-
// 如果没检测到任何 IDE,默认安装 Claude 模板
|
|
628
603
|
if (detectedIdes.length === 0) {
|
|
629
604
|
installClaudeTemplates(cwd);
|
|
630
605
|
}
|
package/dist/config.js
CHANGED
|
@@ -38,7 +38,7 @@ export async function loadConfig() {
|
|
|
38
38
|
const envConfig = readEnvConfig();
|
|
39
39
|
if (envConfig)
|
|
40
40
|
return envConfig;
|
|
41
|
-
// 2. .ppdocs 文件 (由
|
|
41
|
+
// 2. .ppdocs 文件 (由 init 命令生成)
|
|
42
42
|
const fileConfig = readPpdocsFile();
|
|
43
43
|
if (fileConfig)
|
|
44
44
|
return fileConfig;
|
package/dist/index.js
CHANGED
|
@@ -22,17 +22,9 @@ const VERSION = pkg.version;
|
|
|
22
22
|
// 检查是否为 CLI 命令
|
|
23
23
|
const args = process.argv.slice(2);
|
|
24
24
|
if (args.length > 0) {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
25
|
+
const handled = await runCli(args);
|
|
26
|
+
if (handled)
|
|
27
27
|
process.exit(0);
|
|
28
|
-
if (result === 'keep-alive') {
|
|
29
|
-
// webui 长驻模式,不继续执行 MCP Server
|
|
30
|
-
// 用 setInterval 保活,避免 Node.js 'unsettled top-level await' 警告
|
|
31
|
-
setInterval(() => { }, 1 << 30);
|
|
32
|
-
// @ts-ignore: 防止后续 main() 执行
|
|
33
|
-
await new Promise(() => { });
|
|
34
|
-
}
|
|
35
|
-
// result === false → 继续作为 MCP Server
|
|
36
28
|
}
|
|
37
29
|
// 运行 MCP 服务
|
|
38
30
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ppdocs/mcp",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.18",
|
|
4
4
|
"description": "ppdocs MCP Server - Knowledge Graph for Claude",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"ppdocs": "dist/index.js",
|
|
9
9
|
"mcp": "dist/index.js",
|
|
10
|
-
"ppdocs-mcp": "dist/index.js"
|
|
11
|
-
"ppdocs-agent": "dist/agent.js"
|
|
10
|
+
"ppdocs-mcp": "dist/index.js"
|
|
12
11
|
},
|
|
13
12
|
"scripts": {
|
|
14
13
|
"prebuild": "node scripts/copy-templates.js",
|