Skip to main content
Glama

get_clusters

Retrieve all Kubernetes clusters from your kubeconfig file to manage multiple cluster configurations and switch contexts efficiently.

Instructions

Get all clusters from the kubeconfig file. :return:

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'get_clusters' tool. It is decorated with @mcp.tool() which also serves as its registration in the MCP system. Parses kubeconfig to return list of available clusters as ContextInfo objects.
    @mcp.tool()
    def get_clusters():
        """
        Get all clusters from the kubeconfig file.
        :return:
        """
        config_data = get_kubeconfig()
        current_context = config_data.get("current-context")
        contexts = config_data.get("contexts", [])
    
        return [
            ContextInfo(
                name=ctx["name"],
                cluster=ctx["context"].get("cluster"),
                user=ctx["context"].get("user"),
                current=ctx["name"] == current_context,
            )
            for ctx in contexts]
  • Dataclass schema/model defining the structure of cluster context information returned by the get_clusters tool.
    @dataclass
    class ContextInfo:
        """
        Represents a Kubernetes context.
        """
        name: str
        cluster: str
        user: str
        current: bool
  • tools/cluster.py:10-10 (registration)
    The @mcp.tool() decorator registers the get_clusters function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bourbonkk/k8s-pilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server