Skip to main content
Glama
rainhan99

Cloud Manage MCP Server

by rainhan99

get_digitalocean_droplet_info

Retrieve detailed information about DigitalOcean droplets using either their public IP address or droplet ID to monitor status, track resources, and manage cloud servers.

Instructions

获取DigitalOcean Droplet信息

Args:
    ip_address_or_id (str): 公网IP地址或Droplet ID
    
Returns:
    Dict: Droplet信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ip_address_or_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:378-394 (handler)
    The MCP tool handler for 'get_digitalocean_droplet_info', decorated with @mcp.tool(). Dispatches to provider methods based on whether input is numeric ID or IP address.
    @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)
  • Helper method to find DigitalOcean Droplet by public IPv4 address by listing all droplets and matching 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'
            }
  • Helper method to retrieve specific DigitalOcean Droplet by its integer ID.
    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'
            }
  • Private helper to format raw API response of a droplet into a clean structured dictionary used by the query methods.
    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")
        }

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