list-function-versions
Retrieve a list of function versions in Alibaba Cloud Function Compute, specifying region, sorting direction, and pagination for efficient version management and deployment tracking.
Instructions
获取函数计算的函数版本列表
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | No | 函数版本列表的排序方向,BACKWARD表示按版本号降序,FORWARD表示按版本号升序 | BACKWARD |
| functionName | Yes | 函数名称,函数名称在每个region必须是唯一的。 | |
| limit | No | 函数版本列表的返回数量上限,默认50,最大100 | |
| nextToken | No | 函数版本列表的下一页token,用于分页查询函数版本列表。第一页不需要提供 | |
| 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"direction": {
"default": "BACKWARD",
"description": "函数版本列表的排序方向,BACKWARD表示按版本号降序,FORWARD表示按版本号升序",
"enum": [
"BACKWARD",
"FORWARD"
],
"type": "string"
},
"functionName": {
"description": "函数名称,函数名称在每个region必须是唯一的。",
"pattern": "^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,63}$",
"type": "string"
},
"limit": {
"default": 50,
"description": "函数版本列表的返回数量上限,默认50,最大100",
"maximum": 100,
"minimum": 1,
"type": "number"
},
"nextToken": {
"description": "函数版本列表的下一页token,用于分页查询函数版本列表。第一页不需要提供",
"type": "string"
},
"region": {
"default": "cn-hangzhou",
"description": "部署的区域,当前可选的区域是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",
"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"
],
"type": "string"
}
},
"required": [
"functionName"
],
"type": "object"
}
Implementation Reference
- src/index.ts:827-856 (handler)The handler function for the 'list-function-versions' tool. It validates credentials, retrieves account ID, creates an FC client, builds the ListFunctionVersionsRequest with provided parameters, calls the Alibaba Cloud FC SDK to list versions, and returns the result or error message.async (args) => { const { functionName, region, nextToken, direction, limit } = 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); const listFunctionVersionsRequest = new ListFunctionVersionsRequest({ functionName, direction, }) if (nextToken) { listFunctionVersionsRequest.nextToken = nextToken; } if (limit) { listFunctionVersionsRequest.limit = limit; } try { const listFunctionVersionsResult = await fcClient.listFunctionVersions(functionName, listFunctionVersionsRequest); return { content: [{ type: "text", text: `获取函数版本列表成功。result: ${JSON.stringify(listFunctionVersionsResult)}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `获取函数版本列表失败:${JSON.stringify(error as any)}` }] }; } }
- src/schema.ts:172-182 (schema)Zod schema definitions for parameters used in the 'list-function-versions' tool, including nextToken, limit, direction, and related pagination schemas.export const listFunctionsPrefixSchema = z.string().describe("函数名称前缀,用于过滤函数列表"); export const listFunctionsNextTokenSchema = z.string().describe("函数列表的下一页token,用于分页查询函数列表。第一页不需要提供"); export const listFunctionVersionsNextTokenSchema = z.string().describe("函数版本列表的下一页token,用于分页查询函数版本列表。第一页不需要提供"); export const listFunctionVersionsLimitSchema = z.number().describe("函数版本列表的返回数量上限,默认50,最大100").min(1).max(100).default(50); export const listFunctionVersionsDirectionSchema = z.enum(["BACKWARD", "FORWARD"]).describe("函数版本列表的排序方向,BACKWARD表示按版本号降序,FORWARD表示按版本号升序").default("BACKWARD"); export const versionIdSchema = z.string().describe("函数版本ID");
- src/index.ts:817-857 (registration)Registration of the 'list-function-versions' tool with the MCP server, including name, description, input schema references, and inline handler function.server.tool( "list-function-versions", "获取函数计算的函数版本列表", { functionName: functionNameSchema, region: regionSchema, nextToken: listFunctionVersionsNextTokenSchema.optional(), direction: listFunctionVersionsDirectionSchema, limit: listFunctionVersionsLimitSchema.optional(), }, async (args) => { const { functionName, region, nextToken, direction, limit } = 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); const listFunctionVersionsRequest = new ListFunctionVersionsRequest({ functionName, direction, }) if (nextToken) { listFunctionVersionsRequest.nextToken = nextToken; } if (limit) { listFunctionVersionsRequest.limit = limit; } try { const listFunctionVersionsResult = await fcClient.listFunctionVersions(functionName, listFunctionVersionsRequest); return { content: [{ type: "text", text: `获取函数版本列表成功。result: ${JSON.stringify(listFunctionVersionsResult)}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `获取函数版本列表失败:${JSON.stringify(error as any)}` }] }; } } )
- src/utils/alibaba_cloud_sdk.ts:11-17 (helper)Helper function to create an Alibaba Cloud FC client instance used in the handler.export function createFcClient(regionId: string) { const config = new $OpenApi.Config({ credential: getCredentialClient(), endpoint: `fcv3.${regionId}.aliyuncs.com`, }); return new FCClient(config); }
- src/utils/alibaba_cloud_sdk.ts:28-37 (helper)Helper function to retrieve the Alibaba Cloud account ID, used for validation in the handler.export async function getAccountId(): Promise<string> { try { const client = createStsClient('cn-hangzhou'); const result = await client.getCallerIdentity(); const accountId = result.body?.accountId || ''; return accountId; } catch (ex: any) { console.error('getAccountId异常:', JSON.stringify(ex)) return ''; }