@bangdao-ai/zentao-mcp 1.1.4 → 1.1.5
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/index.js +44 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -92,13 +92,46 @@ function getScriptPath() {
|
|
|
92
92
|
return scriptPath;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
//
|
|
96
|
-
function checkPythonDependencies() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
// 检查并安装 Python 依赖
|
|
96
|
+
function checkPythonDependencies(python) {
|
|
97
|
+
try {
|
|
98
|
+
// 检查 mcp 模块是否已安装
|
|
99
|
+
execSync(`${python} -c "import mcp"`, {
|
|
100
|
+
encoding: 'utf-8',
|
|
101
|
+
stdio: ['ignore', 'ignore', 'ignore']
|
|
102
|
+
});
|
|
103
|
+
// 如果导入成功,说明已安装
|
|
104
|
+
return true;
|
|
105
|
+
} catch (e) {
|
|
106
|
+
// 模块未安装,尝试自动安装
|
|
107
|
+
try {
|
|
108
|
+
console.error('检测到 mcp 模块未安装,正在自动安装...');
|
|
109
|
+
const requirementsPath = path.join(__dirname, 'requirements.txt');
|
|
110
|
+
|
|
111
|
+
if (fs.existsSync(requirementsPath)) {
|
|
112
|
+
// 使用 --user 标志安装,避免权限问题
|
|
113
|
+
execSync(`${python} -m pip install --user -r "${requirementsPath}"`, {
|
|
114
|
+
encoding: 'utf-8',
|
|
115
|
+
stdio: 'inherit'
|
|
116
|
+
});
|
|
117
|
+
console.error('依赖安装完成!');
|
|
118
|
+
return true;
|
|
119
|
+
} else {
|
|
120
|
+
// 如果找不到 requirements.txt,尝试直接安装 mcp
|
|
121
|
+
execSync(`${python} -m pip install --user mcp`, {
|
|
122
|
+
encoding: 'utf-8',
|
|
123
|
+
stdio: 'inherit'
|
|
124
|
+
});
|
|
125
|
+
console.error('mcp 模块安装完成!');
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
} catch (installError) {
|
|
129
|
+
console.error('自动安装失败,请手动安装依赖:');
|
|
130
|
+
console.error(` ${python} -m pip install --user -r "${path.join(__dirname, 'requirements.txt')}"`);
|
|
131
|
+
console.error('或者:');
|
|
132
|
+
console.error(` ${python} -m pip install --user mcp`);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
137
|
|
|
@@ -108,8 +141,10 @@ function main() {
|
|
|
108
141
|
const python = findPython();
|
|
109
142
|
const scriptPath = getScriptPath();
|
|
110
143
|
|
|
111
|
-
//
|
|
112
|
-
checkPythonDependencies()
|
|
144
|
+
// 检查并自动安装 Python 依赖
|
|
145
|
+
if (!checkPythonDependencies(python)) {
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
113
148
|
|
|
114
149
|
// 启动 Python MCP 服务器
|
|
115
150
|
// 注意:MCP 服务器通过 stdio 通信,不会输出到控制台
|