update_ssh_key
Modify the name or labels of an existing SSH key in Hetzner Cloud to maintain organized access management.
Instructions
Update an SSH key.
Updates the name or labels of an existing SSH key.
Example:
- Update name: {"ssh_key_id": 12345, "name": "new-key-name"}
- Update labels: {"ssh_key_id": 12345, "name": "existing-name", "labels": {"environment": "staging"}}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- mcp_hetzner/server.py:1261-1286 (handler)The handler function implementing the 'update_ssh_key' MCP tool. It retrieves the SSH key by ID, updates its name and/or labels using the Hetzner Cloud client, and returns the updated key details or an error.@mcp.tool() def update_ssh_key(params: UpdateSSHKeyParams) -> Dict[str, Any]: """ Update an SSH key. Updates the name or labels of an existing SSH key. Example: - Update name: {"ssh_key_id": 12345, "name": "new-key-name"} - Update labels: {"ssh_key_id": 12345, "name": "existing-name", "labels": {"environment": "staging"}} """ try: ssh_key = client.ssh_keys.get_by_id(params.ssh_key_id) if not ssh_key: return {"error": f"SSH key with ID {params.ssh_key_id} not found"} updated_ssh_key = client.ssh_keys.update( ssh_key=ssh_key, name=params.name, labels=params.labels ) return {"ssh_key": ssh_key_to_dict(updated_ssh_key)} except Exception as e: return {"error": f"Failed to update SSH key: {str(e)}"}
- mcp_hetzner/server.py:250-253 (schema)Pydantic model defining the input parameters (schema) for the update_ssh_key tool.class UpdateSSHKeyParams(BaseModel): ssh_key_id: int = Field(..., description="The ID of the SSH key") name: str = Field(..., description="New name for the SSH key") labels: Optional[Dict[str, str]] = Field(None, description="User-defined labels (key-value pairs)")
- mcp_hetzner/server.py:101-110 (helper)Helper function to serialize SSHKey domain objects to dictionaries, used in the response of the update_ssh_key tool.def ssh_key_to_dict(ssh_key: SSHKey) -> Dict[str, Any]: """Convert an SSHKey object to a dictionary with relevant information.""" return { "id": ssh_key.id, "name": ssh_key.name, "fingerprint": ssh_key.fingerprint, "public_key": ssh_key.public_key, "labels": ssh_key.labels, "created": ssh_key.created.isoformat() if ssh_key.created else None, }