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
ExplainSymbol, GetConfig, GetContext, GetControllers, GetConventions, GetGems, GetModelDetails, GetProviderContext, GetRoutes, GetSchema, GetStimulus, GetTestInfo, GetView, ListContextProviders, ListRegistry, ResolveSkill, SearchCode, SearchSemantic, UseAgent, UseSkill
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, resolved through AppScope so CLI, tests, and standalone processes can scope a different app without global leakage.
-
.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 whenmax_tool_response_charsis set on the gem configuration.
Class Method Details
.cached_context ⇒ Hash
Full introspection hash (TTL + fingerprint invalidation).
27 28 29 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 27 def cached_context ContextProvider.fetch(rails_app) end |
.cached_section(section) ⇒ Object?
Returns a single introspection section via the shared context provider.
35 36 37 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 35 def cached_section(section) ContextProvider.fetch_section(section, rails_app) end |
.config ⇒ RailsAiBridge::Configuration
Returns gem configuration.
20 21 22 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 20 def config RailsAiBridge.configuration end |
.rails_app ⇒ Rails::Application
Returns the host Rails application, resolved through AppScope so CLI, tests, and standalone processes can scope a different app without global leakage.
15 16 17 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 15 def rails_app AppScope.current_app end |
.reset_cache! ⇒ void
This method returns an undefined value.
Clears the shared introspection cache used by MCP tools.
42 43 44 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 42 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rails_ai_bridge/tools/base_tool.rb', line 51 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 |