Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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)}"}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/abhijeetka/mcp-k8s-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server