@ppdocs/mcp 3.9.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 +15 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as fs from 'fs';
|
|
|
6
6
|
import * as os from 'os';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
-
import { execSync } from 'child_process';
|
|
9
|
+
import { execSync, spawnSync } from 'child_process';
|
|
10
10
|
import { generateUser } from './config.js';
|
|
11
11
|
import { PpdocsApiClient } from './storage/httpClient.js';
|
|
12
12
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -259,25 +259,33 @@ function execSilent(cmd) {
|
|
|
259
259
|
function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
260
260
|
const detected = [];
|
|
261
261
|
const serverName = 'ppdocs-kg';
|
|
262
|
-
const addCmd = `-- npx -y @ppdocs/mcp@latest`;
|
|
263
262
|
const envPairs = [
|
|
264
263
|
`PPDOCS_API_URL=${apiUrl}`,
|
|
265
264
|
`PPDOCS_USER=${user}`,
|
|
266
265
|
`PPDOCS_PROJECT_ROOT=${cwd}`,
|
|
267
266
|
];
|
|
268
|
-
|
|
269
|
-
|
|
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
|
+
}
|
|
270
278
|
// Claude CLI
|
|
271
279
|
if (commandExists('claude')) {
|
|
272
280
|
detected.push('Claude');
|
|
273
281
|
try {
|
|
274
282
|
execSilent(`claude mcp remove ${serverName}`);
|
|
275
|
-
|
|
283
|
+
mcpAdd('claude', '-e');
|
|
276
284
|
}
|
|
277
285
|
catch {
|
|
278
286
|
try {
|
|
279
287
|
execSilent(`claude mcp remove ${serverName}`);
|
|
280
|
-
|
|
288
|
+
mcpAdd('claude', '-e');
|
|
281
289
|
}
|
|
282
290
|
catch {
|
|
283
291
|
console.log(`⚠️ Claude MCP registration failed`);
|
|
@@ -289,7 +297,7 @@ function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
|
289
297
|
detected.push('Codex');
|
|
290
298
|
try {
|
|
291
299
|
execSilent(`codex mcp remove ${serverName}`);
|
|
292
|
-
|
|
300
|
+
mcpAdd('codex', '--env');
|
|
293
301
|
}
|
|
294
302
|
catch {
|
|
295
303
|
console.log(`⚠️ Codex MCP registration failed`);
|