Skip to main content
Glama
dkruyt

Hetzner Cloud MCP Server

by dkruyt

attach_volume

Attach a Hetzner Cloud volume to a server and optionally mount it for expanded storage capacity.

Instructions

Attach a volume to a server.

Attaches a volume to a server and optionally mounts it.

Example:
- Attach volume: {"volume_id": 12345, "server_id": 67890}
- Attach and mount: {"volume_id": 12345, "server_id": 67890, "automount": true}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The handler function implementing the attach_volume tool logic. It retrieves the volume and server, attaches the volume using the Hetzner client, and returns the action status.
    @mcp.tool()
    def attach_volume(params: AttachVolumeParams) -> Dict[str, Any]:
        """
        Attach a volume to a server.
        
        Attaches a volume to a server and optionally mounts it.
        
        Example:
        - Attach volume: {"volume_id": 12345, "server_id": 67890}
        - Attach and mount: {"volume_id": 12345, "server_id": 67890, "automount": true}
        """
        try:
            volume = client.volumes.get_by_id(params.volume_id)
            if not volume:
                return {"error": f"Volume with ID {params.volume_id} not found"}
            
            server = client.servers.get_by_id(params.server_id)
            if not server:
                return {"error": f"Server with ID {params.server_id} not found"}
            
            action = client.volumes.attach(volume, server, params.automount)
            
            # Format the response
            return {
                "success": True,
                "action": {
                    "id": action.id,
                    "status": action.status,
                    "command": action.command,
                    "progress": action.progress,
                    "error": action.error,
                    "started": action.started.isoformat() if action.started else None,
                    "finished": action.finished.isoformat() if action.finished else None,
                } if action else None,
            }
        except Exception as e:
            return {"error": f"Failed to attach volume: {str(e)}"}
  • Pydantic BaseModel defining the input parameters for the attach_volume tool.
    class AttachVolumeParams(BaseModel):
        volume_id: int = Field(..., description="The ID of the volume")
        server_id: int = Field(..., description="The ID of the server to attach the volume to")
        automount: Optional[bool] = Field(False, description="Auto-mount the volume after attaching it")
  • The @mcp.tool() decorator registers the attach_volume function as an MCP tool.
    @mcp.tool()

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/dkruyt/mcp-hetzner'

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