get_namespaces
Retrieve all namespaces within a Kubernetes cluster using the MCP Kubernetes Server, simplifying Kubernetes management through structured API interactions.
Instructions
Get all namespaces in the cluster
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:56-56 (registration)The @mcp.tool() decorator registers the get_namespaces function as an MCP tool.@mcp.tool()
- kubernetes.py:57-64 (handler)The handler function implements the tool logic by executing 'kubectl get namespaces -o json' via subprocess, parsing the JSON output, and returning it or an error dictionary.async def get_namespaces() -> dict: """Get all namespaces in the cluster""" try: cmd = ["kubectl", "get", "namespaces", "-o", "json"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return json.loads(result.stdout) except subprocess.CalledProcessError as e: return {"error": f"Failed to get namespaces: {str(e)}"}