Class: ActionMCP::RegistryBase::RegistryScope

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/action_mcp/registry_base.rb

Overview

Query object for chainable registry scopes.

Constant Summary collapse

Item =

Using a Data type for items.

Data.define(:name, :klass) do
  delegate :description, to: :klass
end

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ void

Initializes a new RegistryScope instance.

Parameters:

  • items (Hash)

    The items to scope.



96
97
98
99
100
# File 'lib/action_mcp/registry_base.rb', line 96

def initialize(items)
  @items = items.reject do |_name, klass|
    RegistryBase.send(:abstract_item?, klass)
  end.map { |name, klass| Item.new(name, klass) }
end

Instance Method Details

#each {|Item| ... } ⇒ void

This method returns an undefined value.

Iterates over the items in the scope.

Yields:

  • (Item)

    The item to yield.



106
107
108
# File 'lib/action_mcp/registry_base.rb', line 106

def each(&)
  @items.each(&)
end

#find_available_tool(name) ⇒ Class?

Chainable finder for available tools by name.

Parameters:

  • name (String)

    The name of the tool to find.

Returns:

  • (Class, nil)

    The class of the tool, or nil if not found.



121
122
123
124
# File 'lib/action_mcp/registry_base.rb', line 121

def find_available_tool(name)
  item = @items.find { |i| i.name == name }
  item&.klass
end

#keysArray<String>

Returns the names (keys) of all non-abstract items.

Returns:

  • (Array<String>)

    The names of all non-abstract items.



113
114
115
# File 'lib/action_mcp/registry_base.rb', line 113

def keys
  @items.map(&:name)
end