list_namespaces
Retrieve and display all namespaces in a Kubernetes cluster using the specified context, returning detailed information in JSON format for streamlined management and monitoring.
Instructions
List all namespaces in the Kubernetes cluster.
Args: context_name: The Kubernetes context name
Returns: JSON string containing basic information about all namespaces
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes |
Implementation Reference
- tools/namespace.py:13-28 (handler)The handler function decorated with @mcp.tool() that lists all Kubernetes namespaces in the specified context and returns a JSON array of namespace names.@mcp.tool() @use_current_context def list_namespaces(context_name: str): """ List all namespaces in the Kubernetes cluster. Args: context_name: The Kubernetes context name Returns: JSON string containing basic information about all namespaces """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] namespaces = core_v1.list_namespace() result = [{"name": ns.metadata.name} for ns in namespaces.items] return json.dumps(result)
- tools/namespace.py:13-13 (registration)The @mcp.tool() decorator registers the list_namespaces function as an MCP tool.@mcp.tool()