Class: McpToolkit::Authority::CompositeToolProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_toolkit/authority/composite_tool_provider.rb

Overview

Composes several tool_providers into one, so a host can serve the generic Registry-backed tools (McpToolkit::Authority::RegistryToolProvider) ALONGSIDE its own bespoke tools (e.g. a paper-trail/versions tool that doesn't fit the generic resource model) behind a single config.tool_provider.

It satisfies the same duck-typed provider contract the dispatcher calls:

tool_definitions(context) -> the concatenation of every provider's definitions,
                           in registration order
find(name)                -> the first provider (in order) that resolves the
                           name, else nil

Ordering is significant only if two providers advertise the same tool name; the first registered wins. A host controls precedence by argument order.

Instance Method Summary collapse

Constructor Details

#initialize(*providers) ⇒ CompositeToolProvider

Returns a new instance of CompositeToolProvider.



17
18
19
# File 'lib/mcp_toolkit/authority/composite_tool_provider.rb', line 17

def initialize(*providers)
  @providers = providers
end

Instance Method Details

#find(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/mcp_toolkit/authority/composite_tool_provider.rb', line 25

def find(name)
  @providers.each do |provider|
    tool = provider.find(name)
    return tool if tool
  end
  nil
end

#tool_definitions(context) ⇒ Object



21
22
23
# File 'lib/mcp_toolkit/authority/composite_tool_provider.rb', line 21

def tool_definitions(context)
  @providers.flat_map { |provider| provider.tool_definitions(context) }
end