14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/admin_suite/mcp/tools/get_record.rb', line 14
def self.call(resource:, id:, server_context:)
AdminSuite::Mcp.instrument(tool: "get_record", resource: resource, actor: server_context[:actor], request: server_context[:request]) do
allowed = false
config = Authorization.authorize_resource!(name: resource, actor: server_context[:actor], action: :read, request: server_context[:request])
next [Authorization.denied_response, nil, false] if config.nil?
allowed = true
record = config.model_class.find_by(id: id)
next [Authorization.denied_response, nil, false] if record.nil?
unless Authorization.authorize_record?(config: config, actor: server_context[:actor], record: record, request: server_context[:request])
next [Authorization.denied_response, nil, false]
end
payload = {
resource: resource, id: id, fields: Serializer.show_payload(record, config),
associations: Serializer.associations_payload(record, config, max_rows: AdminSuite.config.mcp.max_page_size)
}
response = ::MCP::Tool::Response.new([{ type: "text", text: Serializer.dump(payload) }])
[response, 1, true]
rescue StandardError => e
Rails.logger&.warn("AdminSuite MCP get_record failed: #{e.class}: #{e.message}")
[Authorization.error_response("get_record failed"), nil, allowed]
end
end
|