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
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| namespace | Yes | ||
| name | Yes | ||
| rules | Yes |
Implementation Reference
- tools/role.py:27-49 (handler)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"}