set_current_cluster
Switch the active Kubernetes cluster in the kubeconfig file by specifying the desired cluster name, simplifying cluster management and context switching.
Instructions
Set the current cluster in the kubeconfig file. :param cluster_name: :return:
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cluster_name | Yes |
Implementation Reference
- tools/cluster.py:51-68 (handler)The handler function for the 'set_current_cluster' MCP tool, which updates the current context in the kubeconfig file to the specified cluster_name. It is directly registered as a tool using the @mcp.tool() decorator.@mcp.tool() def set_current_cluster(cluster_name: str): """ Set the current cluster in the kubeconfig file. :param cluster_name: :return: """ config_data = get_kubeconfig() contexts = config_data.get("contexts", []) for ctx in contexts: if ctx["name"] == cluster_name: config_data["current-context"] = cluster_name with open(os.path.expanduser("~/.kube/config"), "w") as f: yaml.dump(config_data, f) return {"status": "success", "message": f"Current context set to {cluster_name}"} return {"status": "error", "message": f"Context {cluster_name} not found"}