Skip to main content
Glama
aliyun

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

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

  • 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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only mentions cloud disk handling options. It fails to disclose critical behavioral traits: this is a destructive operation with irreversible data loss, requires specific permissions, has no rate limit information, and doesn't describe response format or error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently communicates core functionality. It's appropriately sized and front-loaded with the main purpose, though it could benefit from additional context about the tool's destructive nature.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a highly destructive tool with 7 parameters, no annotations, and no output schema, the description is inadequate. It lacks critical information about irreversible consequences, authentication requirements, error handling, and response format, leaving significant gaps for safe agent invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds value by explaining the tool supports parameter settings for cloud disk handling ('支持通过参数设置决定云盘是否释放或转换为按量付费保留'), which provides context beyond individual parameter descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('批量删除或者释放') and resources ('按量付费实例或者到期的包年包月实例'), and distinguishes it from siblings by focusing on deletion/release operations rather than description, monitoring, or management functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for deleting/releasing instances based on billing type, but provides no explicit guidance on when to use this tool versus alternatives like StopInstances or RebootInstances, nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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