DescribeZones
Query available zone details on AlibabaCloud by specifying region ID, billing method, and other parameters. Retrieve comprehensive zone information to manage and deploy resources efficiently.
Instructions
根据地域ID、计费方式等参数查询可用区信息列表。
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:包年包月。 - PostPaid:按量付费。 默认值:PostPaid。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:PostPaid | |
| RegionId | Yes | 可用区所在的地域ID。您可以调用[DescribeRegions](~~25609~~)查看最新的阿里云地域列表。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:cn-hangzhou | |
| SpotStrategy | No | 按量付费实例的竞价策略。当`InstanceChargeType=PostPaid`时,您可以传入该参数。更多信息,请参见[抢占式实例](~~52088~~)。取值范围: - NoSpot:正常按量付费实例。 - SpotWithPriceLimit:设置上限价格的抢占式实例。 - SpotAsPriceGo:系统自动出价,最高按量付费价格。 默认值:NoSpot。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:NoSpot | |
| Verbose | No | 是否展示详细信息。 - true:展示。 - false:不展示。 默认值:true。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: boolean,参数示例:false |
Implementation Reference
- The _tools_api_call function implements the core logic for calling Alibaba Cloud APIs, used by the dynamic DescribeZones tool.
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 - _create_function_schemas dynamically generates the input schema for tools like DescribeZones based on API meta data.
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 - src/alibaba_cloud_ops_mcp_server/tools/api_tools.py:256-266 (registration)_create_and_decorate_tool creates and registers the dynamic tool function for each API including DescribeZones using mcp.tool()
def _create_and_decorate_tool(mcp: FastMCP, service: str, api: str): """Create a tool function for an AlibabaCloud openapi.""" api_meta, _ = ApiMetaClient.get_api_meta(service, api) fields = _create_function_schemas(service, api, api_meta).get(api, {}) description = api_meta.get('summary', '') dynamic_lambda = _create_tool_function_with_signature(service, api, fields, description) function_name = f'{service.upper()}_{api}' decorated_function = mcp.tool(name=function_name)(dynamic_lambda) return decorated_function - src/alibaba_cloud_ops_mcp_server/config.py:8-17 (registration)Config lists 'DescribeZones' under 'ecs' service, which triggers its dynamic tool registration.
'ecs': [ 'DescribeInstances', 'DescribeRegions', 'DescribeZones', 'DescribeAccountAttributes', 'DescribeAvailableResource', 'DescribeImages', 'DescribeSecurityGroups', 'DeleteInstances' ], - src/alibaba_cloud_ops_mcp_server/server.py:88-88 (registration)api_tools.create_api_tools(mcp, config) is called to register all tools listed in config, including DescribeZones.
api_tools.create_api_tools(mcp, config)