get_current_context
Retrieve the active Kubernetes cluster context to identify and manage resources within the targeted environment using the MCP Kubernetes Server.
Instructions
Get the current Kubernetes context
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:207-214 (handler)The main handler function that implements the logic for the 'get_current_context' tool by executing 'kubectl config current-context' and returning the current Kubernetes context or an error.async def get_current_context() -> dict: """Get the current Kubernetes context""" try: cmd = ["kubectl", "config", "current-context"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"current_context": result.stdout.strip()} except subprocess.CalledProcessError as e: return {"error": f"Failed to get current context: {str(e)}"}
- kubernetes.py:206-206 (registration)The @mcp.tool() decorator registers the get_current_context function as an MCP tool.@mcp.tool()