Skip to main content
Glama
dkruyt

Hetzner Cloud MCP Server

by dkruyt

get_ssh_key

Retrieve details for a specific SSH key by its ID to manage access to Hetzner Cloud resources.

Instructions

Get details about a specific SSH key.

Returns detailed information about an SSH key identified by its ID.

Example:
- Get SSH key details: {"ssh_key_id": 12345}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The handler function for the 'get_ssh_key' tool. It retrieves an SSH key by ID from the Hetzner Cloud API using the client, converts it to a dictionary using ssh_key_to_dict, and returns it or an error.
    @mcp.tool()
    def get_ssh_key(params: SSHKeyIdParam) -> Dict[str, Any]:
        """
        Get details about a specific SSH key.
        
        Returns detailed information about an SSH key identified by its ID.
        
        Example:
        - Get SSH key details: {"ssh_key_id": 12345}
        """
        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"}
            
            return {"ssh_key": ssh_key_to_dict(ssh_key)}
        except Exception as e:
            return {"error": f"Failed to get SSH key: {str(e)}"}
  • Pydantic model defining the input schema for the get_ssh_key tool, requiring the SSH key ID.
    class SSHKeyIdParam(BaseModel):
        ssh_key_id: int = Field(..., description="The ID of the SSH key")
  • Helper function that converts a Hetzner Cloud SSHKey object to a serializable dictionary format, used in get_ssh_key and list_ssh_keys tools.
    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,
        }
  • The @mcp.tool() decorator registers the get_ssh_key function as an MCP tool with the name 'get_ssh_key'.
    @mcp.tool()

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