get_node_pods
Retrieve all pods running on a specific Kubernetes node by providing the context and node name. Outputs a JSON string with the pod details for efficient cluster management.
Instructions
Get all pods running on a specific node.
Args: context_name: The Kubernetes context name node_name: The name of the node to get pods for
Returns: JSON string containing the pods running on the node
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| node_name | Yes |
Implementation Reference
- tools/node.py:445-478 (handler)The handler function for the 'get_node_pods' tool, decorated with @mcp.tool() for registration. It fetches all pods running on the specified node across all namespaces using the Kubernetes CoreV1Api and returns a JSON object with pod details including name, namespace, status, containers, count.@mcp.tool() @use_current_context def get_node_pods(context_name: str, node_name: str): """ Get all pods running on a specific node. Args: context_name: The Kubernetes context name node_name: The name of the node to get pods for Returns: JSON string containing the pods running on the node """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] # Get all pods in all namespaces pods = core_v1.list_pod_for_all_namespaces(field_selector=f"spec.nodeName={node_name}") pod_list = [ { "name": pod.metadata.name, "namespace": pod.metadata.namespace, "status": pod.status.phase, "containers": [c.name for c in pod.spec.containers] } for pod in pods.items ] result = { "node": node_name, "pods": pod_list, "pod_count": len(pod_list) } return json.dumps(result)
- tools/node.py:445-445 (registration)The @mcp.tool() decorator registers the get_node_pods function as an MCP tool.@mcp.tool()
- tools/node.py:447-456 (schema)The function signature and docstring define the input schema (context_name: str, node_name: str) and output (JSON string with pods).def get_node_pods(context_name: str, node_name: str): """ Get all pods running on a specific node. Args: context_name: The Kubernetes context name node_name: The name of the node to get pods for Returns: JSON string containing the pods running on the node