delete-function
Remove serverless functions from Alibaba Cloud Function Compute to manage resources and maintain clean deployments.
Instructions
删除函数计算的函数
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionName | Yes | 函数名称,函数名称在每个region必须是唯一的。 | |
| region | No | 部署的区域,当前可选的区域是cn-hangzhou, cn-shanghai, cn-beijing, cn-shenzhen, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1, me-east-1, cn-chengdu, cn-wulanchabu, cn-guangzhou,默认是cn-hangzhou | cn-hangzhou |
Implementation Reference
- src/index.ts:617-641 (handler)The handler function that implements the logic to delete the specified Alibaba Cloud Function Compute function and its associated custom domain configuration.async (args) => { const { functionName, region } = args; const accessKeyId = process.env.ALIBABA_CLOUD_ACCESS_KEY_ID; const accessKeySecret = process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET; if (!accessKeyId || !accessKeySecret) { return { isError: true, content: [{ type: "text", text: `执行失败,请设置ALIBABA_CLOUD_ACCESS_KEY_ID, ALIBABA_CLOUD_ACCESS_KEY_SECRET, ALIBABA_CLOUD_SECURITY_TOKEN环境变量` }] }; } const accountId = await getAccountId(); if (!accountId) { return { isError: true, content: [{ type: "text", text: `执行失败,获取accountId异常` }] }; } const fcClient = createFcClient(region); try { await fcClient.deleteFunction(functionName); } catch (error) { return { isError: true, content: [{ type: "text", text: `删除函数失败:${JSON.stringify(error as any)}` }] }; } const autoCustomDomainName = getAutoCustomDomainName(accountId, functionName, region); try { await fcClient.deleteCustomDomain(autoCustomDomainName); } catch (error) { return { isError: true, content: [{ type: "text", text: `删除函数域名路由配置失败:${JSON.stringify(error as any)}` }] }; } return { content: [{ type: "text", text: `删除函数成功` }] }; }
- src/index.ts:610-642 (registration)The server.tool registration for the 'delete-function' MCP tool, including name, description, input schema, and handler.server.tool( "delete-function", "删除函数计算的函数", { functionName: functionNameSchema, region: regionSchema, }, async (args) => { const { functionName, region } = args; const accessKeyId = process.env.ALIBABA_CLOUD_ACCESS_KEY_ID; const accessKeySecret = process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET; if (!accessKeyId || !accessKeySecret) { return { isError: true, content: [{ type: "text", text: `执行失败,请设置ALIBABA_CLOUD_ACCESS_KEY_ID, ALIBABA_CLOUD_ACCESS_KEY_SECRET, ALIBABA_CLOUD_SECURITY_TOKEN环境变量` }] }; } const accountId = await getAccountId(); if (!accountId) { return { isError: true, content: [{ type: "text", text: `执行失败,获取accountId异常` }] }; } const fcClient = createFcClient(region); try { await fcClient.deleteFunction(functionName); } catch (error) { return { isError: true, content: [{ type: "text", text: `删除函数失败:${JSON.stringify(error as any)}` }] }; } const autoCustomDomainName = getAutoCustomDomainName(accountId, functionName, region); try { await fcClient.deleteCustomDomain(autoCustomDomainName); } catch (error) { return { isError: true, content: [{ type: "text", text: `删除函数域名路由配置失败:${JSON.stringify(error as any)}` }] }; } return { content: [{ type: "text", text: `删除函数成功` }] }; } )
- src/schema.ts:118-120 (schema)Zod schema validation for the 'functionName' input parameter used in delete-function.// function name schema export const functionNameSchema = z.string().describe("函数名称,函数名称在每个region必须是唯一的。") .regex(/^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,63}$/);
- src/schema.ts:4-6 (schema)Zod schema validation for the 'region' input parameter used in delete-function.export const regionSchema = z.enum(['cn-hangzhou', 'cn-shanghai', 'cn-beijing', 'cn-shenzhen', 'cn-hongkong', 'ap-southeast-1', 'ap-southeast-2', 'ap-southeast-3', 'ap-southeast-5', 'ap-northeast-1', 'eu-central-1', 'eu-west-1', 'us-west-1', 'us-east-1', 'ap-south-1', 'me-east-1', 'cn-chengdu', 'cn-wulanchabu', 'cn-guangzhou']) .default('cn-hangzhou') .describe("部署的区域,当前可选的区域是cn-hangzhou, cn-shanghai, cn-beijing, cn-shenzhen, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1, me-east-1, cn-chengdu, cn-wulanchabu, cn-guangzhou,默认是cn-hangzhou");
- src/index.ts:275-278 (helper)Helper function to generate the auto-generated custom domain name for deletion.function getAutoCustomDomainName(uid: string, functionName: string, regionID: string) { const normalizedFunctionName = functionName.replace(/_/g, '-').toLowerCase(); return `${normalizedFunctionName}.fcv3.${uid}.${regionID}.fc.devsapp.net`; }