update_firewall
Modify firewall configuration by updating its name or labels in Hetzner Cloud to maintain accurate resource identification and organization.
Instructions
Update a firewall.
Updates the name or labels of an existing firewall.
Example:
- Update name: {"firewall_id": 12345, "name": "new-name"}
- Update labels: {"firewall_id": 12345, "labels": {"key": "value"}}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- mcp_hetzner/server.py:747-770 (handler)The handler function for the 'update_firewall' tool. Updates the name and/or labels of a specified Hetzner Cloud firewall using the hcloud client.def update_firewall(params: UpdateFirewallParams) -> Dict[str, Any]: """ Update a firewall. Updates the name or labels of an existing firewall. Example: - Update name: {"firewall_id": 12345, "name": "new-name"} - Update labels: {"firewall_id": 12345, "labels": {"key": "value"}} """ try: firewall = client.firewalls.get_by_id(params.firewall_id) if not firewall: return {"error": f"Firewall with ID {params.firewall_id} not found"} updated_firewall = client.firewalls.update( firewall=firewall, name=params.name, labels=params.labels ) return {"firewall": firewall_to_dict(updated_firewall)} except Exception as e: return {"error": f"Failed to update firewall: {str(e)}"}
- mcp_hetzner/server.py:199-202 (schema)Pydantic BaseModel schema defining the input parameters for the update_firewall tool.class UpdateFirewallParams(BaseModel): firewall_id: int = Field(..., description="The ID of the firewall") name: Optional[str] = Field(None, description="New name for the firewall") labels: Optional[Dict[str, str]] = Field(None, description="User-defined labels (key-value pairs)")
- mcp_hetzner/server.py:113-158 (helper)Helper function used by the update_firewall tool (and others) to serialize a Firewall object into a dictionary format for the response.def firewall_to_dict(firewall: Firewall) -> Dict[str, Any]: """Convert a Firewall object to a dictionary with relevant information.""" # Convert rules to dict rules = [] if firewall.rules: for rule in firewall.rules: rule_dict = { "direction": rule.direction, "protocol": rule.protocol, "source_ips": rule.source_ips, } if rule.port: rule_dict["port"] = rule.port if rule.destination_ips: rule_dict["destination_ips"] = rule.destination_ips if rule.description: rule_dict["description"] = rule.description rules.append(rule_dict) # Convert applied_to resources to dict applied_to = [] if firewall.applied_to: for resource in firewall.applied_to: resource_dict = {"type": resource.type} if resource.server: resource_dict["server"] = {"id": resource.server.id, "name": resource.server.name} if resource.label_selector: resource_dict["label_selector"] = {"selector": resource.label_selector.selector} if getattr(resource, 'applied_to_resources', None): applied_resources = [] for applied_resource in resource.applied_to_resources: applied_resource_dict = {"type": applied_resource.type} if applied_resource.server: applied_resource_dict["server"] = {"id": applied_resource.server.id, "name": applied_resource.server.name} applied_resources.append(applied_resource_dict) resource_dict["applied_to_resources"] = applied_resources applied_to.append(resource_dict) return { "id": firewall.id, "name": firewall.name, "rules": rules, "applied_to": applied_to, "labels": firewall.labels, "created": firewall.created.isoformat() if firewall.created else None, }