get_digitalocean_droplet_info
Retrieve detailed information about a DigitalOcean Droplet by providing its IP address or ID, enabling efficient cloud server management on the Cloud Manage MCP Server.
Instructions
获取DigitalOcean Droplet信息
Args:
ip_address_or_id (str): 公网IP地址或Droplet ID
Returns:
Dict: Droplet信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip_address_or_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"ip_address_or_id": {
"title": "Ip Address Or Id",
"type": "string"
}
},
"required": [
"ip_address_or_id"
],
"title": "get_digitalocean_droplet_infoArguments",
"type": "object"
}
Implementation Reference
- main.py:378-394 (handler)MCP tool registration and handler function for 'get_digitalocean_droplet_info'. Dispatches to provider's get_droplet_by_id or get_droplet_by_ip based on whether input is numeric.@mcp.tool() def get_digitalocean_droplet_info(ip_address_or_id: str) -> Dict: """ 获取DigitalOcean Droplet信息 Args: ip_address_or_id (str): 公网IP地址或Droplet ID Returns: Dict: Droplet信息 """ # 判断是IP地址还是Droplet ID if ip_address_or_id.isdigit(): return digitalocean_provider.get_droplet_by_id(int(ip_address_or_id)) else: return digitalocean_provider.get_droplet_by_ip(ip_address_or_id)
- Core logic for retrieving DigitalOcean Droplet by public IP address. Lists all droplets and matches IP in public v4 networks.def get_droplet_by_ip(self, ip_address: str) -> Dict: """ 根据公网IP地址查找Droplet Args: ip_address (str): 公网IP地址 Returns: Dict: Droplet信息或错误信息 """ if not self.available: return { 'error': f'DigitalOcean服务不可用: {getattr(self, "error", "未知错误")}', 'provider': 'digitalocean' } try: response = self.client.droplets.list() droplets = response.get("droplets", []) for droplet in droplets: networks = droplet.get("networks", {}) ipv4_networks = networks.get("v4", []) for network in ipv4_networks: if network.get("type") == "public" and network.get("ip_address") == ip_address: droplet_info = self._format_droplet_info(droplet) return { 'provider': 'digitalocean', 'found': True, 'droplet_info': droplet_info } return { 'provider': 'digitalocean', 'found': False, 'message': f'未找到使用IP地址 {ip_address} 的Droplet', 'total_droplets_checked': len(droplets) } except Exception as e: return { 'error': f'查询Droplet时发生错误: {str(e)}', 'provider': 'digitalocean' }
- Core logic for retrieving specific DigitalOcean Droplet by its ID using the pydo client.def get_droplet_by_id(self, droplet_id: int) -> Dict: """ 根据Droplet ID查找信息 Args: droplet_id (int): Droplet ID Returns: Dict: Droplet信息或错误信息 """ if not self.available: return { 'error': f'DigitalOcean服务不可用: {getattr(self, "error", "未知错误")}', 'provider': 'digitalocean' } try: response = self.client.droplets.get(droplet_id) droplet = response.get("droplet", {}) if not droplet: return { 'provider': 'digitalocean', 'found': False, 'message': f'未找到ID为 {droplet_id} 的Droplet' } droplet_info = self._format_droplet_info(droplet) return { 'provider': 'digitalocean', 'found': True, 'droplet_info': droplet_info } except Exception as e: return { 'error': f'查询Droplet时发生错误: {str(e)}', 'provider': 'digitalocean' }
- Helper function to format raw DigitalOcean Droplet data into a structured dictionary with extracted IPs, specs, and metadata.def _format_droplet_info(self, droplet: Dict) -> Dict: """格式化Droplet详细信息""" networks = droplet.get("networks", {}) # 获取IP地址 public_ip = None private_ip = None public_ipv6 = None for net in networks.get("v4", []): if net.get("type") == "public": public_ip = net.get("ip_address") elif net.get("type") == "private": private_ip = net.get("ip_address") for net in networks.get("v6", []): if net.get("type") == "public": public_ipv6 = net.get("ip_address") return { 'id': droplet.get("id"), 'name': droplet.get("name"), 'status': droplet.get("status"), 'size_slug': droplet.get("size_slug"), 'memory': droplet.get("memory"), 'vcpus': droplet.get("vcpus"), 'disk': droplet.get("disk"), 'region': droplet.get("region", {}).get("name"), 'region_slug': droplet.get("region", {}).get("slug"), 'image': { 'id': droplet.get("image", {}).get("id"), 'name': droplet.get("image", {}).get("name"), 'distribution': droplet.get("image", {}).get("distribution"), 'slug': droplet.get("image", {}).get("slug") }, 'public_ipv4': public_ip, 'private_ipv4': private_ip, 'public_ipv6': public_ipv6, 'features': droplet.get("features", []), 'tags': droplet.get("tags", []), 'created_at': droplet.get("created_at"), 'volume_ids': droplet.get("volume_ids", []), 'vpc_uuid': droplet.get("vpc_uuid") }