@cloudbase/cloudbase-mcp 1.7.1 → 1.7.2
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/tools/functions.js +28 -4
- package/package.json +1 -1
package/dist/tools/functions.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { getCloudBaseManager } from '../cloudbase-manager.js';
|
|
3
|
+
import path from 'path';
|
|
3
4
|
// 支持的 Node.js 运行时列表
|
|
4
5
|
export const SUPPORTED_NODEJS_RUNTIMES = [
|
|
5
6
|
'Nodejs 18.15',
|
|
@@ -10,6 +11,25 @@ export const SUPPORTED_NODEJS_RUNTIMES = [
|
|
|
10
11
|
'Nodejs 8.9(即将下线)',
|
|
11
12
|
];
|
|
12
13
|
export const DEFAULT_NODEJS_RUNTIME = 'Nodejs 18.15';
|
|
14
|
+
/**
|
|
15
|
+
* 处理函数根目录路径,确保不包含函数名
|
|
16
|
+
* @param functionRootPath 用户输入的路径
|
|
17
|
+
* @param functionName 函数名称
|
|
18
|
+
* @returns 处理后的根目录路径
|
|
19
|
+
*/
|
|
20
|
+
function processFunctionRootPath(functionRootPath, functionName) {
|
|
21
|
+
if (!functionRootPath)
|
|
22
|
+
return functionRootPath;
|
|
23
|
+
const normalizedPath = path.normalize(functionRootPath);
|
|
24
|
+
const lastDir = path.basename(normalizedPath);
|
|
25
|
+
// 如果路径的最后一级目录名与函数名相同,说明用户可能传入了包含函数名的路径
|
|
26
|
+
if (lastDir === functionName) {
|
|
27
|
+
const parentPath = path.dirname(normalizedPath);
|
|
28
|
+
console.warn(`检测到 functionRootPath 包含函数名 "${functionName}",已自动调整为父目录: ${parentPath}`);
|
|
29
|
+
return parentPath;
|
|
30
|
+
}
|
|
31
|
+
return functionRootPath;
|
|
32
|
+
}
|
|
13
33
|
export function registerFunctionTools(server) {
|
|
14
34
|
// getFunctionList - 获取云函数列表(推荐)
|
|
15
35
|
server.tool("getFunctionList", "获取云函数列表", {
|
|
@@ -52,17 +72,19 @@ export function registerFunctionTools(server) {
|
|
|
52
72
|
version: z.number()
|
|
53
73
|
})).optional().describe("Layer配置")
|
|
54
74
|
}).describe("函数配置"),
|
|
55
|
-
functionRootPath: z.string().optional().describe("
|
|
75
|
+
functionRootPath: z.string().optional().describe("函数根目录(云函数目录的父目录),这里需要传操作系统上文件的绝对路径,注意:不要包含函数名本身,例如函数名为 'hello',应传入 '/path/to/cloudfunctions',而不是 '/path/to/cloudfunctions/hello'"),
|
|
56
76
|
force: z.boolean().describe("是否覆盖")
|
|
57
77
|
}, async ({ func, functionRootPath, force }) => {
|
|
58
78
|
// 自动填充默认 runtime
|
|
59
79
|
if (!func.runtime) {
|
|
60
80
|
func.runtime = DEFAULT_NODEJS_RUNTIME;
|
|
61
81
|
}
|
|
82
|
+
// 处理函数根目录路径,确保不包含函数名
|
|
83
|
+
const processedRootPath = processFunctionRootPath(functionRootPath, func.name);
|
|
62
84
|
const cloudbase = await getCloudBaseManager();
|
|
63
85
|
const result = await cloudbase.functions.createFunction({
|
|
64
86
|
func,
|
|
65
|
-
functionRootPath,
|
|
87
|
+
functionRootPath: processedRootPath,
|
|
66
88
|
force
|
|
67
89
|
});
|
|
68
90
|
return {
|
|
@@ -79,15 +101,17 @@ export function registerFunctionTools(server) {
|
|
|
79
101
|
func: z.object({
|
|
80
102
|
name: z.string().describe("函数名称")
|
|
81
103
|
}).describe("函数配置"),
|
|
82
|
-
functionRootPath: z.string().optional().describe("
|
|
104
|
+
functionRootPath: z.string().optional().describe("函数根目录(云函数目录的父目录),这里需要传操作系统上文件的绝对路径,注意:不要包含函数名本身,例如函数名为 'hello',应传入 '/path/to/cloudfunctions',而不是 '/path/to/cloudfunctions/hello'")
|
|
83
105
|
}, async ({ func, functionRootPath }) => {
|
|
106
|
+
// 处理函数根目录路径,确保不包含函数名
|
|
107
|
+
const processedRootPath = processFunctionRootPath(functionRootPath, func.name);
|
|
84
108
|
const cloudbase = await getCloudBaseManager();
|
|
85
109
|
const result = await cloudbase.functions.updateFunctionCode({
|
|
86
110
|
func: {
|
|
87
111
|
...func,
|
|
88
112
|
installDependency: true // 默认安装依赖
|
|
89
113
|
},
|
|
90
|
-
functionRootPath,
|
|
114
|
+
functionRootPath: processedRootPath,
|
|
91
115
|
});
|
|
92
116
|
return {
|
|
93
117
|
content: [
|