Class: Legion::MCP::Tools::RbacCheck

Inherits:
MCP::Tool
  • Object
show all
Extended by:
Logging::Helper
Defined in:
lib/legion/mcp/tools/rbac_check.rb

Class Method Summary collapse

Class Method Details

.call(principal:, action:, resource:, roles: [], team: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/mcp/tools/rbac_check.rb', line 24

def call(principal:, action:, resource:, roles: [], team: nil)
  log.info('Starting legion.mcp.tools.rbac_check.call')
  return error_response('legion-rbac not installed') unless defined?(Legion::Rbac)

  p = Legion::Rbac::Principal.new(id: principal, roles: roles, team: team)
  result = Legion::Rbac::PolicyEngine.evaluate(principal: p, action: action, resource: resource,
                                               enforce: false)
  text_response(result)
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'legion.mcp.tools.rbac_check.call')
  log.warn("RbacCheck#call failed: #{e.message}")
  error_response("RBAC check failed: #{e.message}")
end