@ppdocs/mcp 3.8.0 → 3.9.1
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 +19 -10
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* 命令: init - 初始化项目配置 + 安装工作流模板 + 自动注册 MCP
|
|
4
4
|
*/
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
+
import * as os from 'os';
|
|
6
7
|
import * as path from 'path';
|
|
7
8
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import { execSync } from 'child_process';
|
|
9
|
+
import { execSync, spawnSync } from 'child_process';
|
|
9
10
|
import { generateUser } from './config.js';
|
|
10
11
|
import { PpdocsApiClient } from './storage/httpClient.js';
|
|
11
12
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -258,25 +259,33 @@ function execSilent(cmd) {
|
|
|
258
259
|
function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
259
260
|
const detected = [];
|
|
260
261
|
const serverName = 'ppdocs-kg';
|
|
261
|
-
const addCmd = `-- npx -y @ppdocs/mcp@latest`;
|
|
262
262
|
const envPairs = [
|
|
263
263
|
`PPDOCS_API_URL=${apiUrl}`,
|
|
264
264
|
`PPDOCS_USER=${user}`,
|
|
265
265
|
`PPDOCS_PROJECT_ROOT=${cwd}`,
|
|
266
266
|
];
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
/** 用 spawnSync + args 数组注册 MCP,避免 Windows cmd.exe 引号解析问题 */
|
|
268
|
+
function mcpAdd(cli, envFlag) {
|
|
269
|
+
const args = ['mcp', 'add'];
|
|
270
|
+
for (const pair of envPairs) {
|
|
271
|
+
args.push(envFlag, pair);
|
|
272
|
+
}
|
|
273
|
+
args.push(serverName, '--', 'npx', '-y', '@ppdocs/mcp@latest');
|
|
274
|
+
const result = spawnSync(cli, args, { stdio: 'inherit', shell: true });
|
|
275
|
+
if (result.status !== 0)
|
|
276
|
+
throw new Error(`${cli} mcp add failed`);
|
|
277
|
+
}
|
|
269
278
|
// Claude CLI
|
|
270
279
|
if (commandExists('claude')) {
|
|
271
280
|
detected.push('Claude');
|
|
272
281
|
try {
|
|
273
282
|
execSilent(`claude mcp remove ${serverName}`);
|
|
274
|
-
|
|
283
|
+
mcpAdd('claude', '-e');
|
|
275
284
|
}
|
|
276
285
|
catch {
|
|
277
286
|
try {
|
|
278
287
|
execSilent(`claude mcp remove ${serverName}`);
|
|
279
|
-
|
|
288
|
+
mcpAdd('claude', '-e');
|
|
280
289
|
}
|
|
281
290
|
catch {
|
|
282
291
|
console.log(`⚠️ Claude MCP registration failed`);
|
|
@@ -288,18 +297,18 @@ function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
|
288
297
|
detected.push('Codex');
|
|
289
298
|
try {
|
|
290
299
|
execSilent(`codex mcp remove ${serverName}`);
|
|
291
|
-
|
|
300
|
+
mcpAdd('codex', '--env');
|
|
292
301
|
}
|
|
293
302
|
catch {
|
|
294
303
|
console.log(`⚠️ Codex MCP registration failed`);
|
|
295
304
|
}
|
|
296
305
|
}
|
|
297
|
-
// Gemini CLI
|
|
306
|
+
// Gemini CLI (gemini mcp add 不支持 --env,直接写 settings.json)
|
|
298
307
|
if (commandExists('gemini') && !skipGemini) {
|
|
299
308
|
detected.push('Gemini');
|
|
300
309
|
try {
|
|
301
|
-
|
|
302
|
-
|
|
310
|
+
const geminiSettings = path.join(os.homedir(), '.gemini', 'settings.json');
|
|
311
|
+
createMcpConfigAt(geminiSettings, apiUrl, { user, projectRoot: cwd });
|
|
303
312
|
}
|
|
304
313
|
catch {
|
|
305
314
|
console.log(`⚠️ Gemini MCP registration failed`);
|