Class: TalkToYourApp::CustomTool
- Defined in:
- lib/talk_to_your_app/custom_tool.rb
Overview
Base class for application-defined tools. Subclass it, declare the usual Tool DSL, and enable the ‘:custom_tools` plugin — every subclass is then exposed over MCP automatically, no explicit registration needed.
class MakeAdmin < TalkToYourApp::CustomTool
name "make_admin"
description "Grant admin to a user."
argument :user_id, :integer, required: true
def call(args, _ctx)
user = User.find(args[:user_id])
user.update!(admin: true)
json(id: user.id, admin: user.admin)
end
end
Custom tools can do anything the host app allows (including writes), so only enable the plugin when you trust the authenticated principals — pair it with config.authorize to scope access.
Class Method Summary collapse
-
.clear! ⇒ Object
Test seam: forget all registered custom tools.
-
.inherited(subclass) ⇒ Object
Every subclass (at any depth) registers itself here, in definition order.
- .registry ⇒ Object
Methods inherited from Tool
argument, arguments, #call, connection, default_arguments, description, dispatch, input_schema_hash, invoke, name, normalize_response, to_mcp_definition, to_mcp_tool
Class Method Details
.clear! ⇒ Object
Test seam: forget all registered custom tools.
36 37 38 |
# File 'lib/talk_to_your_app/custom_tool.rb', line 36 def self.clear! registry.clear end |
.inherited(subclass) ⇒ Object
Every subclass (at any depth) registers itself here, in definition order.
26 27 28 29 |
# File 'lib/talk_to_your_app/custom_tool.rb', line 26 def self.inherited(subclass) super TalkToYourApp::CustomTool.registry << subclass end |
.registry ⇒ Object
31 32 33 |
# File 'lib/talk_to_your_app/custom_tool.rb', line 31 def self.registry @registry ||= [] end |