Skip to main content
Glama

remove_node_label

Remove specific labels from Kubernetes nodes to manage resource organization and configuration across clusters. Specify context, node name, and label key for targeted label removal.

Instructions

Remove a label from a node.

Args: context_name: The Kubernetes context name node_name: The name of the node to modify label_key: The label key to remove

Returns: JSON string containing the updated node labels

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
node_nameYes
label_keyYes

Implementation Reference

  • The handler function for the 'remove_node_label' tool. It removes the specified label from the given Kubernetes node by patching the node's metadata.labels using the Kubernetes CoreV1 API. Includes decorators for registration (@mcp.tool()) and context (@use_current_context). Returns JSON with updated labels or a message if label not found.
    @mcp.tool()
    @use_current_context
    def remove_node_label(context_name: str, node_name: str, label_key: str):
        """
        Remove a label from a node.
    
        Args:
            context_name: The Kubernetes context name
            node_name: The name of the node to modify
            label_key: The label key to remove
    
        Returns:
            JSON string containing the updated node labels
        """
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
    
        # Get the current node
        node = core_v1.read_node(node_name)
    
        # Check if the node has labels
        if not node.metadata.labels or label_key not in node.metadata.labels:
            result = {
                "name": node_name,
                "labels": node.metadata.labels,
                "message": f"Label '{label_key}' not found on node"
            }
            return json.dumps(result)
    
        # Update the labels
        labels = dict(node.metadata.labels)
        del labels[label_key]
    
        # Apply the patch
        body = {
            "metadata": {
                "labels": labels
            }
        }
    
        patched_node = core_v1.patch_node(node_name, body)
    
        result = {
            "name": patched_node.metadata.name,
            "labels": patched_node.metadata.labels
        }
    
        return json.dumps(result)

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/bourbonkk/k8s-pilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server