Class: McpToolkit::GetExecutor
- Inherits:
-
Object
- Object
- McpToolkit::GetExecutor
- Defined in:
- lib/mcp_toolkit/get_executor.rb
Overview
Runs a read-only "show" query for a registered resource by id, rooted on the scoped relation so cross-scope ids are simply not found. Serializes via the resource's serializer.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(resource:, scope_root:, id:, fields: nil) ⇒ GetExecutor
constructor
A new instance of GetExecutor.
Constructor Details
#initialize(resource:, scope_root:, id:, fields: nil) ⇒ GetExecutor
Returns a new instance of GetExecutor.
11 12 13 14 15 16 |
# File 'lib/mcp_toolkit/get_executor.rb', line 11 def initialize(resource:, scope_root:, id:, fields: nil) @resource = resource @scope_root = scope_root @id = id @fields = fields end |
Class Method Details
.call(resource:, scope_root:, id:, fields: nil) ⇒ Object
7 8 9 |
# File 'lib/mcp_toolkit/get_executor.rb', line 7 def self.call(resource:, scope_root:, id:, fields: nil) new(resource:, scope_root:, id:, fields:).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mcp_toolkit/get_executor.rb', line 18 def call raise McpToolkit::Errors::InvalidParams, "id is required" if id.blank? # Validate the sparse fieldset BEFORE the lookup so a bad `fields` fails fast. selection = McpToolkit::FieldSelection.build(resource:, raw: fields) record = resource.resolve_relation(scope_root).find_by(id:) raise McpToolkit::Errors::InvalidParams, "#{resource.name} not found for id=#{id}" unless record McpToolkit::Serialization.new(resource.serializer, selection).one(record, scope: scope_root) end |