Class: RailsAiBridge::Tools::BaseTool
- Inherits:
-
MCP::Tool
- Object
- MCP::Tool
- RailsAiBridge::Tools::BaseTool
- Defined in:
- lib/rails_ai_bridge/tools/base_tool.rb
Overview
Base class for all MCP tools exposed by rails-ai-bridge. Inherits from the official MCP::Tool to get schema validation, annotations, and protocol compliance for free.
Direct Known Subclasses
GetConfig, GetControllers, GetConventions, GetGems, GetModelDetails, GetRoutes, GetSchema, GetStimulus, GetTestInfo, GetView, SearchCode
Class Method Summary collapse
-
.cached_context ⇒ Hash
Full introspection hash (TTL + fingerprint invalidation).
-
.cached_section(section) ⇒ Object?
Returns a single introspection section via the shared context provider.
-
.config ⇒ RailsAiBridge::Configuration
Gem configuration.
-
.rails_app ⇒ Rails::Application
The host Rails application.
-
.reset_cache! ⇒ void
Clears the shared introspection cache used by MCP tools.
-
.text_response(text) ⇒ MCP::Tool::Response
Wraps markdown (or plain text) in a +MCP::Tool::Response+, truncating when +max_tool_response_chars+ is set on the gem configuration.
Class Method Details
.cached_context ⇒ Hash
Full introspection hash (TTL + fingerprint invalidation).
25 26 27 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 25 def cached_context ContextProvider.fetch(rails_app) end |
.cached_section(section) ⇒ Object?
Returns a single introspection section via the shared context provider.
33 34 35 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 33 def cached_section(section) ContextProvider.fetch_section(section, rails_app) end |
.config ⇒ RailsAiBridge::Configuration
Returns gem configuration.
18 19 20 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 18 def config RailsAiBridge.configuration end |
.rails_app ⇒ Rails::Application
Returns the host Rails application.
13 14 15 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 13 def rails_app Rails.application end |
.reset_cache! ⇒ void
This method returns an undefined value.
Clears the shared introspection cache used by MCP tools.
40 41 42 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 40 def reset_cache! ContextProvider.reset! end |
.text_response(text) ⇒ MCP::Tool::Response
Wraps markdown (or plain text) in a +MCP::Tool::Response+, truncating when +max_tool_response_chars+ is set on the gem configuration.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 49 def text_response(text) max = RailsAiBridge.configuration.max_tool_response_chars if max && text.length > max suffix = "\n\n---\n_Response truncated (#{text.length} chars). Use `detail:\"summary\"` for an overview, or filter by a specific item (e.g. `table:\"users\"`)._" available_chars = max - suffix.length truncated = if available_chars.positive? "#{text[0...available_chars]}#{suffix}" else suffix[0...max] end MCP::Tool::Response.new([{ type: 'text', text: truncated }]) else MCP::Tool::Response.new([{ type: 'text', text: text }]) end end |