Class: McpToolkit::UnknownResourceMessage
- Inherits:
-
Object
- Object
- McpToolkit::UnknownResourceMessage
- Defined in:
- lib/mcp_toolkit/unknown_resource_message.rb
Overview
Builds the McpToolkit::Registry::UnknownResource message from a bad name and the
registered resource names: it states the bad name, then (a) suggests the nearest
registered name(s) for a near-miss — via Ruby's stdlib DidYouMean spell checker
when available, else a dependency-free prefix/substring + edit-distance fallback —
and (b), when the catalog is short, lists them all, so a caller (typically an MCP
agent that guessed a name) can self-correct without another round-trip to the
resources tool.
Constant Summary collapse
- FULL_LIST_MAX =
10- MAX_SUGGESTIONS =
3
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, resource_names) ⇒ UnknownResourceMessage
constructor
A new instance of UnknownResourceMessage.
Constructor Details
#initialize(name, resource_names) ⇒ UnknownResourceMessage
Returns a new instance of UnknownResourceMessage.
20 21 22 23 |
# File 'lib/mcp_toolkit/unknown_resource_message.rb', line 20 def initialize(name, resource_names) @name = name @resource_names = resource_names end |
Instance Method Details
#build ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/mcp_toolkit/unknown_resource_message.rb', line 25 def build = "unknown resource: #{@name.inspect}" return if @resource_names.empty? suggestions = suggestions_for(@name.to_s, @resource_names) += ". Did you mean #{quote_join(suggestions)}?" if suggestions.any? += " Registered resources: #{quote_join(@resource_names.sort)}." if @resource_names.size <= FULL_LIST_MAX end |