list_contexts
Retrieve all available Kubernetes contexts to manage access and operations across clusters efficiently within the MCP Kubernetes Server environment.
Instructions
List all available Kubernetes contexts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:216-225 (handler)The handler function for the 'list_contexts' tool, decorated with @mcp.tool() for registration. It executes 'kubectl config get-contexts -o name' to list all Kubernetes contexts and returns them as a list in a dict.@mcp.tool() async def list_contexts() -> dict: """List all available Kubernetes contexts""" try: cmd = ["kubectl", "config", "get-contexts", "-o", "name"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) contexts = result.stdout.strip().split('\n') return {"contexts": contexts} except subprocess.CalledProcessError as e: return {"error": f"Failed to list contexts: {str(e)}"}