Skip to main content
Glama

remove_namespace_label

Remove a specific label from a Kubernetes namespace by providing the context name, namespace, and label key. Returns updated namespace labels in JSON format, simplifying label management in multi-cluster environments.

Instructions

Remove a label from a namespace.

Args: context_name: The Kubernetes context name namespace: The name of the namespace label_key: The label key to remove

Returns: JSON string containing the updated namespace labels

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
label_keyYes
namespaceYes

Implementation Reference

  • The core handler function for the 'remove_namespace_label' MCP tool. It is decorated with @mcp.tool() which registers it, @use_current_context for context management, and @check_readonly_permission for access control. The function reads the namespace, removes the specified label if present, patches the namespace via Kubernetes API, and returns JSON with updated labels or error.
    @mcp.tool() @use_current_context @check_readonly_permission def remove_namespace_label(context_name: str, namespace: str, label_key: str): """ Remove a label from a namespace. Args: context_name: The Kubernetes context name namespace: The name of the namespace label_key: The label key to remove Returns: JSON string containing the updated namespace labels """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] try: # Get the current namespace ns = core_v1.read_namespace(namespace) # Check if the namespace has labels if not ns.metadata.labels or label_key not in ns.metadata.labels: result = { "name": namespace, "labels": ns.metadata.labels, "message": f"Label '{label_key}' not found on namespace" } return json.dumps(result) # Update the labels labels = dict(ns.metadata.labels) del labels[label_key] # Apply the patch body = { "metadata": { "labels": labels } } patched_ns = core_v1.patch_namespace(namespace, body) result = { "name": patched_ns.metadata.name, "labels": patched_ns.metadata.labels } return json.dumps(result) except ApiException as e: if e.status == 404: return json.dumps({"error": f"Namespace '{namespace}' not found"}) else: return json.dumps({"error": f"Failed to remove label: {str(e)}"})

Other Tools

Related Tools

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