Skip to main content
Glama
RadiumGu

Alibaba Cloud Operations MCP Server

by RadiumGu

run_ecs_command

Execute commands on Alibaba Cloud ECS instances to manage, configure, or troubleshoot cloud servers remotely.

Instructions

在ECS实例上运行命令

Args:
    region: 区域ID,如cn-beijing
    instance_ids: ECS实例ID列表
    command: 要执行的命令

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionNocn-beijing
instance_idsNo
commandNoecho 'Hello World'

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the MCP tool 'run_ecs_command'. Registered via @app.tool(). It wraps and calls the underlying OOS_RunCommand by dynamic lookup.
    @app.tool()
    def run_ecs_command(region: str = "cn-beijing", instance_ids: List[str] = None, command: str = "echo 'Hello World'") -> str:
        """在ECS实例上运行命令
        
        Args:
            region: 区域ID,如cn-beijing
            instance_ids: ECS实例ID列表
            command: 要执行的命令
        """
        try:
            sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'alibaba_cloud_ops_mcp_server'))
            from tools import oos_tools
            
            if not instance_ids:
                return "请提供ECS实例ID列表"
            
            for tool_func in oos_tools.tools:
                if hasattr(tool_func, '__name__') and 'run' in tool_func.__name__.lower() and 'command' in tool_func.__name__.lower():
                    result = tool_func(RegionId=region, InstanceIds=instance_ids, CommandContent=command)
                    return str(result)
            
            return f"ECS命令执行功能可用,region: {region}, 实例: {instance_ids}, 命令: {command}"
        except Exception as e:
            return f"ECS命令执行失败: {str(e)}"
  • Pydantic-based input schema definitions for the OOS_RunCommand function, which defines parameters like Command, InstanceIds, RegionId, and CommandType.
    def OOS_RunCommand(
        Command: str = Field(description='Content of the command executed on the ECS instance'),
        InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
        RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
        CommandType: str = Field(description='The type of command executed on the ECS instance, optional value:RunShellScript,RunPythonScript,RunPerlScript,RunBatScript,RunPowerShellScript', default='RunShellScript')
    ):
  • Core handler implementation OOS_RunCommand that invokes Alibaba Cloud OOS to run commands on multiple ECS instances using the 'ACS-ECS-BulkyRunCommand' template.
    @tools.append
    def OOS_RunCommand(
        Command: str = Field(description='Content of the command executed on the ECS instance'),
        InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
        RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
        CommandType: str = Field(description='The type of command executed on the ECS instance, optional value:RunShellScript,RunPythonScript,RunPerlScript,RunBatScript,RunPowerShellScript', default='RunShellScript')
    ):
        """批量在多台ECS实例上运行云助手命令,适用于需要同时管理多台ECS实例的场景,如应用程序管理和资源标记操作等。"""
        
        parameters = {
            'regionId': RegionId,
            'resourceType': 'ALIYUN::ECS::Instance',
            'targets': {
                'ResourceIds': InstanceIds,
                'RegionId': RegionId,
                'Type': 'ResourceIds',
                'Parameters': {
                    'RegionId': RegionId,
                    'Status': 'Running'
                }
            },
            "commandType": CommandType,
            "commandContent": Command
        }
        return _start_execution_sync(region_id=RegionId, template_name='ACS-ECS-BulkyRunCommand', parameters=parameters)
  • Helper function that starts an OOS execution and polls until completion, handling success, failure, or cancellation.
    def _start_execution_sync(region_id: str, template_name: str, parameters: dict):
        client = create_client(region_id=region_id)
        start_execution_request = oos_20190601_models.StartExecutionRequest(
            region_id=region_id,
            template_name=template_name,
            parameters=json.dumps(parameters)
        )
        start_execution_resp = client.start_execution(start_execution_request)
        execution_id = start_execution_resp.body.execution.execution_id
    
        while True:
            list_executions_request = oos_20190601_models.ListExecutionsRequest(
                region_id=region_id,
                execution_id=execution_id
            )
            list_executions_resp = client.list_executions(list_executions_request)
            status = list_executions_resp.body.executions[0].status
            if status == FAILED:
                status_message = list_executions_resp.body.executions[0].status_message
                raise exception.OOSExecutionFailed(reason=status_message)
            elif status in END_STATUSES:
                return list_executions_resp.body
            time.sleep(1)
    @tools.append
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool runs commands but doesn't describe critical behaviors: whether it requires specific permissions, if commands run as root or a user, timeout limits, output handling, or error conditions. For a command execution tool with zero annotation coverage, this leaves significant gaps in understanding its operational traits.

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 appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by a structured 'Args' section listing parameters with brief explanations. There's no wasted text, though it could be more polished (e.g., using bullet points instead of plain text). Every sentence adds value, making it efficient.

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

Completeness3/5

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

Given the tool's complexity (command execution on cloud instances), no annotations, and an output schema exists (which covers return values), the description is minimally complete. It explains what the tool does and parameters but lacks behavioral context (e.g., security implications, execution environment). With the output schema handling returns, it's adequate but has clear gaps in safety and operational guidance.

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

Parameters3/5

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

The description adds basic semantics for all 3 parameters (region, instance_ids, command) with examples like 'cn-beijing' for region and '要执行的命令' (command to execute). However, schema description coverage is 0%, so the schema provides no additional documentation. The description compensates somewhat but lacks details on parameter constraints (e.g., region format, instance ID validation, command length limits), keeping it at a baseline level.

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

Purpose4/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: '在ECS实例上运行命令' (run commands on ECS instances). It specifies the verb '运行' (run) and resource 'ECS实例' (ECS instances), making the action clear. However, it doesn't explicitly differentiate from sibling tools like 'reboot_ecs_instances' or 'start_ecs_instances', which are also ECS-related operations.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., instance must be running), exclusions (e.g., commands that require sudo), or compare it to sibling tools like 'describe_ecs_instances' for checking instance status before running commands. Usage is implied but not explicitly stated.

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

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/RadiumGu/alicloud-ops-mcp'

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