get_vultr_instance_info
Retrieve detailed information about Vultr cloud instances using a public IP address or instance ID, enabling efficient management and monitoring of cloud resources.
Instructions
获取Vultr实例信息
Args:
ip_address_or_id (str): 公网IP地址或实例ID
Returns:
Dict: Vultr实例信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip_address_or_id | Yes |
Implementation Reference
- main.py:481-497 (handler)The primary MCP tool handler function for 'get_vultr_instance_info'. It inspects the input to determine if it's an instance ID (UUID-like) or IP address, then delegates to the appropriate Vultr provider method.@mcp.tool() def get_vultr_instance_info(ip_address_or_id: str) -> Dict: """ 获取Vultr实例信息 Args: ip_address_or_id (str): 公网IP地址或实例ID Returns: Dict: Vultr实例信息 """ # Vultr实例ID通常是UUID格式 if '-' in ip_address_or_id and len(ip_address_or_id) > 20: return vultr_provider.get_instance_by_id(ip_address_or_id) else: return vultr_provider.get_instance_by_ip(ip_address_or_id)
- providers/vultr_provider.py:29-85 (helper)Core helper method in VultrProvider class that queries all instances via Vultr API and finds the one matching the given IP address (main_ip).def get_instance_by_ip(self, ip_address: str) -> Dict: """ 根据公网IP地址查找Vultr实例 Args: ip_address (str): 公网IP地址 Returns: Dict: 实例信息或错误信息 """ if not self.available: return { 'error': f'Vultr服务不可用: {getattr(self, "error", "未知错误")}', 'provider': 'vultr' } try: # 获取所有实例 response = requests.get(f'{self.base_url}/instances', headers=self.headers, timeout=10) if response.status_code != 200: return { 'error': f'Vultr API调用失败: {response.status_code} - {response.text}', 'provider': 'vultr' } data = response.json() instances = data.get('instances', []) # 查找匹配的IP地址 for instance in instances: if instance.get('main_ip') == ip_address: instance_info = self._format_instance_info(instance) return { 'provider': 'vultr', 'found': True, 'instance_info': instance_info } return { 'provider': 'vultr', 'found': False, 'message': f'未找到使用IP地址 {ip_address} 的Vultr实例', 'total_instances_checked': len(instances) } except requests.RequestException as e: return { 'error': f'网络请求失败: {str(e)}', 'provider': 'vultr' } except Exception as e: return { 'error': f'查询Vultr实例时发生错误: {str(e)}', 'provider': 'vultr' }
- providers/vultr_provider.py:86-138 (helper)Core helper method in VultrProvider class that directly queries the Vultr API for a specific instance by its ID.def get_instance_by_id(self, instance_id: str) -> Dict: """ 根据实例ID查找Vultr实例 Args: instance_id (str): Vultr实例ID Returns: Dict: 实例信息或错误信息 """ if not self.available: return { 'error': f'Vultr服务不可用: {getattr(self, "error", "未知错误")}', 'provider': 'vultr' } try: response = requests.get(f'{self.base_url}/instances/{instance_id}', headers=self.headers, timeout=10) if response.status_code == 404: return { 'provider': 'vultr', 'found': False, 'message': f'未找到ID为 {instance_id} 的Vultr实例' } if response.status_code != 200: return { 'error': f'Vultr API调用失败: {response.status_code} - {response.text}', 'provider': 'vultr' } data = response.json() instance = data.get('instance', {}) instance_info = self._format_instance_info(instance) return { 'provider': 'vultr', 'found': True, 'instance_info': instance_info } except requests.RequestException as e: return { 'error': f'网络请求失败: {str(e)}', 'provider': 'vultr' } except Exception as e: return { 'error': f'查询Vultr实例时发生错误: {str(e)}', 'provider': 'vultr' }
- providers/vultr_provider.py:374-402 (helper)Helper method that formats raw Vultr API instance data into a standardized dictionary response.def _format_instance_info(self, instance: Dict) -> Dict: """格式化实例详细信息""" return { 'id': instance.get('id'), 'label': instance.get('label', '未命名'), 'hostname': instance.get('hostname'), 'status': instance.get('status'), 'power_status': instance.get('power_status'), 'server_status': instance.get('server_status'), 'allowed_bandwidth': instance.get('allowed_bandwidth'), 'netmask_v4': instance.get('netmask_v4'), 'gateway_v4': instance.get('gateway_v4'), 'main_ip': instance.get('main_ip'), 'v6_main_ip': instance.get('v6_main_ip'), 'ram': instance.get('ram'), 'disk': instance.get('disk'), 'vcpu_count': instance.get('vcpu_count'), 'region': instance.get('region'), 'plan': instance.get('plan'), 'os': instance.get('os'), 'os_id': instance.get('os_id'), 'app_id': instance.get('app_id'), 'firewall_group_id': instance.get('firewall_group_id'), 'features': instance.get('features', []), 'tags': instance.get('tags', []), 'internal_ip': instance.get('internal_ip'), 'kvm': instance.get('kvm'), 'date_created': instance.get('date_created') }