add_node_label
Add or update labels on Kubernetes nodes using the specified context, node name, label key, and value, returning updated node labels in JSON format.
Instructions
Add or update a label to a node.
Args: context_name: The Kubernetes context name node_name: The name of the node to modify label_key: The label key to add label_value: The label value to set
Returns: JSON string containing the updated node labels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| label_key | Yes | ||
| label_value | Yes | ||
| node_name | Yes |
Implementation Reference
- tools/node.py:96-138 (handler)The handler function for the 'add_node_label' MCP tool. It reads the current node, updates or adds the specified label, patches the node via Kubernetes API, and returns the updated labels as JSON. Registered via @mcp.tool() decorator.@mcp.tool() @use_current_context def add_node_label(context_name: str, node_name: str, label_key: str, label_value: str): """ Add or update a label to a node. Args: context_name: The Kubernetes context name node_name: The name of the node to modify label_key: The label key to add label_value: The label value to set 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) # Prepare the patch if not node.metadata.labels: node.metadata.labels = {} # Update the labels labels = dict(node.metadata.labels) labels[label_key] = label_value # 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)
- tools/node.py:96-96 (registration)The @mcp.tool() decorator registers this function as an MCP tool named 'add_node_label'.@mcp.tool()