RunCommand
Execute commands across multiple ECS instances simultaneously using AlibabaCloud MCP Server, ideal for managing applications, marking resources, and automating tasks efficiently.
Instructions
批量在多台ECS实例上运行云助手命令,适用于需要同时管理多台ECS实例的场景,如应用程序管理和资源标记操作等。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Command | Yes | Content of the command executed on the ECS instance | |
| CommandType | No | The type of command executed on the ECS instance, optional value:RunShellScript,RunPythonScript,RunPerlScript,RunBatScript,RunPowerShellScript | RunShellScript |
| InstanceIds | Yes | AlibabaCloud ECS instance ID List | |
| RegionId | No | AlibabaCloud region ID | cn-hangzhou |
Implementation Reference
- The handler function for the 'OOS_RunCommand' tool, which executes the specified command on multiple ECS instances using Alibaba Cloud's OOS service 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 with the given template and parameters, and synchronously polls until completion or failure.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)
- src/alibaba_cloud_ops_mcp_server/server.py:82-83 (registration)The registration code that adds all tools from oos_tools module (including OOS_RunCommand) to the FastMCP server instance.for tool in oos_tools.tools: mcp.tool(tool)
- Pydantic Field definitions providing the input schema for the OOS_RunCommand tool.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')