@ppdocs/mcp 2.5.2 → 2.6.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.d.ts +1 -1
- package/dist/cli.js +90 -15
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
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}`,
|
|
@@ -92,9 +94,95 @@ function initProject(opts) {
|
|
|
92
94
|
user: opts.user,
|
|
93
95
|
};
|
|
94
96
|
const ppdocsPath = path.join(cwd, '.ppdocs');
|
|
97
|
+
// 检查是否存在同名目录,如果是则删除
|
|
98
|
+
if (fs.existsSync(ppdocsPath)) {
|
|
99
|
+
const stat = fs.statSync(ppdocsPath);
|
|
100
|
+
if (stat.isDirectory()) {
|
|
101
|
+
fs.rmSync(ppdocsPath, { recursive: true });
|
|
102
|
+
console.log(`⚠️ Removed existing .ppdocs directory`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
95
105
|
fs.writeFileSync(ppdocsPath, JSON.stringify(ppdocsConfig, null, 2));
|
|
96
106
|
console.log(`✅ Created ${ppdocsPath}`);
|
|
97
|
-
//
|
|
107
|
+
// Install workflow templates
|
|
108
|
+
if (opts.codex) {
|
|
109
|
+
installCodexTemplates(cwd);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
installClaudeTemplates(cwd);
|
|
113
|
+
}
|
|
114
|
+
// 自动检测并注册 MCP
|
|
115
|
+
const registered = autoRegisterMcp(apiUrl, opts.user);
|
|
116
|
+
// 如果没有检测到任何 AI CLI,创建 .mcp.json 作为备用
|
|
117
|
+
if (!registered) {
|
|
118
|
+
createMcpJson(cwd);
|
|
119
|
+
}
|
|
120
|
+
console.log(`
|
|
121
|
+
🎉 Done! ppdocs MCP configured for project: ${opts.project}
|
|
122
|
+
User: ${opts.user}
|
|
123
|
+
|
|
124
|
+
Restart your AI tool to use ppdocs knowledge graph.
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
/** 检测命令是否存在 */
|
|
128
|
+
function commandExists(cmd) {
|
|
129
|
+
try {
|
|
130
|
+
const checkCmd = process.platform === 'win32' ? `where ${cmd}` : `which ${cmd}`;
|
|
131
|
+
execSync(checkCmd, { stdio: 'ignore' });
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** 自动检测 AI CLI 并注册 MCP */
|
|
139
|
+
function autoRegisterMcp(apiUrl, user) {
|
|
140
|
+
const detected = [];
|
|
141
|
+
// 检测 Claude CLI
|
|
142
|
+
if (commandExists('claude')) {
|
|
143
|
+
detected.push('Claude');
|
|
144
|
+
try {
|
|
145
|
+
const cmd = `claude mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
|
|
146
|
+
console.log(`✅ Detected Claude CLI, registering MCP...`);
|
|
147
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.log(`⚠️ Claude MCP registration failed: ${e}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// 检测 Codex CLI (OpenAI)
|
|
154
|
+
if (commandExists('codex')) {
|
|
155
|
+
detected.push('Codex');
|
|
156
|
+
try {
|
|
157
|
+
const cmd = `codex mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
|
|
158
|
+
console.log(`✅ Detected Codex CLI, registering MCP...`);
|
|
159
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.log(`⚠️ Codex MCP registration failed: ${e}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// 检测 Gemini CLI
|
|
166
|
+
if (commandExists('gemini')) {
|
|
167
|
+
detected.push('Gemini');
|
|
168
|
+
try {
|
|
169
|
+
const cmd = `gemini mcp add ppdocs-kg -e PPDOCS_API_URL=${apiUrl} -e PPDOCS_USER=${user} -- npx -y @ppdocs/mcp`;
|
|
170
|
+
console.log(`✅ Detected Gemini CLI, registering MCP...`);
|
|
171
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
console.log(`⚠️ Gemini MCP registration failed: ${e}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (detected.length === 0) {
|
|
178
|
+
console.log(`ℹ️ No AI CLI detected (claude/codex/gemini), creating .mcp.json for manual config`);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
console.log(`✅ Registered MCP for: ${detected.join(', ')}`);
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
/** 创建 .mcp.json (手动配置备用) */
|
|
185
|
+
function createMcpJson(cwd) {
|
|
98
186
|
const mcpPath = path.join(cwd, '.mcp.json');
|
|
99
187
|
let mcpConfig = {};
|
|
100
188
|
if (fs.existsSync(mcpPath)) {
|
|
@@ -116,19 +204,6 @@ function initProject(opts) {
|
|
|
116
204
|
};
|
|
117
205
|
fs.writeFileSync(mcpPath, JSON.stringify(mcpConfig, null, 2));
|
|
118
206
|
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
207
|
}
|
|
133
208
|
/** 递归复制目录 */
|
|
134
209
|
function copyDirRecursive(src, dest) {
|