get_namespaces
Retrieve all namespaces in a Kubernetes cluster to manage resources and organize workloads effectively.
Instructions
Get all namespaces in the cluster
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_namespaces"
}
}Input 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)}"}