Module: RubynCode::MCP::ToolBridge
- Defined in:
- lib/rubyn_code/mcp/tool_bridge.rb
Overview
Wraps MCP tools as native RubynCode tools by dynamically creating tool classes that delegate execution to the MCP client.
Each bridged tool:
-
Has TOOL_NAME prefixed with “mcp_”
-
Has RISK_LEVEL = :external
-
Delegates #execute to the MCP client’s #call_tool
-
Registers itself with Tools::Registry
A server’s resources and prompts are bridged separately by ServerExtrasBridge, which #bridge folds into the returned classes.
Constant Summary collapse
- JSON_TYPE_MAP =
{ 'string' => :string, 'integer' => :integer, 'number' => :number, 'boolean' => :boolean, 'array' => :array, 'object' => :object }.freeze
Class Method Summary collapse
-
.bridge(mcp_client) ⇒ Array<Class>
Discovers tools from an MCP client and creates corresponding RubynCode tool classes (plus any resource/prompt bridge tools).
-
.sanitize_name(name) ⇒ String
Sanitizes a tool name into a Ruby-friendly identifier.
Class Method Details
.bridge(mcp_client) ⇒ Array<Class>
Discovers tools from an MCP client and creates corresponding RubynCode tool classes (plus any resource/prompt bridge tools).
28 29 30 31 32 33 |
# File 'lib/rubyn_code/mcp/tool_bridge.rb', line 28 def bridge(mcp_client) classes = Array(mcp_client.tools).map { |tool_def| build_tool_class(mcp_client, tool_def) } classes.concat(ServerExtrasBridge.bridge_resources(mcp_client)) classes.concat(ServerExtrasBridge.bridge_prompts(mcp_client)) classes end |
.sanitize_name(name) ⇒ String
Sanitizes a tool name into a Ruby-friendly identifier. Public so ServerExtrasBridge names its resource/prompt tools the same way.
40 41 42 |
# File 'lib/rubyn_code/mcp/tool_bridge.rb', line 40 def sanitize_name(name) name.to_s.gsub(/[^a-zA-Z0-9_]/, '_').gsub(/_+/, '_').downcase end |