Skip to main content
Glama

set_namespace_resource_quota

Configure resource limits for Kubernetes namespaces to control CPU, memory, and pod usage across clusters.

Instructions

Set or update resource quotas for a namespace.

Args: context_name: The Kubernetes context name namespace: The name of the namespace cpu_limit: Optional CPU limit (e.g., "2", "500m") memory_limit: Optional memory limit (e.g., "1Gi", "500Mi") pod_count: Optional maximum number of pods

Returns: JSON string containing the resource quota status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes
cpu_limitNo
memory_limitNo
pod_countNo

Implementation Reference

  • The handler function for the 'set_namespace_resource_quota' tool. It creates or updates a ResourceQuota object in the specified namespace with the given CPU, memory, and pod limits using the Kubernetes CoreV1Api. The @mcp.tool() decorator registers it as an MCP tool.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def set_namespace_resource_quota(context_name: str, namespace: str,
                                     cpu_limit: Optional[str] = None,
                                     memory_limit: Optional[str] = None,
                                     pod_count: Optional[int] = None):
        """
        Set or update resource quotas for a namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The name of the namespace
            cpu_limit: Optional CPU limit (e.g., "2", "500m")
            memory_limit: Optional memory limit (e.g., "1Gi", "500Mi")
            pod_count: Optional maximum number of pods
    
        Returns:
            JSON string containing the resource quota status
        """
        from kubernetes.client.models.v1_resource_quota import V1ResourceQuota
        from kubernetes.client.models.v1_resource_quota_spec import V1ResourceQuotaSpec
    
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
    
        try:
            # Check if namespace exists
            try:
                core_v1.read_namespace(namespace)
            except ApiException as e:
                if e.status == 404:
                    return json.dumps({"error": f"Namespace '{namespace}' not found"})
                else:
                    return json.dumps({"error": f"API error: {str(e)}"})
    
            # If no limits are provided, return error
            if not any([cpu_limit, memory_limit, pod_count]):
                return json.dumps({"error": "At least one resource limit must be specified"})
    
            # Prepare the resource quota
            quota_name = f"{namespace}-resource-quota"
            hard_quotas = {}
    
            if cpu_limit:
                hard_quotas["limits.cpu"] = cpu_limit
    
            if memory_limit:
                hard_quotas["limits.memory"] = memory_limit
    
            if pod_count:
                hard_quotas["pods"] = str(pod_count)
    
            # Check if quota already exists
            try:
                existing_quota = core_v1.read_namespaced_resource_quota(quota_name, namespace)
                # Update existing quota
                body = {
                    "spec": {
                        "hard": hard_quotas
                    }
                }
                updated_quota = core_v1.patch_namespaced_resource_quota(quota_name, namespace, body)
    
                result = {
                    "name": updated_quota.metadata.name,
                    "namespace": namespace,
                    "quotas": updated_quota.spec.hard,
                    "message": "Resource quota updated successfully"
                }
            except ApiException as e:
                if e.status == 404:
                    # Create new quota
                    quota_spec = V1ResourceQuotaSpec(hard=hard_quotas)
                    quota_metadata = V1ObjectMeta(name=quota_name)
                    quota_body = V1ResourceQuota(metadata=quota_metadata, spec=quota_spec)
    
                    created_quota = core_v1.create_namespaced_resource_quota(namespace, quota_body)
    
                    result = {
                        "name": created_quota.metadata.name,
                        "namespace": namespace,
                        "quotas": created_quota.spec.hard,
                        "message": "Resource quota created successfully"
                    }
                else:
                    return json.dumps({"error": f"API error: {str(e)}"})
    
            return json.dumps(result)
        except ApiException as e:
            return json.dumps({"error": f"Failed to set resource quota: {str(e)}"})
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Set or update' implies a mutation operation, the description doesn't specify whether this requires specific permissions, if it's idempotent, what happens on partial updates, or any rate limits. It mentions the return format ('JSON string containing the resource quota status'), but lacks details on error conditions or side effects.

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 and appropriately sized. It starts with a clear purpose statement, then lists parameters with helpful examples, and ends with return information. Every sentence adds value, though the formatting with 'Args:' and 'Returns:' sections is slightly verbose but still efficient.

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 the complexity (a mutation tool with 5 parameters, no annotations, and no output schema), the description is moderately complete. It covers the purpose and parameters well but lacks behavioral context (permissions, idempotency, errors) and detailed output explanation. For a tool that modifies system resources, this leaves important gaps unaddressed.

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?

The description provides meaningful semantics for all 5 parameters beyond the schema (which has 0% description coverage). It explains each parameter's purpose with examples (e.g., 'cpu_limit: Optional CPU limit (e.g., "2", "500m")'), which is crucial since the schema only provides titles. This compensates well for the poor schema coverage, though it could be slightly more detailed about constraints.

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 tool's purpose: 'Set or update resource quotas for a namespace.' This is a specific verb ('Set or update') with a clear resource ('resource quotas for a namespace'). However, it doesn't explicitly differentiate from sibling tools like 'get_namespace_resource_quota' or other quota-related operations, which would be needed for 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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing admin permissions), when to choose this over other quota tools, or any constraints. With many sibling tools available, this lack of contextual guidance is a significant gap.

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