Class: RailsAiBridge::Tools::ExplainSymbol
- Defined in:
- lib/rails_ai_bridge/tools/explain_symbol.rb,
lib/rails_ai_bridge/tools/explain_symbol/cli_explorer.rb
Overview
MCP tool that explains a Ruby/Rails symbol from a local CodeGraph index.
When .codegraph/ exists under Rails.root, this tool runs codegraph explore
(or a stubbed explorer in tests) and returns truncated markdown. Missing indexes
and CLI failures return a setup message — the tool never raises to the MCP host
and never makes network calls.
Defined Under Namespace
Classes: CliExplorer, ExploreError
Constant Summary collapse
- INDEX_DIR_NAME =
'.codegraph'- SETUP_HINT =
'Generate a local index with `codegraph init` or `codegraph index` ' \ '(no network required), then retry.'
- MISSING_INDEX_MESSAGE =
"No local CodeGraph index found at `#{INDEX_DIR_NAME}/`. #{SETUP_HINT}".freeze
- BLANK_QUERY_MESSAGE =
'Provide a `symbol` or `query` string (for example `User` or `User#save`).'
Class Attribute Summary collapse
-
.explorer ⇒ #explore
Explorer responding to
explore(query).
Class Method Summary collapse
-
.call(symbol: nil, query: nil, _server_context: nil) ⇒ MCP::Tool::Response
Markdown explanation or a setup/error message.
-
.index_present? ⇒ Boolean
Whether
.codegraph/exists under the application root. -
.reset! ⇒ void
Clears a stubbed explorer so the next call builds the default.
Methods inherited from BaseTool
cached_context, cached_section, config, rails_app, reset_cache!, text_response
Class Attribute Details
.explorer ⇒ #explore
Returns explorer responding to explore(query).
70 71 72 |
# File 'lib/rails_ai_bridge/tools/explain_symbol.rb', line 70 def explorer @explorer ||= CliExplorer.new(root: rails_root) end |
Class Method Details
.call(symbol: nil, query: nil, _server_context: nil) ⇒ MCP::Tool::Response
Returns markdown explanation or a setup/error message.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rails_ai_bridge/tools/explain_symbol.rb', line 56 def call(symbol: nil, query: nil, _server_context: nil) resolved = resolve_query(symbol, query) return text_response(BLANK_QUERY_MESSAGE) if resolved.empty? return text_response(MISSING_INDEX_MESSAGE) unless index_present? text_response(explorer.explore(resolved)) rescue ExploreError => error text_response((error)) rescue StandardError => error log_unexpected_error(error) text_response((error)) end |
.index_present? ⇒ Boolean
Returns whether .codegraph/ exists under the application root.
82 83 84 |
# File 'lib/rails_ai_bridge/tools/explain_symbol.rb', line 82 def index_present? Dir.exist?(File.join(rails_root, INDEX_DIR_NAME)) end |
.reset! ⇒ void
This method returns an undefined value.
Clears a stubbed explorer so the next call builds the default.
77 78 79 |
# File 'lib/rails_ai_bridge/tools/explain_symbol.rb', line 77 def reset! @explorer = nil end |