@ppdocs/mcp 3.2.17 → 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 +1 -1
- package/dist/cli.js +46 -65
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
*/
|
|
5
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
|
@@ -158,15 +158,15 @@ async function initProject(opts) {
|
|
|
158
158
|
hasIdeDir = true;
|
|
159
159
|
}
|
|
160
160
|
if (detectedIdes.includes('cursor')) {
|
|
161
|
-
installCursorTemplates(cwd, apiUrl);
|
|
161
|
+
installCursorTemplates(cwd, apiUrl, opts.user);
|
|
162
162
|
hasIdeDir = true;
|
|
163
163
|
}
|
|
164
164
|
if (detectedIdes.includes('antigravity')) {
|
|
165
|
-
installAntigravityTemplates(cwd, apiUrl);
|
|
165
|
+
installAntigravityTemplates(cwd, apiUrl, opts.user);
|
|
166
166
|
hasIdeDir = true;
|
|
167
167
|
}
|
|
168
168
|
if (detectedIdes.includes('kiro')) {
|
|
169
|
-
installKiroTemplates(cwd, apiUrl);
|
|
169
|
+
installKiroTemplates(cwd, apiUrl, opts.user);
|
|
170
170
|
hasIdeDir = true;
|
|
171
171
|
}
|
|
172
172
|
// Fallback behavior: if no specific IDE config directories found
|
|
@@ -182,7 +182,7 @@ async function initProject(opts) {
|
|
|
182
182
|
const registered = autoRegisterMcp(apiUrl, opts.user, detectedIdes.includes('antigravity'));
|
|
183
183
|
// 如果没有检测到任何 AI CLI,并且也没有检测到配置文件夹,创建 .mcp.json 作为备用
|
|
184
184
|
if (!registered && !hasIdeDir) {
|
|
185
|
-
createMcpJson(cwd, apiUrl);
|
|
185
|
+
createMcpJson(cwd, apiUrl, opts.user);
|
|
186
186
|
}
|
|
187
187
|
// --from: 从模板项目拉取 IDE 配置文件
|
|
188
188
|
if (opts.from) {
|
|
@@ -276,61 +276,46 @@ function execSilent(cmd) {
|
|
|
276
276
|
}
|
|
277
277
|
catch { /* ignore */ }
|
|
278
278
|
}
|
|
279
|
-
/** 自动检测 AI CLI 并注册 MCP */
|
|
279
|
+
/** 自动检测 AI CLI 并注册 MCP (注入环境变量实现启动即就绪) */
|
|
280
280
|
function autoRegisterMcp(apiUrl, user, skipGemini = false) {
|
|
281
281
|
const detected = [];
|
|
282
282
|
const serverName = 'ppdocs-kg';
|
|
283
|
-
|
|
283
|
+
const envFlags = `-e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user}`;
|
|
284
|
+
// Claude CLI
|
|
284
285
|
if (commandExists('claude')) {
|
|
285
286
|
detected.push('Claude');
|
|
286
287
|
try {
|
|
287
288
|
console.log(`✅ Detected Claude CLI, registering MCP...`);
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
console.log(`✅ Claude MCP already configured`);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
const cmd = `claude mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
295
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
296
|
-
}
|
|
289
|
+
// 先移除旧配置(可能无 env),再重新注册
|
|
290
|
+
execSilent(`claude mcp remove ${serverName}`);
|
|
291
|
+
execSync(`claude mcp add ${serverName} ${envFlags} -- npx -y @ppdocs/mcp@latest`, { stdio: 'inherit' });
|
|
297
292
|
}
|
|
298
|
-
catch
|
|
299
|
-
|
|
300
|
-
try {
|
|
301
|
-
execSilent(`claude mcp remove ${serverName}`);
|
|
302
|
-
const cmd = `claude mcp add ${serverName} -- npx -y @ppdocs/mcp@latest`;
|
|
303
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
console.log(`⚠️ Claude MCP registration failed`);
|
|
307
|
-
}
|
|
293
|
+
catch {
|
|
294
|
+
console.log(`⚠️ Claude MCP registration failed`);
|
|
308
295
|
}
|
|
309
296
|
}
|
|
310
|
-
//
|
|
297
|
+
// Codex CLI (OpenAI)
|
|
311
298
|
if (commandExists('codex')) {
|
|
312
299
|
detected.push('Codex');
|
|
313
300
|
try {
|
|
314
301
|
console.log(`✅ Detected Codex CLI, registering MCP...`);
|
|
315
302
|
execSilent(`codex mcp remove ${serverName}`);
|
|
316
|
-
|
|
317
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
303
|
+
execSync(`codex mcp add ${serverName} ${envFlags} -- npx -y @ppdocs/mcp@latest`, { stdio: 'inherit' });
|
|
318
304
|
}
|
|
319
|
-
catch
|
|
320
|
-
console.log(`⚠️ Codex MCP registration failed
|
|
305
|
+
catch {
|
|
306
|
+
console.log(`⚠️ Codex MCP registration failed`);
|
|
321
307
|
}
|
|
322
308
|
}
|
|
323
|
-
//
|
|
309
|
+
// Gemini CLI
|
|
324
310
|
if (commandExists('gemini') && !skipGemini) {
|
|
325
311
|
detected.push('Gemini');
|
|
326
312
|
try {
|
|
327
313
|
console.log(`✅ Detected Gemini CLI, registering MCP...`);
|
|
328
314
|
execSilent(`gemini mcp remove ${serverName}`);
|
|
329
|
-
|
|
330
|
-
execSync(cmd, { stdio: 'inherit' });
|
|
315
|
+
execSync(`gemini mcp add ${serverName} "npx -y @ppdocs/mcp@latest"`, { stdio: 'inherit' });
|
|
331
316
|
}
|
|
332
|
-
catch
|
|
333
|
-
console.log(`⚠️ Gemini MCP registration failed
|
|
317
|
+
catch {
|
|
318
|
+
console.log(`⚠️ Gemini MCP registration failed`);
|
|
334
319
|
}
|
|
335
320
|
}
|
|
336
321
|
if (detected.length === 0) {
|
|
@@ -340,34 +325,33 @@ function autoRegisterMcp(apiUrl, user, skipGemini = false) {
|
|
|
340
325
|
console.log(`✅ Registered MCP for: ${detected.join(', ')}`);
|
|
341
326
|
return true;
|
|
342
327
|
}
|
|
343
|
-
/** 在指定路径创建或更新 mcp.json
|
|
344
|
-
function createMcpConfigAt(mcpPath,
|
|
328
|
+
/** 在指定路径创建或更新 mcp.json 配置,注入 PPDOCS_API_URL 环境变量实现启动即就绪 */
|
|
329
|
+
function createMcpConfigAt(mcpPath, apiUrl, options) {
|
|
345
330
|
let mcpConfig = {};
|
|
346
331
|
if (fs.existsSync(mcpPath)) {
|
|
347
332
|
try {
|
|
348
333
|
mcpConfig = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
|
|
349
334
|
}
|
|
350
335
|
catch {
|
|
351
|
-
// 解析失败时中止,避免清空已有配置
|
|
352
336
|
console.log(`⚠️ ${mcpPath} JSON格式无效,跳过MCP配置写入(请手动修复后重试)`);
|
|
353
337
|
return;
|
|
354
338
|
}
|
|
355
339
|
}
|
|
356
|
-
// Windows 需要 cmd /c 包装才能执行 npx
|
|
357
340
|
const isWindows = process.platform === 'win32';
|
|
358
|
-
// 对于 Mac/Linux,IDE 可能没有用户的完整 PATH,导致找不到 npx
|
|
359
341
|
const macExtraPaths = '/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin';
|
|
360
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
|
+
}
|
|
361
352
|
const ppdocsServer = isWindows
|
|
362
|
-
? {
|
|
363
|
-
|
|
364
|
-
args: ['/c', 'npx', '-y', '@ppdocs/mcp@latest'],
|
|
365
|
-
}
|
|
366
|
-
: {
|
|
367
|
-
command: 'npx',
|
|
368
|
-
args: ['-y', '@ppdocs/mcp@latest'],
|
|
369
|
-
env: { "PATH": actualPath }
|
|
370
|
-
};
|
|
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 };
|
|
371
355
|
mcpConfig.mcpServers = {
|
|
372
356
|
...(mcpConfig.mcpServers || {}),
|
|
373
357
|
"ppdocs-kg": ppdocsServer,
|
|
@@ -381,8 +365,8 @@ function createMcpConfigAt(mcpPath, _apiUrl, _options) {
|
|
|
381
365
|
console.log(`✅ Configured MCP in ${mcpPath}`);
|
|
382
366
|
}
|
|
383
367
|
/** 创建 .mcp.json (手动配置备用) */
|
|
384
|
-
function createMcpJson(cwd, apiUrl) {
|
|
385
|
-
createMcpConfigAt(path.join(cwd, '.mcp.json'), apiUrl);
|
|
368
|
+
function createMcpJson(cwd, apiUrl, user) {
|
|
369
|
+
createMcpConfigAt(path.join(cwd, '.mcp.json'), apiUrl, { user });
|
|
386
370
|
}
|
|
387
371
|
/** 递归复制目录 */
|
|
388
372
|
function copyDirRecursive(src, dest) {
|
|
@@ -505,9 +489,8 @@ function generateAgentsMd(cwd) {
|
|
|
505
489
|
}
|
|
506
490
|
}
|
|
507
491
|
/** 安装 Cursor 模板 */
|
|
508
|
-
function installCursorTemplates(cwd, apiUrl) {
|
|
509
|
-
|
|
510
|
-
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'), apiUrl);
|
|
492
|
+
function installCursorTemplates(cwd, apiUrl, user) {
|
|
493
|
+
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'), apiUrl, { user });
|
|
511
494
|
// 2. 生成 .cursorrules 提示词
|
|
512
495
|
const srcRules = path.join(TEMPLATES_DIR, 'cursorrules.md');
|
|
513
496
|
const destRules = path.join(cwd, '.cursorrules');
|
|
@@ -517,9 +500,9 @@ function installCursorTemplates(cwd, apiUrl) {
|
|
|
517
500
|
}
|
|
518
501
|
}
|
|
519
502
|
/** 安装 Antigravity (Gemini IDE) 模板 */
|
|
520
|
-
function installAntigravityTemplates(cwd, apiUrl) {
|
|
521
|
-
//
|
|
522
|
-
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 });
|
|
523
506
|
// 2. 生成 AGENTS.md
|
|
524
507
|
generateAgentsMd(cwd);
|
|
525
508
|
// 3. 安装斜杠命令 → 全局目录 ~/.gemini/antigravity/global_workflows/
|
|
@@ -575,9 +558,8 @@ function installAntigravityTemplates(cwd, apiUrl) {
|
|
|
575
558
|
}
|
|
576
559
|
}
|
|
577
560
|
/** 安装 Kiro 模板 */
|
|
578
|
-
function installKiroTemplates(cwd, apiUrl) {
|
|
579
|
-
|
|
580
|
-
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 });
|
|
581
563
|
// 2. 生成 Kiro Agent 规则
|
|
582
564
|
const kiroRulesDir = path.join(cwd, '.kiro', 'rules');
|
|
583
565
|
if (!fs.existsSync(kiroRulesDir)) {
|
|
@@ -604,21 +586,20 @@ function detectIDEs(cwd) {
|
|
|
604
586
|
return ides;
|
|
605
587
|
}
|
|
606
588
|
/** 安装项目模板文件 (供授权后自动配置调用) */
|
|
607
|
-
export function setupProjectFiles(cwd, apiUrl) {
|
|
589
|
+
export function setupProjectFiles(cwd, apiUrl, user) {
|
|
608
590
|
const detectedIdes = detectIDEs(cwd);
|
|
609
591
|
if (detectedIdes.includes('antigravity')) {
|
|
610
|
-
installAntigravityTemplates(cwd, apiUrl);
|
|
592
|
+
installAntigravityTemplates(cwd, apiUrl, user);
|
|
611
593
|
}
|
|
612
594
|
if (detectedIdes.includes('cursor')) {
|
|
613
|
-
installCursorTemplates(cwd, apiUrl);
|
|
595
|
+
installCursorTemplates(cwd, apiUrl, user);
|
|
614
596
|
}
|
|
615
597
|
if (detectedIdes.includes('kiro')) {
|
|
616
|
-
installKiroTemplates(cwd, apiUrl);
|
|
598
|
+
installKiroTemplates(cwd, apiUrl, user);
|
|
617
599
|
}
|
|
618
600
|
if (detectedIdes.includes('claude')) {
|
|
619
601
|
installClaudeTemplates(cwd);
|
|
620
602
|
}
|
|
621
|
-
// 如果没检测到任何 IDE,默认安装 Claude 模板
|
|
622
603
|
if (detectedIdes.length === 0) {
|
|
623
604
|
installClaudeTemplates(cwd);
|
|
624
605
|
}
|