create_ssh_key
Generate SSH keys for Hetzner Cloud server authentication. Add a name and public key to create secure access credentials.
Instructions
Create a new SSH key.
Creates a new SSH key with the specified name and public key data.
Examples:
- Basic SSH key: {"name": "my-ssh-key", "public_key": "ssh-rsa AAAAB3NzaC1..."}
- With labels: {"name": "user-key", "public_key": "ssh-rsa AAAAB3NzaC1...", "labels": {"environment": "production"}}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- mcp_hetzner/server.py:1239-1259 (handler)The handler function decorated with @mcp.tool() that implements the create_ssh_key tool. It uses the Hetzner client to create an SSH key with the given name, public_key, and optional labels, then serializes and returns it or an error.@mcp.tool() def create_ssh_key(params: CreateSSHKeyParams) -> Dict[str, Any]: """ Create a new SSH key. Creates a new SSH key with the specified name and public key data. Examples: - Basic SSH key: {"name": "my-ssh-key", "public_key": "ssh-rsa AAAAB3NzaC1..."} - With labels: {"name": "user-key", "public_key": "ssh-rsa AAAAB3NzaC1...", "labels": {"environment": "production"}} """ try: ssh_key = client.ssh_keys.create( name=params.name, public_key=params.public_key, labels=params.labels ) return {"ssh_key": ssh_key_to_dict(ssh_key)} except Exception as e: return {"error": f"Failed to create SSH key: {str(e)}"}
- mcp_hetzner/server.py:244-247 (schema)Pydantic model defining the input parameters for the create_ssh_key tool.class CreateSSHKeyParams(BaseModel): name: str = Field(..., description="Name of the SSH key") public_key: str = Field(..., description="The public key in OpenSSH format") labels: Optional[Dict[str, str]] = Field(None, description="User-defined labels (key-value pairs)")
- mcp_hetzner/server.py:101-110 (helper)Helper function used by create_ssh_key (and other SSH tools) to convert Hetzner SSHKey object to a serializable dictionary.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, }