get_current_cluster
Retrieve the active Kubernetes cluster from the kubeconfig file using the k8s-pilot MCP server to manage and switch contexts efficiently.
Instructions
Get the current cluster from the kubeconfig file. :return:
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools/cluster.py:30-48 (handler)The handler function for the 'get_current_cluster' tool. It fetches the kubeconfig, identifies the current context, and returns a ContextInfo object for the current cluster.@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
- tools/cluster.py:30-30 (registration)Registration of the 'get_current_cluster' tool using the @mcp.tool() decorator.@mcp.tool()