Skip to main content
Glama
dkruyt

Hetzner Cloud MCP Server

by dkruyt

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
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • 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)}"}
  • 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)")
  • 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,
        }

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