@zzp123/mcp-zentao 1.18.11 → 1.18.12

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/index-pm.js CHANGED
@@ -283,6 +283,73 @@ server.tool("getUsers", {
283
283
  throw new Error("Please initialize Zentao API first");
284
284
  return { content: [{ type: "text", text: JSON.stringify(await zentaoApi.getUsers(params), null, 2) }] };
285
285
  });
286
+ server.tool("uploadFile", {
287
+ filePath: z.string().optional(),
288
+ base64Data: z.string().optional(),
289
+ filename: z.string().optional(),
290
+ uid: z.string().optional()
291
+ }, async ({ filePath, base64Data, filename, uid }) => {
292
+ if (!zentaoApi)
293
+ throw new Error("Please initialize Zentao API first");
294
+ const fs = await import('fs');
295
+ const path = await import('path');
296
+ let fileBuffer;
297
+ let finalFilename;
298
+ let savedPath;
299
+ // 如果提供了 base64 数据(复制的图片)
300
+ if (base64Data) {
301
+ // 创建 img 文件夹(如果不存在)
302
+ const imgDir = path.join(process.cwd(), 'img');
303
+ if (!fs.existsSync(imgDir)) {
304
+ fs.mkdirSync(imgDir, { recursive: true });
305
+ }
306
+ // 处理 base64 数据
307
+ const matches = base64Data.match(/^data:image\/(\w+);base64,(.+)$/);
308
+ if (matches) {
309
+ const ext = matches[1];
310
+ const data = matches[2];
311
+ fileBuffer = Buffer.from(data, 'base64');
312
+ finalFilename = filename || `image_${Date.now()}.${ext}`;
313
+ }
314
+ else {
315
+ // 直接的 base64 数据,没有 data URL 前缀
316
+ fileBuffer = Buffer.from(base64Data, 'base64');
317
+ finalFilename = filename || `image_${Date.now()}.png`;
318
+ }
319
+ // 保存到 img 文件夹
320
+ savedPath = path.join(imgDir, finalFilename);
321
+ fs.writeFileSync(savedPath, fileBuffer);
322
+ }
323
+ // 如果提供了文件路径
324
+ else if (filePath) {
325
+ fileBuffer = fs.readFileSync(filePath);
326
+ finalFilename = path.basename(filePath);
327
+ }
328
+ else {
329
+ throw new Error("必须提供 filePath 或 base64Data 参数");
330
+ }
331
+ const result = await zentaoApi.uploadFile({
332
+ file: fileBuffer,
333
+ filename: finalFilename,
334
+ uid
335
+ });
336
+ // 生成禅道需要的 HTML 格式
337
+ const fileId = result.id;
338
+ const baseUrl = zentaoApi.getConfig().url;
339
+ const imageUrl = `${baseUrl}/zentao/entao/api.php?m=file&f=read&t=png&fileID=${fileId}`;
340
+ const imageHtml = `<p><img onload="setImageSize(this,0)" src="${imageUrl}" alt="${finalFilename}" /></p>`;
341
+ const response = {
342
+ upload: result,
343
+ fileId: fileId,
344
+ imageUrl: imageUrl,
345
+ imageHtml: imageHtml,
346
+ tip: `更新 Bug 描述时,请使用 imageHtml 字段中的 HTML 代码。图片会被包裹在 <p> 标签中以确保正确显示。`
347
+ };
348
+ if (savedPath) {
349
+ response.savedPath = savedPath;
350
+ }
351
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
352
+ });
286
353
  server.tool("getComments", "获取评论列表 - 获取指定对象的所有评论", {
287
354
  objectType: z.enum([
288
355
  'story', // 软件需求
@@ -82,7 +82,7 @@ export const TOOL_CATEGORIES = {
82
82
  };
83
83
  // 角色权限配置
84
84
  export const ROLE_PERMISSIONS = {
85
- // 产品经理:初始化+项目+需求+执行+计划+评论+用户
85
+ // 产品经理:初始化+项目+需求+执行+计划+评论+用户+文件
86
86
  pm: [
87
87
  'initZentao',
88
88
  'getProjects',
@@ -99,14 +99,22 @@ export const ROLE_PERMISSIONS = {
99
99
  'getComments',
100
100
  'addComment',
101
101
  'getUsers',
102
- 'getMyProfile'
102
+ 'getMyProfile',
103
+ 'uploadFile'
103
104
  ],
104
- // 测试工程师:初始化+缺陷与用例
105
+ // 测试工程师:初始化+任务查看+缺陷查看+测试用例完整管理+用户信息+文件
105
106
  qa: [
106
107
  'initZentao',
107
- 'createBug',
108
+ 'getTaskDetail',
109
+ 'getBugDetail',
110
+ 'getProductTestCases',
111
+ 'getTestCaseDetail',
108
112
  'createTestCase',
109
- 'getMyBugs'
113
+ 'updateTestCase',
114
+ 'deleteTestCase',
115
+ 'getUsers',
116
+ 'getMyProfile',
117
+ 'uploadFile'
110
118
  ],
111
119
  // 开发工程师:初始化+缺陷处理
112
120
  dev: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzp123/mcp-zentao",
3
- "version": "1.18.11",
3
+ "version": "1.18.12",
4
4
  "description": "禅道项目管理系统的高级API集成包 - 完整版,包含所有94个工具。另有产品经理、测试工程师、开发工程师专用精简版本可选",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -42,7 +42,8 @@ const ROLE_PERMISSIONS = {
42
42
  'getComments', // 查看评论
43
43
  'addComment', // 添加评论
44
44
  'getUsers', // 获取用户列表
45
- 'getMyProfile' // 获取我的个人信息
45
+ 'getMyProfile', // 获取我的个人信息
46
+ 'uploadFile' // 上传文件
46
47
  ],
47
48
  qa: [
48
49
  ...TOOL_CATEGORIES.init,