list_node_pools
Retrieve a list of node pools in a specified GKE cluster by providing the GCP project ID, cluster name, and location. Simplify cluster management within the GCP MCP system.
Instructions
List node pools in a GKE cluster.
Args:
project_id: The ID of the GCP project
cluster_name: The name of the GKE cluster
location: The location (region or zone) of the cluster
Returns:
List of node pools in the specified GKE cluster
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cluster_name | Yes | ||
| location | Yes | ||
| project_id | Yes |
Implementation Reference
- The handler function for the 'list_node_pools' MCP tool. It is decorated with @mcp.tool() which also serves as registration. The function uses the Google Cloud Container client to list node pools in a GKE cluster, formats the information including machine types, autoscaling settings, and labels, and returns a formatted string.@mcp.tool() def list_node_pools(project_id: str, cluster_name: str, location: str) -> str: """ List node pools in a GKE cluster. Args: project_id: The ID of the GCP project cluster_name: The name of the GKE cluster location: The location (region or zone) of the cluster Returns: List of node pools in the specified GKE cluster """ try: from google.cloud import container_v1 # Initialize the GKE client client = container_v1.ClusterManagerClient() # List node pools cluster_path = f"projects/{project_id}/locations/{location}/clusters/{cluster_name}" node_pools = client.list_node_pools(parent=cluster_path) # Format the response pools_list = [] for pool in node_pools.node_pools: machine_type = pool.config.machine_type disk_size_gb = pool.config.disk_size_gb autoscaling = "Enabled" if pool.autoscaling and pool.autoscaling.enabled else "Disabled" min_nodes = pool.autoscaling.min_node_count if pool.autoscaling and pool.autoscaling.enabled else "N/A" max_nodes = pool.autoscaling.max_node_count if pool.autoscaling and pool.autoscaling.enabled else "N/A" initial_nodes = pool.initial_node_count pool_info = [ f"- {pool.name}:", f" Machine Type: {machine_type}", f" Disk Size: {disk_size_gb}GB", f" Initial Node Count: {initial_nodes}", f" Autoscaling: {autoscaling}" ] if autoscaling == "Enabled": pool_info.append(f" Min Nodes: {min_nodes}") pool_info.append(f" Max Nodes: {max_nodes}") if pool.config.labels: labels = [f"{k}: {v}" for k, v in pool.config.labels.items()] pool_info.append(f" Labels: {', '.join(labels)}") pools_list.append("\n".join(pool_info)) if not pools_list: return f"No node pools found in GKE cluster {cluster_name} in location {location}." pools_str = "\n".join(pools_list) return f""" Node Pools in GKE Cluster {cluster_name} (Location: {location}): {pools_str} """ except Exception as e: return f"Error listing node pools: {str(e)}"
- src/gcp_mcp/gcp_modules/kubernetes/tools.py:6-7 (registration)The register_tools function that defines and registers all Kubernetes tools, including list_node_pools, by nesting the tool definitions inside it with @mcp.tool() decorators.def register_tools(mcp): """Register all kubernetes tools with the MCP server."""