role_create
Define and create Kubernetes roles in specified namespaces using policy rules with the k8s-pilot server. Simplify role management across multiple clusters.
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 | ||
| name | Yes | ||
| namespace | Yes | ||
| rules | Yes |
Implementation Reference
- tools/role.py:27-50 (handler)The core handler function for the 'role_create' MCP tool. It uses the Kubernetes RBAC API to create a namespaced Role object with the provided name and rules. Registered directly via the @mcp.tool() decorator. Input schema is defined by type hints and the function docstring.@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"}
- tools/role.py:27-27 (registration)The @mcp.tool() decorator registers the role_create function as an MCP tool.@mcp.tool()
- tools/role.py:30-42 (schema)Input schema and documentation for the role_create tool, specifying parameters: context_name (str), namespace (str), name (str), rules (list). Returns creation status.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 """