Skip to main content
Glama

list_gke_clusters

List all Google Kubernetes Engine (GKE) clusters within a specified GCP project, optionally filtered by region. Simplify cluster management and visibility for better resource tracking in GCP environments.

Instructions

    List Google Kubernetes Engine (GKE) clusters in a GCP project.
    
    Args:
        project_id: The ID of the GCP project to list GKE clusters for
        region: Optional region to filter clusters (e.g., "us-central1")
    
    Returns:
        List of GKE clusters in the specified GCP project
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
regionNo

Implementation Reference

  • The handler function for the 'list_gke_clusters' tool. It uses the Google Cloud Container API to list GKE clusters in the specified project, optionally filtered by region. Handles both regional and zonal clusters, formatting output with details like version, node count, and status.
        @mcp.tool()
        def list_gke_clusters(project_id: str, region: str = "") -> str:
            """
            List Google Kubernetes Engine (GKE) clusters in a GCP project.
            
            Args:
                project_id: The ID of the GCP project to list GKE clusters for
                region: Optional region to filter clusters (e.g., "us-central1")
            
            Returns:
                List of GKE clusters in the specified GCP project
            """
            try:
                from google.cloud import container_v1
                
                # Initialize the GKE client
                client = container_v1.ClusterManagerClient()
                
                clusters_list = []
                
                if region:
                    # List clusters in the specified region
                    parent = f"projects/{project_id}/locations/{region}"
                    response = client.list_clusters(parent=parent)
                    
                    for cluster in response.clusters:
                        version = cluster.current_master_version
                        node_count = sum(pool.initial_node_count for pool in cluster.node_pools)
                        status = "Running" if cluster.status == container_v1.Cluster.Status.RUNNING else cluster.status.name
                        clusters_list.append(f"- {cluster.name} (Region: {region}, Version: {version}, Nodes: {node_count}, Status: {status})")
                else:
                    # List clusters in all regions
                    from google.cloud import compute_v1
                    
                    # Get all regions
                    regions_client = compute_v1.RegionsClient()
                    regions_request = compute_v1.ListRegionsRequest(project=project_id)
                    regions = regions_client.list(request=regions_request)
                    
                    for region_item in regions:
                        region_name = region_item.name
                        parent = f"projects/{project_id}/locations/{region_name}"
                        try:
                            response = client.list_clusters(parent=parent)
                            
                            for cluster in response.clusters:
                                version = cluster.current_master_version
                                node_count = sum(pool.initial_node_count for pool in cluster.node_pools)
                                status = "Running" if cluster.status == container_v1.Cluster.Status.RUNNING else cluster.status.name
                                clusters_list.append(f"- {cluster.name} (Region: {region_name}, Version: {version}, Nodes: {node_count}, Status: {status})")
                        except Exception:
                            # Skip regions where we can't list clusters
                            continue
                        
                    # Also check zonal clusters
                    zones_client = compute_v1.ZonesClient()
                    zones_request = compute_v1.ListZonesRequest(project=project_id)
                    zones = zones_client.list(request=zones_request)
                    
                    for zone_item in zones:
                        zone_name = zone_item.name
                        parent = f"projects/{project_id}/locations/{zone_name}"
                        try:
                            response = client.list_clusters(parent=parent)
                            
                            for cluster in response.clusters:
                                version = cluster.current_master_version
                                node_count = sum(pool.initial_node_count for pool in cluster.node_pools)
                                status = "Running" if cluster.status == container_v1.Cluster.Status.RUNNING else cluster.status.name
                                clusters_list.append(f"- {cluster.name} (Zone: {zone_name}, Version: {version}, Nodes: {node_count}, Status: {status})")
                        except Exception:
                            # Skip zones where we can't list clusters
                            continue
                
                if not clusters_list:
                    region_msg = f" in region {region}" if region else ""
                    return f"No GKE clusters found{region_msg} for project {project_id}."
                
                clusters_str = "\n".join(clusters_list)
                region_msg = f" in region {region}" if region else ""
                
                return f"""
    Google Kubernetes Engine (GKE) Clusters{region_msg} in GCP Project {project_id}:
    {clusters_str}
    """
            except Exception as e:
                return f"Error listing GKE clusters: {str(e)}"
  • Registration of the Kubernetes tools module in the main MCP server, which includes the 'list_gke_clusters' tool via the call to kubernetes_tools.register_tools(mcp). This is invoked during server initialization.
    kubernetes_tools.register_tools(mcp)
  • The register_tools function in the Kubernetes module that defines and registers the 'list_gke_clusters' tool using the @mcp.tool() decorator.
    def register_tools(mcp):
        """Register all kubernetes tools with the MCP server."""

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the burden of behavioral disclosure. It mentions listing clusters but does not explicitly state this is a read-only operation, nor does it mention pagination or any other behavior. For a simple list tool, it is adequate but not rich.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with a one-sentence summary followed by Args and Returns sections. No fluff, and the essential information is front-loaded. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity, the description is mostly complete: it states the purpose, parameters, and return type. However, it does not detail the structure of the returned cluster objects or mention pagination, which could be useful if the list is large. This is a minor gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has no descriptions (0% coverage), so the Args section adds meaningful context: project_id is defined as the GCP project ID, and region is described as optional with a concrete example ('us-central1'). This compensates for the schema gap, though it does not specify the exact format of project_id.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (List), resource (Google Kubernetes Engine (GKE) clusters), and scope (GCP project). This distinguishes it from sibling tools like list_compute_instances or list_node_pools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides context by explaining the project_id and optional region filter, but it does not explicitly state when to use this tool versus alternatives like get_cluster_details or list_node_pools. Usage is implied but not directly contrasted with siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.