Skip to main content
Glama

Alibaba Cloud MCP Server

Official
by aliyun

DeleteInstances

Manage and delete Alibaba Cloud ECS instances in bulk, including pay-as-you-go or expired subscription instances, with options to release or retain associated disks. Supports forced shutdown and dry-run checks for instance termination.

Instructions

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

Input 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

Input Schema (JSON Schema)

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

Implementation Reference

  • Configuration defining the list of ECS APIs to register as MCP tools, including 'DeleteInstances'.
    config = { 'ecs': [ 'DescribeInstances', 'DescribeRegions', 'DescribeZones', 'DescribeAccountAttributes', 'DescribeAvailableResource', 'DescribeImages', 'DescribeSecurityGroups', 'DeleteInstances' ], 'Vpc': [ 'DescribeVpcs', 'DescribeVSwitches' ], 'rds': [ 'DescribeDBInstances' ] }
  • Triggers the registration of dynamic API tools by calling create_api_tools with the config that includes DeleteInstances.
    api_tools.create_api_tools(mcp, config)
  • Registers a dynamic MCP tool for each API listed in config, including ECS_DeleteInstances based on 'DeleteInstances'.
    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)
  • Dynamically generates the input schema (Pydantic dataclass fields) for the tool from the API metadata retrieved for DeleteInstances.
    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
  • Executes the actual Alibaba Cloud API call for service='ecs' and api='DeleteInstances' with the provided parameters, handling specifics like endpoint and ECS list parameters.
    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

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

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