Class: RailsAiBridge::Tools::GetProviderContext
- Defined in:
- lib/rails_ai_bridge/tools/get_provider_context.rb
Overview
MCP tool for fetching context from declared external providers.
Calls the Registry::ContextAggregator to fetch and map results from
providers declared in the registry manifest. Providers are disabled by
default; this tool returns a setup message when context_providers.enabled
is false. It is separate from the local GetContext tool and does
not alter its behavior.
Defined Under Namespace
Classes: ResultFormatter
Constant Summary collapse
- DISABLED_MESSAGE =
<<~MSG Context providers are disabled. To enable outbound provider access: ```ruby RailsAiBridge.configure do |config| config.context_providers.enabled = true config.context_providers.allowed_hosts = ['context.example.com'] end ``` See `docs/v5/context-providers-design.md` for configuration and security details. MSG
- NO_MANIFEST_MESSAGE =
<<~MSG No registry manifest found. Create `config/rails_ai_bridge/registry.json` with a `context_providers` section to declare external providers. See `docs/skill-registry-guide.md` for a step-by-step guide. MSG
- MALFORMED_MANIFEST_MESSAGE =
<<~MSG Registry manifest at `%<path>s` is invalid and could not be parsed. Check the JSON syntax and try again. See `docs/skill-registry-guide.md` for the expected format. MSG
- NO_PROVIDERS_MESSAGE =
'No context providers are declared in the registry manifest.'
Class Method Summary collapse
-
.call(provider: nil, _server_context: nil) ⇒ MCP::Tool::Response
Formatted provider context or a setup/error message.
Methods inherited from BaseTool
cached_context, cached_section, config, rails_app, reset_cache!, text_response
Class Method Details
.call(provider: nil, _server_context: nil) ⇒ MCP::Tool::Response
Returns formatted provider context or a setup/error message.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rails_ai_bridge/tools/get_provider_context.rb', line 73 def self.call(provider: nil, _server_context: nil) return text_response(DISABLED_MESSAGE) unless providers_config.enabled manifest = load_manifest return text_response(NO_MANIFEST_MESSAGE) if manifest == :missing return text_response(format(MALFORMED_MANIFEST_MESSAGE, path: manifest_path)) if manifest == :malformed return text_response(NO_PROVIDERS_MESSAGE) if manifest.context_providers.empty? return text_response("Provider `#{provider}` not found in the registry manifest.") if provider && !manifest.context_providers.key?(provider) aggregator = build_aggregator(manifest) result = provider ? aggregator.fetch_one(provider) : aggregator.fetch_all text_response(format_result(result, provider_name: provider)) end |