@ppdocs/mcp 2.5.2 → 2.6.0

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * ppdocs MCP CLI
3
- * 命令: init - 初始化项目配置 + 安装工作流模板
3
+ * 命令: init - 初始化项目配置 + 安装工作流模板 + 自动注册 MCP
4
4
  */
5
5
  export declare function runCli(args: string[]): boolean;
package/dist/cli.js CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * ppdocs MCP CLI
3
- * 命令: init - 初始化项目配置 + 安装工作流模板
3
+ * 命令: init - 初始化项目配置 + 安装工作流模板 + 自动注册 MCP
4
4
  */
5
5
  import * as fs from 'fs';
6
6
  import * as path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
+ import { execSync } from 'child_process';
8
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
10
  const TEMPLATES_DIR = path.join(__dirname, '..', 'templates');
10
11
  /** 生成随机用户名 (8位字母数字) */
@@ -84,6 +85,7 @@ export function runCli(args) {
84
85
  }
85
86
  function initProject(opts) {
86
87
  const cwd = process.cwd();
88
+ const apiUrl = `http://${opts.api}:${opts.port}/api/${opts.project}/${opts.key}`;
87
89
  // Create .ppdocs config
88
90
  const ppdocsConfig = {
89
91
  api: `http://${opts.api}:${opts.port}`,
@@ -94,7 +96,85 @@ function initProject(opts) {
94
96
  const ppdocsPath = path.join(cwd, '.ppdocs');
95
97
  fs.writeFileSync(ppdocsPath, JSON.stringify(ppdocsConfig, null, 2));
96
98
  console.log(`✅ Created ${ppdocsPath}`);
97
- // Create or update .mcp.json
99
+ // Install workflow templates
100
+ if (opts.codex) {
101
+ installCodexTemplates(cwd);
102
+ }
103
+ else {
104
+ installClaudeTemplates(cwd);
105
+ }
106
+ // 自动检测并注册 MCP
107
+ const registered = autoRegisterMcp(apiUrl, opts.user);
108
+ // 如果没有检测到任何 AI CLI,创建 .mcp.json 作为备用
109
+ if (!registered) {
110
+ createMcpJson(cwd);
111
+ }
112
+ console.log(`
113
+ 🎉 Done! ppdocs MCP configured for project: ${opts.project}
114
+ User: ${opts.user}
115
+
116
+ Restart your AI tool to use ppdocs knowledge graph.
117
+ `);
118
+ }
119
+ /** 检测命令是否存在 */
120
+ function commandExists(cmd) {
121
+ try {
122
+ const checkCmd = process.platform === 'win32' ? `where ${cmd}` : `which ${cmd}`;
123
+ execSync(checkCmd, { stdio: 'ignore' });
124
+ return true;
125
+ }
126
+ catch {
127
+ return false;
128
+ }
129
+ }
130
+ /** 自动检测 AI CLI 并注册 MCP */
131
+ function autoRegisterMcp(apiUrl, user) {
132
+ const detected = [];
133
+ // 检测 Claude CLI
134
+ if (commandExists('claude')) {
135
+ detected.push('Claude');
136
+ try {
137
+ const cmd = `claude mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
138
+ console.log(`✅ Detected Claude CLI, registering MCP...`);
139
+ execSync(cmd, { stdio: 'inherit' });
140
+ }
141
+ catch (e) {
142
+ console.log(`⚠️ Claude MCP registration failed: ${e}`);
143
+ }
144
+ }
145
+ // 检测 Codex CLI (OpenAI)
146
+ if (commandExists('codex')) {
147
+ detected.push('Codex');
148
+ try {
149
+ const cmd = `codex mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
150
+ console.log(`✅ Detected Codex CLI, registering MCP...`);
151
+ execSync(cmd, { stdio: 'inherit' });
152
+ }
153
+ catch (e) {
154
+ console.log(`⚠️ Codex MCP registration failed: ${e}`);
155
+ }
156
+ }
157
+ // 检测 Gemini CLI
158
+ if (commandExists('gemini')) {
159
+ detected.push('Gemini');
160
+ try {
161
+ const cmd = `gemini mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
162
+ console.log(`✅ Detected Gemini CLI, registering MCP...`);
163
+ execSync(cmd, { stdio: 'inherit' });
164
+ }
165
+ catch (e) {
166
+ console.log(`⚠️ Gemini MCP registration failed: ${e}`);
167
+ }
168
+ }
169
+ if (detected.length === 0) {
170
+ console.log(`ℹ️ No AI CLI detected (claude/codex/gemini), creating .mcp.json for manual config`);
171
+ return false;
172
+ }
173
+ console.log(`✅ Registered MCP for: ${detected.join(', ')}`);
174
+ return true;
175
+ }
176
+ /** 创建 .mcp.json (手动配置备用) */
177
+ function createMcpJson(cwd) {
98
178
  const mcpPath = path.join(cwd, '.mcp.json');
99
179
  let mcpConfig = {};
100
180
  if (fs.existsSync(mcpPath)) {
@@ -116,19 +196,6 @@ function initProject(opts) {
116
196
  };
117
197
  fs.writeFileSync(mcpPath, JSON.stringify(mcpConfig, null, 2));
118
198
  console.log(`✅ Created ${mcpPath}`);
119
- // Install workflow templates
120
- if (opts.codex) {
121
- installCodexTemplates(cwd);
122
- }
123
- else {
124
- installClaudeTemplates(cwd);
125
- }
126
- console.log(`
127
- 🎉 Done! ppdocs MCP configured for project: ${opts.project}
128
- User: ${opts.user}
129
-
130
- Restart Claude Code to use ppdocs knowledge graph.
131
- `);
132
199
  }
133
200
  /** 递归复制目录 */
134
201
  function copyDirRecursive(src, dest) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ppdocs/mcp",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "description": "ppdocs MCP Server - Knowledge Graph for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",