Skip to main content
Glama

add_namespace_label

Add or update labels on Kubernetes namespaces to organize and manage cluster resources using the k8s-pilot server.

Instructions

Add or update a label on a namespace.

Args: context_name: The Kubernetes context name namespace: The name of the namespace label_key: The label key to add label_value: The label value to set

Returns: JSON string containing the updated namespace labels

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes
label_keyYes
label_valueYes

Implementation Reference

  • The @mcp.tool()-decorated handler function that implements adding or updating a label on a Kubernetes namespace by patching its metadata.labels using the CoreV1Api.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def add_namespace_label(context_name: str, namespace: str, label_key: str, label_value: str):
        """
        Add or update a label on a namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The name of the namespace
            label_key: The label key to add
            label_value: The label value to set
    
        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)
    
            # Prepare the patch
            if not ns.metadata.labels:
                ns.metadata.labels = {}
    
            # Update the labels
            labels = dict(ns.metadata.labels)
            labels[label_key] = label_value
    
            # 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 add label: {str(e)}"})
  • The @mcp.tool() decorator registers the add_namespace_label function as an MCP tool.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Add or update a label') and return format ('JSON string containing the updated namespace labels'), but lacks critical information about whether this is a mutation requiring specific permissions, if it overwrites existing labels, error conditions, or rate limits. For a Kubernetes mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement followed by parameter and return sections. It's appropriately sized with no redundant information, though the 'Args:' and 'Returns:' formatting could be slightly more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with no annotations and no output schema, the description provides basic purpose and parameter information but lacks important context about permissions, side effects, error handling, and how it differs from similar tools. The return format is mentioned but without schema details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description provides meaningful parameter documentation through the Args section, explaining all 4 parameters clearly. It adds substantial value beyond the bare schema, though it doesn't specify format constraints (e.g., valid label key patterns) or provide examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add or update a label') and the target resource ('on a namespace'), providing specific verb+resource information. However, it doesn't explicitly differentiate from sibling tools like 'remove_namespace_label' or 'add_node_label' beyond the obvious resource difference, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives like 'remove_namespace_label' or 'configmap_update' for similar operations. The description lacks context about prerequisites, permissions needed, or typical use cases for namespace labeling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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