get_clusters
Retrieve all clusters from the kubeconfig file using this tool, enabling efficient management of Kubernetes clusters through the k8s-pilot MCP server.
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 main handler function for the 'get_clusters' tool, decorated with @mcp.tool(). It reads the kubeconfig using get_kubeconfig(), determines the current context, and returns a list of ContextInfo objects for all clusters.@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 ContextInfo defining the structure for cluster context information (name, cluster, user, current), used in the output of get_clusters.@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()