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
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- mcp_hetzner/server.py:1090-1126 (handler)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)}"}
- mcp_hetzner/server.py:229-233 (schema)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")
- mcp_hetzner/server.py:1090-1090 (registration)The @mcp.tool() decorator registers the attach_volume function as an MCP tool.@mcp.tool()