Class: TalkToYourApp::Plugins::CustomTools::Plugin

Inherits:
TalkToYourApp::Plugin show all
Defined in:
lib/talk_to_your_app/plugins/custom_tools/plugin.rb

Overview

Exposes the host app’s own tools over MCP. Tools live in app/talk_to_your_app/custom_tools/ (one TalkToYourApp::Tool subclass per file, scaffolded by ‘rails g talk_to_your_app:custom_tool`). Unlike the bundled plugins, the tool list is dynamic: it’s whatever this plugin collects while loading that directory — bundled tools, defined when the gem loads, are never collected.

Class Method Summary collapse

Methods inherited from TalkToYourApp::Plugin

log_level, requires_connection, requires_gem, validate_enablement!

Class Method Details

.toolsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/talk_to_your_app/plugins/custom_tools/plugin.rb', line 15

def self.tools
  TalkToYourApp::Tool.collecting_custom_tools = true
  TalkToYourApp.require_app_dir("custom_tools") do |_file, load_file|
    before = TalkToYourApp::Tool.custom_registry.length
    load_file.call
  rescue StandardError, ScriptError
    TalkToYourApp::Tool.custom_registry.slice!(before..)
    raise
  end
  # Dedup by MCP name (last wins) in case two files declare the same
  # tool_name, or a class is collected more than once in a process.
  TalkToYourApp::Tool.custom_registry.each_with_object({}) { |t, acc| acc[t.tool_name] = t }.values
ensure
  TalkToYourApp::Tool.collecting_custom_tools = false
end