@bangdao-ai/zentao-mcp 1.1.4 → 1.1.6
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/src/mcp_server.py +3 -3
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 通信,不会输出到控制台
|
package/package.json
CHANGED
package/src/mcp_server.py
CHANGED
|
@@ -9,7 +9,7 @@ import asyncio
|
|
|
9
9
|
import json
|
|
10
10
|
import os
|
|
11
11
|
import sys
|
|
12
|
-
from typing import Any, Dict, Optional
|
|
12
|
+
from typing import Any, Dict, Optional, List
|
|
13
13
|
|
|
14
14
|
from dotenv import load_dotenv
|
|
15
15
|
from mcp.server import Server
|
|
@@ -34,7 +34,7 @@ class ZenTaoMCPServer:
|
|
|
34
34
|
"""设置请求处理器"""
|
|
35
35
|
|
|
36
36
|
@self.server.list_tools()
|
|
37
|
-
async def list_tools() ->
|
|
37
|
+
async def list_tools() -> List[Tool]:
|
|
38
38
|
"""列出可用工具"""
|
|
39
39
|
return [
|
|
40
40
|
Tool(
|
|
@@ -211,7 +211,7 @@ class ZenTaoMCPServer:
|
|
|
211
211
|
]
|
|
212
212
|
|
|
213
213
|
@self.server.call_tool()
|
|
214
|
-
async def call_tool(name: str, arguments: Dict[str, Any]) ->
|
|
214
|
+
async def call_tool(name: str, arguments: Dict[str, Any]) -> List[TextContent]:
|
|
215
215
|
"""处理工具调用"""
|
|
216
216
|
try:
|
|
217
217
|
# 延迟初始化 nexus(只在第一次使用时初始化)
|