get_nodes
Retrieve all nodes in a Kubernetes cluster with a simple command, enabling efficient cluster management through the MCP Kubernetes Server.
Instructions
Get all nodes in the cluster
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:66-74 (handler)Primary handler implementation for the 'get_nodes' tool. Retrieves all nodes in the Kubernetes cluster without namespace restriction using kubectl get nodes -o json.@mcp.tool() async def get_nodes() -> dict: """Get all nodes in the cluster""" try: cmd = ["kubectl", "get", "nodes", "-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 nodes: {str(e)}"}
- kubernetes.py:180-188 (handler)Secondary handler implementation for the 'get_nodes' tool with optional namespace parameter. Note: Nodes are cluster-scoped, so namespace flag may not filter as expected.@mcp.tool() async def get_nodes(namespace: str = "default") -> dict: """Get the nodes of a specific namespace""" try: cmd = ["kubectl", "get", "nodes", "-n", namespace, "-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 nodes: {str(e)}"}
- kubernetes.py:66-74 (registration)Registration of the get_nodes tool via @mcp.tool() decorator.@mcp.tool() async def get_nodes() -> dict: """Get all nodes in the cluster""" try: cmd = ["kubectl", "get", "nodes", "-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 nodes: {str(e)}"}
- kubernetes.py:180-188 (registration)Registration of the overloaded get_nodes tool via @mcp.tool() decorator.@mcp.tool() async def get_nodes(namespace: str = "default") -> dict: """Get the nodes of a specific namespace""" try: cmd = ["kubectl", "get", "nodes", "-n", namespace, "-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 nodes: {str(e)}"}