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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools/cluster.py:10-27 (handler)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]
- models/context.py:3-11 (schema)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()