get_namespaces
Retrieve all namespaces in a Kubernetes cluster to manage resources and organize workloads effectively.
Instructions
Get all namespaces in the cluster
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:56-64 (handler)The tool handler function for 'get_namespaces'. It uses kubectl to fetch all namespaces in JSON format and returns the parsed JSON or an error dictionary.@mcp.tool() 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)}"}