Skip to main content
Glama

Alibaba Cloud FC MCP Server

Official
by aliyun

get-function

Retrieve detailed information about a specific function in Alibaba Cloud Function Compute by specifying its name and region for streamlined serverless function management.

Instructions

获取创建的函数计算的函数信息

Input Schema

NameRequiredDescriptionDefault
functionNameYes函数名称,函数名称在每个region必须是唯一的。
regionNo部署的区域,当前可选的区域是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-hangzhoucn-hangzhou

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "functionName": { "description": "函数名称,函数名称在每个region必须是唯一的。", "pattern": "^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,63}$", "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

  • Handler function that implements the core logic of 'get-function' tool: authenticates, fetches function details from Alibaba Cloud FC using getFunction API, checks for associated custom domain, and returns formatted function information.
    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); let getFunctionResult; try { const getFunctionRequest = new GetFunctionRequest({}) getFunctionResult = await fcClient.getFunction(functionName, getFunctionRequest) } catch (error) { return { isError: true, content: [{ type: "text", text: `获取函数信息失败:${JSON.stringify(error as any)}` }] }; } const functionInfo = { ...getFunctionResult.body, } const autoDomainName = getAutoCustomDomainName(accountId, functionName, region); let getCustomDomainResult; try { getCustomDomainResult = await fcClient.getCustomDomain(autoDomainName); } catch (error: any) { if (error.statusCode !== 404) { return { isError: true, content: [{ type: "text", text: `获取函数域名信息失败:${JSON.stringify(error as any)}` }] }; } getCustomDomainResult = null; } if (getCustomDomainResult) { const routes = getCustomDomainResult.body?.routeConfig?.routes if (routes && routes.length == 1) { const route = routes[0]; if (route.functionName == functionName) { functionInfo.domain = autoDomainName; } } } return { content: [{ type: "text", text: `获取函数信息: ${JSON.stringify(functionInfo)}` }] }; }
  • src/index.ts:533-584 (registration)
    Registers the 'get-function' tool with the MCP server, specifying name, description, input schema, and handler function.
    server.tool( "get-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); let getFunctionResult; try { const getFunctionRequest = new GetFunctionRequest({}) getFunctionResult = await fcClient.getFunction(functionName, getFunctionRequest) } catch (error) { return { isError: true, content: [{ type: "text", text: `获取函数信息失败:${JSON.stringify(error as any)}` }] }; } const functionInfo = { ...getFunctionResult.body, } const autoDomainName = getAutoCustomDomainName(accountId, functionName, region); let getCustomDomainResult; try { getCustomDomainResult = await fcClient.getCustomDomain(autoDomainName); } catch (error: any) { if (error.statusCode !== 404) { return { isError: true, content: [{ type: "text", text: `获取函数域名信息失败:${JSON.stringify(error as any)}` }] }; } getCustomDomainResult = null; } if (getCustomDomainResult) { const routes = getCustomDomainResult.body?.routeConfig?.routes if (routes && routes.length == 1) { const route = routes[0]; if (route.functionName == functionName) { functionInfo.domain = autoDomainName; } } } return { content: [{ type: "text", text: `获取函数信息: ${JSON.stringify(functionInfo)}` }] }; } )
  • Zod schema for the 'region' input parameter used in the 'get-function' tool.
    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");
  • Zod schema for the 'functionName' input parameter used in the 'get-function' tool.
    export const functionNameSchema = z.string().describe("函数名称,函数名称在每个region必须是唯一的。") .regex(/^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,63}$/);
  • Helper function to generate the auto custom domain name for the function, used in the handler to check domain association.
    function getAutoCustomDomainName(uid: string, functionName: string, regionID: string) { const normalizedFunctionName = functionName.replace(/_/g, '-').toLowerCase(); return `${normalizedFunctionName}.fcv3.${uid}.${regionID}.fc.devsapp.net`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aliyun/alibabacloud-fc-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server