@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.
Files changed (2) hide show
  1. package/dist/cli.js +19 -10
  2. 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
- const claudeEnvArgs = envPairs.map((pair) => `-e ${JSON.stringify(pair)}`).join(' ');
268
- const codexEnvArgs = envPairs.map((pair) => `--env ${JSON.stringify(pair)}`).join(' ');
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
- execSync(`claude mcp add ${claudeEnvArgs} ${serverName} ${addCmd}`, { stdio: 'inherit' });
283
+ mcpAdd('claude', '-e');
275
284
  }
276
285
  catch {
277
286
  try {
278
287
  execSilent(`claude mcp remove ${serverName}`);
279
- execSync(`claude mcp add ${claudeEnvArgs} ${serverName} ${addCmd}`, { stdio: 'inherit' });
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
- execSync(`codex mcp add ${codexEnvArgs} ${serverName} ${addCmd}`, { stdio: 'inherit' });
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
- execSilent(`gemini mcp remove ${serverName}`);
302
- execSync(`gemini mcp add ${serverName} "npx -y @ppdocs/mcp@latest"`, { stdio: 'inherit' });
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`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ppdocs/mcp",
3
- "version": "3.8.0",
3
+ "version": "3.9.1",
4
4
  "description": "ppdocs MCP Server - Knowledge Graph for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",