Skip to main content
Glama

role_create

Create Kubernetes Role objects with specific permissions in a namespace to control access to cluster resources.

Instructions

Create a Role in the specified namespace.

Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The Role name rules: List of policy rules

Returns: Status of the creation operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes
nameYes
rulesYes

Implementation Reference

  • The main handler function for the 'role_create' MCP tool. It is decorated with @mcp.tool() for registration and other decorators for context and permissions. The function creates a Kubernetes RBAC Role in the given namespace with the specified name and rules using the Kubernetes RBAC API.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def role_create(context_name: str, namespace: str, name: str, rules: list):
        """
        Create a Role in the specified namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The Kubernetes namespace
            name: The Role name
            rules: List of policy rules
    
        Returns:
            Status of the creation operation
        """
        rbac_v1: RbacAuthorizationV1Api = get_api_clients(context_name)["rbac"]
        role = V1Role(
            metadata=V1ObjectMeta(name=name),
            rules=[V1PolicyRule(**rule) for rule in rules]
        )
        created_role = rbac_v1.create_namespaced_role(namespace=namespace, body=role)
        return {"name": created_role.metadata.name, "status": "Created"}

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