DescribeRegions
Retrieve region information lists for Alibaba Cloud resources based on billing methods, resource types, and other parameters to optimize resource allocation and deployment.
Instructions
根据计费方式、资源类型等参数查询地域信息列表。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| AcceptLanguage | No | 根据汉语、英语和日语筛选返回结果。更多详情,请参见[RFC 7231](https://tools.ietf.org/html/rfc7231)。取值范围: - zh-CN:简体中文。 - zh-TW:繁体中文。 - en-US:英文。 - ja:日文。 - fr:法语。 - de:德语。 - ko:韩语。 默认值:zh-CN。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:zh-CN | |
| InstanceChargeType | No | 实例的计费方式,更多信息,请参见[计费概述](~~25398~~)。取值范围: - PrePaid:包年包月。此时,请确认自己的账号支持余额支付或者信用支付,否则将报错InvalidPayMethod。 - PostPaid:按量付费。 - SpotWithPriceLimit:设置上限价格。 - SpotAsPriceGo:系统自动出价,最高按量付费价格。 默认值:PostPaid。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:PrePaid | |
| RegionId | No | 地域ID | |
| ResourceType | No | 资源类型。取值范围: - instance:ECS实例。 - disk:磁盘。 - reservedinstance:预留实例券。 - scu:存储容量单位包。 默认值:instance。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:instance |
Input Schema (JSON Schema)
{
"properties": {
"AcceptLanguage": {
"default": null,
"description": "根据汉语、英语和日语筛选返回结果。更多详情,请参见[RFC 7231](https://tools.ietf.org/html/rfc7231)。取值范围: \n \n- zh-CN:简体中文。\n- zh-TW:繁体中文。\n- en-US:英文。\n- ja:日文。\n- fr:法语。\n- de:德语。\n- ko:韩语。\n\n默认值:zh-CN。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:zh-CN",
"title": "Acceptlanguage",
"type": "string"
},
"InstanceChargeType": {
"default": null,
"description": "实例的计费方式,更多信息,请参见[计费概述](~~25398~~)。取值范围:\n\n- PrePaid:包年包月。此时,请确认自己的账号支持余额支付或者信用支付,否则将报错InvalidPayMethod。\n- PostPaid:按量付费。\n- SpotWithPriceLimit:设置上限价格。\n- SpotAsPriceGo:系统自动出价,最高按量付费价格。\n\n默认值:PostPaid。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:PrePaid",
"title": "Instancechargetype",
"type": "string"
},
"RegionId": {
"default": null,
"description": "地域ID",
"title": "Regionid",
"type": "string"
},
"ResourceType": {
"default": null,
"description": "资源类型。取值范围:\n\n- instance:ECS实例。\n- disk:磁盘。\n- reservedinstance:预留实例券。\n- scu:存储容量单位包。\n\n默认值:instance。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:instance",
"title": "Resourcetype",
"type": "string"
}
},
"title": "DescribeRegionsArguments",
"type": "object"
}
Implementation Reference
- src/alibaba_cloud_ops_mcp_server/tools/api_tools.py:267-271 (registration)This function registers dynamic MCP tools for each API listed in the config, including the 'DescribeRegions' tool for the 'ecs' service by calling _create_and_decorate_tool.def create_api_tools(mcp: FastMCP, config:dict): for service_code, apis in config.items(): for api_name in apis: _create_and_decorate_tool(mcp, service_code, api_name)
- Core handler logic executed by the dynamic DescribeRegions tool. Fetches API metadata for 'ecs.DescribeRegions', prepares the request, and calls the Alibaba Cloud OpenAPI client.def _tools_api_call(service: str, api: str, parameters: dict, ctx: Context): service = service.lower() api_meta, _ = ApiMetaClient.get_api_meta(service, api) version = ApiMetaClient.get_service_version(service) method = 'POST' if api_meta.get('methods', [])[0] == 'post' else 'GET' path = api_meta.get('path', '/') style = ApiMetaClient.get_service_style(service) # Handling special parameter formats processed_parameters = parameters.copy() processed_parameters = {k: v for k, v in processed_parameters.items() if v is not None} if service == 'ecs': for param_name, param_value in parameters.items(): if param_name in ECS_LIST_PARAMETERS and isinstance(param_value, list): processed_parameters[param_name] = json.dumps(param_value) req = open_api_models.OpenApiRequest( query=OpenApiUtilClient.query(processed_parameters) ) params = open_api_models.Params( action=api, version=version, protocol='HTTPS', pathname=path, method=method, auth_type='AK', style=style, req_body_type='formData', body_type='json' ) logger.info(f'Call API Request: Service: {service} API: {api} Method: {method} Parameters: {processed_parameters}') client = create_client(service, processed_parameters.get('RegionId', 'cn-hangzhou')) runtime = util_models.RuntimeOptions() resp = client.call_api(params, req, runtime) logger.info(f'Call API Response: {resp}') return resp
- Dynamically creates the input schema for the DescribeRegions tool by parsing the API metadata parameters for 'ecs.DescribeRegions'.def _create_function_schemas(service, api, api_meta): schemas = {} schemas[api] = {} parameters = api_meta.get('parameters', []) required_params = [] optional_params = [] for parameter in parameters: name = parameter.get('name') # TODO 目前忽略了带'.'的参数 if '.' in name: continue schema = parameter.get('schema', '') required = schema.get('required', False) if required: required_params.append(parameter) else: optional_params.append(parameter) def process_parameter(parameter): name = parameter.get('name') schema = parameter.get('schema', '') description = schema.get('description', '') example = schema.get('example', '') type_ = schema.get('type', '') description = f'{description} 参数类型: {type_},参数示例:{example}' required = schema.get('required', False) if service.lower() == 'ecs' and name in ECS_LIST_PARAMETERS and type_ == 'string': python_type = list else: python_type = type_map.get(type_, str) field_info = ( python_type, field( default=None, metadata={'description': description, 'required': required} ) ) return name, field_info for parameter in required_params: name, field_info = process_parameter(parameter) schemas[api][name] = field_info for parameter in optional_params: name, field_info = process_parameter(parameter) schemas[api][name] = field_info if 'RegionId' not in schemas[api]: schemas[api]['RegionId'] = ( str, field( default='cn-hangzhou', metadata={'description': '地域ID', 'required': False} ) ) return schemas
- Configuration dictionary that specifies 'DescribeRegions' as one of the APIs to register for the 'ecs' service.config = { 'ecs': [ 'DescribeInstances', 'DescribeRegions', 'DescribeZones', 'DescribeAccountAttributes', 'DescribeAvailableResource', 'DescribeImages', 'DescribeSecurityGroups', 'DeleteInstances' ], 'Vpc': [ 'DescribeVpcs', 'DescribeVSwitches' ], 'rds': [ 'DescribeDBInstances' ] }
- src/alibaba_cloud_ops_mcp_server/server.py:88-89 (registration)Invocation of create_api_tools with config, which triggers registration of the DescribeRegions tool.api_tools.create_api_tools(mcp, config)