Module: Woods::MCP::VersionAwareToolDispatch

Defined in:
lib/woods/mcp/version_aware_tool_dispatch.rb

Overview

Prepended onto a built MCP::Server instance so that a call to a tool the installed gem does not define produces version-aware, self-healing guidance instead of a bare "Tool not found".

An agent following a newer version of the distributed guide skills may try to call a tool that only exists in a later Woods release. The upstream mcp gem raises RequestHandlerError("Tool not found: X") with no seam to customize the message, so we intercept the built server's call_tool (dispatched directly by handle_request, so a prepend on the instance is honored on both the stdio and HTTP transports) and re-raise with the installed version plus an update hint the agent can relay to the user.

Only the genuine tool-not-found case is rewritten; every other RequestHandlerError (missing/invalid arguments, internal errors) is re-raised untouched.

Instance Method Summary collapse

Instance Method Details

#call_tool(request) ⇒ MCP::Tool::Response

Returns the tool result.

Parameters:

  • request (Hash)

    the tools/call params (carries :name)

Returns:

  • (MCP::Tool::Response)

    the tool result

Raises:

  • (MCP::Server::RequestHandlerError)

    rewritten for unknown tools



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/woods/mcp/version_aware_tool_dispatch.rb', line 26

def call_tool(request, **)
  super
rescue ::MCP::Server::RequestHandlerError => e
  raise unless tool_not_found_error?(e)

  raise ::MCP::Server::RequestHandlerError.new(
    Woods::UpdateCheck.tool_not_found_message(request[:name]),
    request,
    error_type: :invalid_params,
    original_error: e
  )
end