Skip to main content
Glama

create_namespace

Create a new namespace in Kubernetes clusters managed by k8s-pilot, specifying context, name, and optional labels for organization.

Instructions

Create a new namespace.

Args: context_name: The Kubernetes context name namespace: The name for the new namespace labels: Optional dictionary of labels to apply to the namespace

Returns: JSON string containing information about the created namespace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes
labelsNo

Implementation Reference

  • Handler function for the 'create_namespace' tool, including @mcp.tool() decorator which serves as registration. Creates a new Kubernetes namespace with optional labels, checks for existence, and returns JSON result.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def create_namespace(context_name: str, namespace: str, labels: Optional[Dict[str, str]] = None):
        """
        Create a new namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The name for the new namespace
            labels: Optional dictionary of labels to apply to the namespace
    
        Returns:
            JSON string containing information about the created namespace
        """
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
    
        try:
            # Check if namespace already exists
            try:
                core_v1.read_namespace(namespace)
                return json.dumps({"error": f"Namespace '{namespace}' already exists"})
            except ApiException as e:
                if e.status != 404:
                    return json.dumps({"error": f"API error: {str(e)}"})
                # 404 means namespace doesn't exist, so we can proceed
    
            # Create namespace object
            ns_metadata = V1ObjectMeta(name=namespace, labels=labels)
            ns_body = V1Namespace(metadata=ns_metadata)
    
            # Create the namespace
            created_ns = core_v1.create_namespace(body=ns_body)
    
            result = {
                "name": created_ns.metadata.name,
                "status": created_ns.status.phase,
                "labels": created_ns.metadata.labels if created_ns.metadata.labels else {},
                "message": f"Namespace '{namespace}' created successfully"
            }
    
            return json.dumps(result)
        except ApiException as e:
            return json.dumps({"error": f"Failed to create namespace: {str(e)}"})
  • Registration of the create_namespace tool via @mcp.tool() decorator.
    @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 this is a creation operation but doesn't mention permissions required, whether it's idempotent, what happens on conflict, or any rate limits. The return format is vaguely described as 'JSON string containing information' without specifying structure. This is inadequate for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is perfectly structured and concise. It opens with a clear purpose statement, then provides organized parameter documentation in an Args section, followed by return information. Every sentence earns its place with no wasted words, and the information is front-loaded effectively.

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

Completeness2/5

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

For a Kubernetes namespace creation tool with 3 parameters, no annotations, and no output schema, the description is incomplete. It covers parameters adequately but lacks critical behavioral context about permissions, idempotency, error conditions, and the structure of return values. The agent would struggle to use this tool correctly without additional documentation or trial-and-error.

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 compensates well by explaining all three parameters in the Args section. It clarifies that 'context_name' is the Kubernetes context, 'namespace' is the name for the new namespace, and 'labels' are optional key-value pairs. This adds significant value beyond the bare schema, though it doesn't provide format examples or 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 verb ('Create') and resource ('a new namespace'), making the purpose immediately understandable. It distinguishes from siblings like 'delete_namespace' and 'list_namespaces' by specifying creation rather than deletion or listing. However, it doesn't explicitly differentiate from other creation tools like 'configmap_create' or 'deployment_create' beyond the resource type.

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., cluster access), when not to use it (e.g., if namespace already exists), or how it relates to sibling tools like 'add_namespace_label' or 'set_namespace_resource_quota'. The agent must infer usage from the tool name alone.

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