Skip to content

Commit 8229de0

Browse files
authored
Merge pull request #83 from TencentCloudBase/claude/issue-81-20250714_145705
fix: resolve runtime parameter format issue in createFunction tool
2 parents fa6b09e + eb8ef31 commit 8229de0

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

mcp/src/tools/functions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
8989
vpcId: z.string(),
9090
subnetId: z.string()
9191
}).optional().describe("私有网络配置"),
92-
runtime: z.string().optional().describe("运行时环境,建议指定为 'Nodejs 18.15',其他可选值:" + SUPPORTED_NODEJS_RUNTIMES.join(',')),
92+
runtime: z.string().optional().describe("运行时环境,建议指定为 'Nodejs18.15',其他可选值:" + SUPPORTED_NODEJS_RUNTIMES.join(',')),
9393
triggers: z.array(z.object({
9494
name: z.string(),
9595
type: z.string(),
@@ -122,6 +122,20 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
122122
// 自动填充默认 runtime
123123
if (!func.runtime) {
124124
func.runtime = DEFAULT_NODEJS_RUNTIME;
125+
} else {
126+
// 验证 runtime 格式,防止常见的空格问题
127+
const normalizedRuntime = func.runtime.replace(/\s+/g, '');
128+
if (SUPPORTED_NODEJS_RUNTIMES.includes(normalizedRuntime)) {
129+
func.runtime = normalizedRuntime;
130+
} else if (func.runtime.includes(' ')) {
131+
console.warn(`检测到 runtime 参数包含空格: "${func.runtime}",已自动移除空格`);
132+
func.runtime = normalizedRuntime;
133+
}
134+
}
135+
136+
// 验证 runtime 是否有效
137+
if (!SUPPORTED_NODEJS_RUNTIMES.includes(func.runtime)) {
138+
throw new Error(`不支持的运行时环境: "${func.runtime}"。支持的值:${SUPPORTED_NODEJS_RUNTIMES.join(', ')}`);
125139
}
126140

127141
// 强制设置 installDependency 为 true(不暴露给AI)

scripts/tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@
506506
},
507507
"runtime": {
508508
"type": "string",
509-
"description": "运行时环境,建议指定为 'Nodejs 18.15',其他可选值:Nodejs18.15,Nodejs16.13,Nodejs14.18,Nodejs12.16,Nodejs10.15,Nodejs8.9"
509+
"description": "运行时环境,建议指定为 'Nodejs18.15',其他可选值:Nodejs16.13,Nodejs14.18,Nodejs12.16,Nodejs10.15,Nodejs8.9"
510510
},
511511
"triggers": {
512512
"type": "array",

0 commit comments

Comments
 (0)