list_contexts
Lists all available Kubernetes contexts to help users identify and switch between different cluster configurations for managing containerized applications.
Instructions
List all available Kubernetes contexts
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_contexts"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kubernetes.py:216-225 (handler)The handler function for the 'list_contexts' MCP tool. It executes 'kubectl config get-contexts -o name' to list all available 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)}"}