Skip to main content
Glama
aliyun

AlibabaCloud MCP Server

Official
by aliyun

DeleteInstances

Bulk delete or release pay-as-you-go instances or expired subscription instances on AlibabaCloud MCP Server, with options to manage disk retention or conversion.

Instructions

本接口用于批量删除或者释放按量付费实例或者到期的包年包月实例,支持通过参数设置决定云盘是否释放或转换为按量付费保留。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ClientTokenNo保证请求幂等性。从您的客户端生成一个参数值,确保不同请求间该参数值唯一。**ClientToken**只支持ASCII字符,且不能超过64个字符。更多信息,请参见[如何保证幂等性](~~25693~~)。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:123e4567-e89b-12d3-a456-426655440000
DryRunNo是否只预检此次请求。 - true:发送检查请求,不会查询资源状况。检查项包括AccessKey是否有效、RAM用户的授权情况和是否填写了必需参数。如果检查不通过,则返回对应错误。如果检查通过,会返回错误码DRYRUN.SUCCESS。 - false:发送正常请求,通过检查后返回2XX HTTP状态码并直接查询资源状况。 默认值:false。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: boolean,参数示例:false
ForceNo是否强制释放**运行中**(`Running`)的ECS实例。 - true:强制释放**运行中**(`Running`)的实例。 - false:正常释放实例,此时实例必须处于**已停止**(`Stopped`)状态。 默认值:false。 ><warning>强制释放相当于断电,实例内存以及存储中的临时数据都会被擦除,无法恢复。></warning> 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: boolean,参数示例:false
ForceStopNo释放**运行中**(`Running`)的实例时的是否采取强制关机策略。仅当`Force=true`时生效。取值范围: - true:强制关机并释放实例。相当于典型的断电操作,实例会直接进入资源释放流程。 ><warning>强制释放相当于断电,实例内存以及存储中的临时数据都会被擦除,无法恢复。></warning> - false:在实例释放前,系统将优先执行标准关机流程,该模式会导致实例释放动作持续几分钟。用户在操作系统关机时,配置一些业务排水动作,从而减少业务系统的噪声。 默认值:true。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: boolean,参数示例:true
InstanceIdYes实例ID数组。数组长度:1~100。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: array,参数示例:i-bp1g6zv0ce8oghu7****
RegionIdYes实例所属的地域ID。您可以调用[DescribeRegions](~~25609~~)查看最新的阿里云地域列表。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: string,参数示例:cn-hangzhou
TerminateSubscriptionNo是否释放已到期的包年包月实例。 - true:释放。 - false:不释放。 默认值:false。 请注意,提供参数要严格按照参数的类型和参数示例的提示,如果提到参数为String,且为一个 JSON 数组字符串,应在数组内使用单引号包裹对应的参数以避免转义问题,并在最外侧用双引号包裹以确保其是字符串,否则可能会导致参数解析错误。参数类型: boolean,参数示例:false

Implementation Reference

  • The core handler function executed by the dynamic tool for DeleteInstances, performing the Alibaba Cloud ECS API call.
    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 generates the input schema for DeleteInstances tool based on API metadata.
    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 listing 'DeleteInstances' as an ECS tool to be registered dynamically.
    'ecs': [
        'DescribeInstances',
        'DescribeRegions',
        'DescribeZones',
        'DescribeAccountAttributes',
        'DescribeAvailableResource',
        'DescribeImages',
        'DescribeSecurityGroups',
        'DeleteInstances'
    ],
  • Registers the DeleteInstances tool (among others) by dynamically creating and decorating tool functions from config and API metadata.
    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)
  • Invokes the registration of API tools including DeleteInstances.
    api_tools.create_api_tools(mcp, config)

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-core-mcp-server'

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