Skip to main content
Glama

get_current_cluster

Retrieve the currently active Kubernetes cluster from your kubeconfig file to verify or switch cluster contexts for managing resources.

Instructions

Get the current cluster from the kubeconfig file. :return:

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_current_cluster' tool, decorated with @mcp.tool() to register it. It loads the kubeconfig, finds the current context, and returns the corresponding ContextInfo.
    @mcp.tool()
    def get_current_cluster():
        """
        Get the current cluster from the kubeconfig file.
        :return:
        """
        config_data = get_kubeconfig()
        current_context = config_data.get("current-context")
        contexts = config_data.get("contexts", [])
    
        for ctx in contexts:
            if ctx["name"] == current_context:
                return ContextInfo(
                    name=ctx["name"],
                    cluster=ctx["context"].get("cluster"),
                    user=ctx["context"].get("user"),
                    current=True,
                )
        return None
  • server/server.py:9-9 (registration)
    Import statement in load_modules() that triggers the registration of tools from tools/cluster.py, including get_current_cluster.
    import tools.cluster  # noqa: F401
  • Dataclass schema/model for ContextInfo, used as the return type of the get_current_cluster tool.
    @dataclass
    class ContextInfo:
        """
        Represents a Kubernetes context.
        """
        name: str
        cluster: str
        user: str
        current: bool
  • Helper function get_kubeconfig() that loads and parses the kubeconfig YAML, called by the tool handler.
    def get_kubeconfig():
        """
        Load the kubeconfig file from the default location.
        The default location is usually ~/.kube/config.
        This function returns the parsed kubeconfig data.
        If the file does not exist or is not readable, it raises an exception.
    
        if you want to load a different kubeconfig file, you can set the KUBECONFIG environment variable
        to the path of the kubeconfig file you want to use.
        """
        kubeconfig_path = os.path.expanduser(config.KUBE_CONFIG_DEFAULT_LOCATION)
        with open(kubeconfig_path, "r") as f:
            config_data = yaml.safe_load(f)
        return config_data
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a read operation ('Get') but doesn't disclose whether this requires specific permissions, what happens if no cluster is set, error conditions, or the format of the returned cluster information. The ':return:' placeholder suggests output documentation is incomplete.

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

Conciseness3/5

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

The description is brief but includes an incomplete ':return:' section that adds no value. The first sentence is clear and front-loaded, but the second fragment is wasted space. It could be more concise by removing the placeholder or expanding it meaningfully.

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

Completeness2/5

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

Given no annotations and no output schema, the description is insufficient for a Kubernetes cluster tool. It doesn't explain what 'current cluster' means in Kubernetes context, how it's determined from kubeconfig, or what the return value contains. For a tool in a complex system like Kubernetes, more context is needed to use it effectively.

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 tool has 0 parameters with 100% schema description coverage, so the schema fully documents the lack of inputs. The description doesn't need to add parameter semantics, and it correctly avoids mentioning any parameters. A baseline of 4 is appropriate for a zero-parameter tool with complete schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Get') and resource ('current cluster from the kubeconfig file'), making the purpose immediately understandable. It distinguishes from sibling 'get_clusters' by specifying 'current' cluster rather than listing all clusters. However, it doesn't fully differentiate from other read operations like 'clusterrole_get' or 'configmap_get' beyond the resource type.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., having a valid kubeconfig), when this is needed versus 'get_clusters', or any context about Kubernetes operations. The agent must infer usage from the tool name alone.

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

Install Server

Other Tools

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