Skip to main content
Glama

clusterrole_create

Create a ClusterRole in Kubernetes to define permissions across all namespaces, specifying rules for resource access and operations.

Instructions

Create a ClusterRole in the cluster.

Args: context_name: The Kubernetes context name name: The ClusterRole name rules: List of policy rules

Returns: Status of the creation operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
nameYes
rulesYes

Implementation Reference

  • The handler function decorated with @mcp.tool() that creates a Kubernetes ClusterRole using the RBAC API. It takes context_name, name, and rules as input and returns the creation status.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def clusterrole_create(context_name: str, name: str, rules: list):
        """
        Create a ClusterRole in the cluster.
    
        Args:
            context_name: The Kubernetes context name
            name: The ClusterRole name
            rules: List of policy rules
    
        Returns:
            Status of the creation operation
        """
        rbac_v1: RbacAuthorizationV1Api = get_api_clients(context_name)["rbac"]
        clusterrole = V1ClusterRole(
            metadata=V1ObjectMeta(name=name),
            rules=[V1PolicyRule(**rule) for rule in rules]
        )
        created_clusterrole = rbac_v1.create_cluster_role(body=clusterrole)
        return {"name": created_clusterrole.metadata.name, "status": "Created"}
  • tools/role.py:112-112 (registration)
    The @mcp.tool() decorator registers the clusterrole_create function as an MCP tool.
    @mcp.tool()
  • Input schema defined by function parameters and docstring: context_name (str), name (str), rules (list).
    def clusterrole_create(context_name: str, name: str, rules: list):
        """
        Create a ClusterRole in the cluster.
    
        Args:
            context_name: The Kubernetes context name
            name: The ClusterRole name

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/bourbonkk/k8s-pilot'

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