Skip to main content
Glama
rainhan99

Cloud Manage MCP Server

by rainhan99

get_alibaba_instance_info

Retrieve Alibaba Cloud ECS instance details using IP address or instance ID to access configuration, status, and resource information for cloud management.

Instructions

获取阿里云ECS实例信息

Args:
    ip_address_or_id (str): 公网IP地址或实例ID
    
Returns:
    Dict: 阿里云实例信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ip_address_or_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:554-570 (handler)
    MCP tool handler and registration for 'get_alibaba_instance_info'. Dispatches to alibaba_provider based on whether the input starts with 'i-' (instance ID) or is an IP address.
    @mcp.tool()
    def get_alibaba_instance_info(ip_address_or_id: str) -> Dict:
        """
        获取阿里云ECS实例信息
        
        Args:
            ip_address_or_id (str): 公网IP地址或实例ID
            
        Returns:
            Dict: 阿里云实例信息
        """
        # 阿里云实例ID通常以i-开头
        if ip_address_or_id.startswith('i-'):
            return alibaba_provider.get_instance_by_id(ip_address_or_id)
        else:
            return alibaba_provider.get_instance_by_ip(ip_address_or_id)
  • Core logic for retrieving Alibaba ECS instance by public IP address. Queries all instances and matches IP in public_ip_address or eip_address.
    def get_instance_by_ip(self, ip_address: str) -> Dict:
        """
        根据公网IP地址查找ECS实例
        
        Args:
            ip_address (str): 公网IP地址
            
        Returns:
            Dict: 实例信息或错误信息
        """
        if not self.available:
            return {
                'error': f'阿里云服务不可用: {getattr(self, "error", "未知错误")}',
                'provider': 'alibaba'
            }
        
        try:
            # 查询所有ECS实例
            request = ecs_models.DescribeInstancesRequest(
                region_id=self.region_id,
                page_size=100
            )
            
            response = self.client.describe_instances(request)
            
            if not response.body.instances:
                return {
                    'provider': 'alibaba',
                    'found': False,
                    'message': f'未找到使用IP地址 {ip_address} 的ECS实例',
                    'searched_region': self.region_id
                }
            
            # 查找匹配的IP地址
            for instance in response.body.instances.instance:
                # 检查公网IP
                public_ips = []
                if hasattr(instance, 'public_ip_address') and instance.public_ip_address:
                    public_ips.extend(instance.public_ip_address.ip_address)
                
                # 检查弹性公网IP
                if hasattr(instance, 'eip_address') and instance.eip_address.ip_address:
                    public_ips.append(instance.eip_address.ip_address)
                
                if ip_address in public_ips:
                    instance_info = self._format_instance_info(instance)
                    return {
                        'provider': 'alibaba',
                        'found': True,
                        'instance_info': instance_info
                    }
            
            return {
                'provider': 'alibaba',
                'found': False,
                'message': f'未找到使用IP地址 {ip_address} 的ECS实例',
                'total_instances_checked': len(response.body.instances.instance)
            }
            
        except Exception as e:
            return {
                'error': f'查询ECS实例时发生错误: {str(e)}',
                'provider': 'alibaba'
            }
  • Core logic for retrieving Alibaba ECS instance by instance ID using DescribeInstancesRequest with instance_ids filter.
    def get_instance_by_id(self, instance_id: str) -> Dict:
        """
        根据实例ID查找ECS实例
        
        Args:
            instance_id (str): ECS实例ID
            
        Returns:
            Dict: 实例信息或错误信息
        """
        if not self.available:
            return {
                'error': f'阿里云服务不可用: {getattr(self, "error", "未知错误")}',
                'provider': 'alibaba'
            }
        
        try:
            request = ecs_models.DescribeInstancesRequest(
                region_id=self.region_id,
                instance_ids=json.dumps([instance_id])
            )
            
            response = self.client.describe_instances(request)
            
            if not response.body.instances or not response.body.instances.instance:
                return {
                    'provider': 'alibaba',
                    'found': False,
                    'message': f'未找到ID为 {instance_id} 的ECS实例'
                }
            
            instance = response.body.instances.instance[0]
            instance_info = self._format_instance_info(instance)
            
            return {
                'provider': 'alibaba',
                'found': True,
                'instance_info': instance_info
            }
            
        except Exception as e:
            return {
                'error': f'查询ECS实例时发生错误: {str(e)}',
                'provider': 'alibaba'
            }
  • Helper function that formats the raw Alibaba ECS instance data into a standardized dictionary with all relevant fields like IPs, status, specs, tags, etc.
    def _format_instance_info(self, instance) -> Dict:
        """格式化实例详细信息"""
        # 获取公网IP
        public_ips = []
        if hasattr(instance, 'public_ip_address') and instance.public_ip_address:
            public_ips.extend(instance.public_ip_address.ip_address)
        
        # 获取弹性公网IP
        eip_address = None
        if hasattr(instance, 'eip_address') and instance.eip_address.ip_address:
            eip_address = instance.eip_address.ip_address
            public_ips.append(eip_address)
        
        # 获取私网IP
        private_ips = []
        if hasattr(instance, 'vpc_attributes') and instance.vpc_attributes.private_ip_address:
            private_ips.extend(instance.vpc_attributes.private_ip_address.ip_address)
        elif hasattr(instance, 'inner_ip_address') and instance.inner_ip_address:
            private_ips.extend(instance.inner_ip_address.ip_address)
        
        # 获取标签
        tags = {}
        if hasattr(instance, 'tags') and instance.tags.tag:
            for tag in instance.tags.tag:
                tags[tag.tag_key] = tag.tag_value
        
        # 获取安全组
        security_groups = []
        if hasattr(instance, 'security_group_ids') and instance.security_group_ids.security_group_id:
            security_groups = instance.security_group_ids.security_group_id
        
        return {
            'instance_id': instance.instance_id,
            'name': instance.instance_name,
            'hostname': getattr(instance, 'hostname', ''),
            'status': instance.status,
            'instance_type': instance.instance_type,
            'image_id': instance.image_id,
            'region_id': instance.region_id,
            'zone_id': instance.zone_id,
            'cpu': instance.cpu,
            'memory': instance.memory,
            'public_ips': public_ips,
            'private_ips': private_ips,
            'eip_address': eip_address,
            'creation_time': instance.creation_time,
            'start_time': getattr(instance, 'start_time', ''),
            'expired_time': getattr(instance, 'expired_time', ''),
            'os_name': getattr(instance, 'osname', ''),
            'os_type': getattr(instance, 'ostype', ''),
            'instance_charge_type': instance.instance_charge_type,
            'internet_charge_type': getattr(instance, 'internet_charge_type', ''),
            'internet_max_bandwidth_in': getattr(instance, 'internet_max_bandwidth_in', 0),
            'internet_max_bandwidth_out': getattr(instance, 'internet_max_bandwidth_out', 0),
            'vpc_id': getattr(instance, 'vpc_id', ''),
            'vswitch_id': getattr(instance, 'vswitch_id', ''),
            'security_group_ids': security_groups,
            'tags': tags
        }
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 retrieves information, implying a read-only operation, but doesn't clarify if it requires specific permissions, has rate limits, returns partial or complete data, or handles errors. For a cloud API tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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, with the core purpose stated first in a single sentence. The Args and Returns sections are structured but could be more integrated. There's no wasted text, though it lacks elaboration on usage or behavior that might be necessary for clarity.

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 moderate complexity (cloud instance info retrieval), no annotations, and an output schema present (which handles return values), the description is minimally adequate. It covers the basic purpose and parameter intent but misses usage guidelines, behavioral details, and deeper parameter context, making it incomplete for optimal agent operation without additional inference.

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 minimal semantics beyond the input schema. It explains that 'ip_address_or_id' accepts a public IP address or instance ID, which clarifies the parameter's purpose, but with 0% schema description coverage, this doesn't fully compensate. It doesn't detail format constraints (e.g., IP address validation, ID patterns) or provide examples, leaving the agent to infer from the schema alone.

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实例信息' (Get Alibaba Cloud ECS instance information). It specifies the resource (Alibaba Cloud ECS instances) and the action (get information), which distinguishes it from power management or listing tools among siblings. However, it doesn't explicitly differentiate from similar tools like 'get_instance_info' or 'get_instance_by_provider' that might serve overlapping functions.

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 when to choose this over 'list_alibaba_instances' for bulk retrieval, 'get_alibaba_instance_monitoring' for metrics, or 'get_instance_info' which might be provider-agnostic. There's also no indication of prerequisites, such as authentication or instance state requirements.

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/rainhan99/cloud_manage_mcp_server'

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