@@ -2,6 +2,17 @@ import { z } from "zod";
22import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
33import { getCloudBaseManager } from '../cloudbase-manager.js'
44
5+ // 支持的 Node.js 运行时列表
6+ export const SUPPORTED_NODEJS_RUNTIMES = [
7+ 'Nodejs 18.15' ,
8+ 'Nodejs 16.13' ,
9+ 'Nodejs 14.18' ,
10+ 'Nodejs 12.16' ,
11+ 'Nodejs 10.15' ,
12+ 'Nodejs 8.9(即将下线)' ,
13+ ] ;
14+ export const DEFAULT_NODEJS_RUNTIME = 'Nodejs 18.15' ;
15+
516export function registerFunctionTools ( server : McpServer ) {
617 // getFunctionList - 获取云函数列表(推荐)
718 server . tool (
@@ -38,7 +49,7 @@ export function registerFunctionTools(server: McpServer) {
3849 vpcId : z . string ( ) ,
3950 subnetId : z . string ( )
4051 } ) . optional ( ) . describe ( "私有网络配置" ) ,
41- runtime : z . string ( ) . optional ( ) . describe ( "运行时环境" ) ,
52+ runtime : z . string ( ) . optional ( ) . describe ( "运行时环境,可选值:" + SUPPORTED_NODEJS_RUNTIMES . join ( ',' ) + ",默认 Nodejs 18.15 ") ,
4253 installDependency : z . boolean ( ) . optional ( ) . describe ( "是否安装依赖,建议传 true" ) ,
4354 triggers : z . array ( z . object ( {
4455 name : z . string ( ) ,
@@ -57,6 +68,10 @@ export function registerFunctionTools(server: McpServer) {
5768 force : z . boolean ( ) . describe ( "是否覆盖" )
5869 } ,
5970 async ( { func, functionRootPath, force } ) => {
71+ // 自动填充默认 runtime
72+ if ( ! func . runtime ) {
73+ func . runtime = DEFAULT_NODEJS_RUNTIME ;
74+ }
6075 const cloudbase = await getCloudBaseManager ( )
6176 const result = await cloudbase . functions . createFunction ( {
6277 func,
@@ -117,10 +132,14 @@ export function registerFunctionTools(server: McpServer) {
117132 vpcId : z . string ( ) ,
118133 subnetId : z . string ( )
119134 } ) . optional ( ) . describe ( "VPC配置" ) ,
120- runtime : z . string ( ) . optional ( ) . describe ( "运行时" )
135+ runtime : z . string ( ) . optional ( ) . describe ( "运行时(可选值:" + SUPPORTED_NODEJS_RUNTIMES . join ( ',' ) + ",默认 Nodejs 18.15) ")
121136 } ) . describe ( "函数配置" )
122137 } ,
123138 async ( { funcParam } ) => {
139+ // 自动填充默认 runtime
140+ if ( ! funcParam . runtime ) {
141+ funcParam . runtime = DEFAULT_NODEJS_RUNTIME ;
142+ }
124143 const cloudbase = await getCloudBaseManager ( )
125144 const result = await cloudbase . functions . updateFunctionConfig ( funcParam ) ;
126145 return {
0 commit comments