get_oke_cluster_kubeconfig
Retrieve kubeconfig content for accessing an Oracle Container Engine (OKE) cluster, enabling kubectl connectivity and Kubernetes cluster management.
Instructions
Get the kubeconfig file content for accessing an OKE cluster.
Args:
cluster_id: OCID of the cluster
Returns:
Kubeconfig content in YAML format that can be saved to ~/.kube/config
or used with kubectl --kubeconfig flag
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cluster_id | Yes |
Implementation Reference
- mcp_server_oci/tools/oke.py:355-392 (handler)Core handler function that executes the logic to fetch kubeconfig from OCI Container Engine using the create_kubeconfig API.def get_cluster_kubeconfig(container_engine_client: oci.container_engine.ContainerEngineClient, cluster_id: str) -> Dict[str, Any]: """ Get the kubeconfig for a specific OKE cluster. Args: container_engine_client: OCI ContainerEngine client cluster_id: OCID of the cluster Returns: Kubeconfig content and metadata """ try: # Create kubeconfig request create_kubeconfig_details = oci.container_engine.models.CreateClusterKubeconfigContentDetails() # Get the kubeconfig kubeconfig_response = container_engine_client.create_kubeconfig( cluster_id, create_kubeconfig_details ) # Read the kubeconfig content kubeconfig_content = kubeconfig_response.data.content.decode('utf-8') if hasattr(kubeconfig_response.data, 'content') else kubeconfig_response.data.text result = { "cluster_id": cluster_id, "kubeconfig": kubeconfig_content, "format": "yaml", "usage": "Save this content to ~/.kube/config or use with kubectl --kubeconfig flag", } logger.info(f"Retrieved kubeconfig for cluster {cluster_id}") return result except Exception as e: logger.exception(f"Error getting cluster kubeconfig: {e}") raise
- mcp_server_oci/mcp_server.py:1865-1882 (registration)MCP tool registration with name 'get_oke_cluster_kubeconfig' and wrapper handler that invokes the core implementation from oke.py.@mcp.tool(name="get_oke_cluster_kubeconfig") @mcp_tool_wrapper( start_msg="Getting kubeconfig for cluster {cluster_id}...", error_prefix="Error getting cluster kubeconfig" ) async def mcp_get_oke_cluster_kubeconfig(ctx: Context, cluster_id: str) -> Dict[str, Any]: """ Get the kubeconfig file content for accessing an OKE cluster. Args: cluster_id: OCID of the cluster Returns: Kubeconfig content in YAML format that can be saved to ~/.kube/config or used with kubectl --kubeconfig flag """ return get_cluster_kubeconfig(oci_clients["container_engine"], cluster_id)
- mcp_server_oci/mcp_server.py:128-136 (helper)Import statement that brings the get_cluster_kubeconfig helper function into scope for use in the MCP server.from mcp_server_oci.tools.oke import ( list_clusters, get_cluster, list_node_pools, get_node_pool, get_cluster_kubeconfig, list_work_requests, get_work_request, )