Skip to main content
Glama

create_namespace

Create a new namespace in Kubernetes clusters with 'k8s-pilot'. Specify the context, namespace name, and optional labels to manage resources efficiently.

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
labelsNo
namespaceYes

Implementation Reference

  • The MCP tool handler for create_namespace, decorated with @mcp.tool(). It checks if the namespace exists, creates it using Kubernetes API with optional labels, 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)}"})
  • The @mcp.tool() decorator registers the create_namespace function as an MCP tool.
    @mcp.tool()

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