Class: McpToolkit::ListExecutor
- Inherits:
-
Object
- Object
- McpToolkit::ListExecutor
- Defined in:
- lib/mcp_toolkit/list_executor.rb
Overview
Runs a read-only, paginated "list" query for a registered resource, rooted on
the scoped relation. Supports the standard ids, updated_since, limit,
offset filters plus the resource's declared per-attribute filters (equality
AND operator-based — see McpToolkit::Filtering), and serializes via the
resource's serializer, producing the { <root> => [...], meta: {...} } wrapper.
An optional fields param applies a sparse fieldset to each row (see
McpToolkit::FieldSelection).
Constant Summary collapse
- DEFAULT_LIMIT =
25- MAX_LIMIT =
100- NUMERIC_PK_TYPES =
Column types whose primary key sorts naturally by
id. Anything else (e.g. a string/uuid PK) sorts bycreated_atinstead. %i[integer bigint].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(resource:, scope_root:, params:) ⇒ ListExecutor
constructor
A new instance of ListExecutor.
Constructor Details
#initialize(resource:, scope_root:, params:) ⇒ ListExecutor
Returns a new instance of ListExecutor.
21 22 23 24 25 |
# File 'lib/mcp_toolkit/list_executor.rb', line 21 def initialize(resource:, scope_root:, params:) @resource = resource @scope_root = scope_root @params = (params || {}).deep_symbolize_keys end |
Class Method Details
.call(resource:, scope_root:, params:) ⇒ Object
17 18 19 |
# File 'lib/mcp_toolkit/list_executor.rb', line 17 def self.call(resource:, scope_root:, params:) new(resource:, scope_root:, params:).call end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mcp_toolkit/list_executor.rb', line 27 def call # Validate the sparse fieldset BEFORE running the query so a bad `fields` # fails fast rather than after a needless count + fetch. selection = McpToolkit::FieldSelection.build(resource:, raw: params[:fields]) relation = build_relation total_count = relation.count rows = paginate(relation).to_a McpToolkit::Serialization.new(resource.serializer, selection).collection( rows, scope: scope_root, total_count:, limit:, offset: ) end |